这是我们的C++考试题,英语的,能不能麻烦各位高手帮我做一下啊,据说很简单的
用中文回答就行,越规范越简洁正确越好,我要打印下来的。网页上没法显示黑体,我就用引号了一.1.Describethedifferencesbetweenthe"point...
用中文回答就行,越规范越简洁正确越好,我要打印下来的。网页上没法显示黑体,我就用引号了
一.1.Describe the differences between the "pointer" and "reference".
2.A class mainly contains two kinds of members.What are they?
3.Compare the two ways to define a constant .Decide which way is better and tell the reason:
#define BUFSIZE 256
Const int bufsize=256
4.Please tell the difference among "public","protected" and "private" in a class.
5.Describe the "constructor" and "destructor" of class.
6.How to define the "copy constructor" ? Give an exemple to explain.
7.Give an example to implement the "polymorphism" in object-oriented programming.
8.How to define a "pure virtual function" ? Give an example.
9.How to define a "template function" ? Give an exemple to explain.
10.What is the "inline function" ?
三.Find out the error in the following code and give the reason.
1.class X{
private:
int a;
};
Class Y: public X{
public:
void set(int c){
This->a=c;
}
};
int main(){
Y y1;
y1.set(10);
return 0;
}
2.class X{
public :
int func(void){
return a++;
}
int a;
};
class Y:public X{
public :
int describe () const{
return func();
}
};
四.1.Please put the content in the following array ia into a vector and sort the data in ascend ,then output the result into standard stream.
int ia[]={46,4,89,3,5,78,12}
2.Please design a complex(复数) class which can be presented as a+bi .It implements the complex operations :+ ,-,x,÷.The rule for complex addition as follow:
suppose:C1:a1+b1i
C2:a2+b2i
C3=C1+C2
then
C3=(a1+a2)+(b1+b2)i
You reasonably use the "cpevator overloading".
就是,太鄙视一楼的翻译了。顶二楼,不过还是希望看看有没有其他更好的答案 展开
一.1.Describe the differences between the "pointer" and "reference".
2.A class mainly contains two kinds of members.What are they?
3.Compare the two ways to define a constant .Decide which way is better and tell the reason:
#define BUFSIZE 256
Const int bufsize=256
4.Please tell the difference among "public","protected" and "private" in a class.
5.Describe the "constructor" and "destructor" of class.
6.How to define the "copy constructor" ? Give an exemple to explain.
7.Give an example to implement the "polymorphism" in object-oriented programming.
8.How to define a "pure virtual function" ? Give an example.
9.How to define a "template function" ? Give an exemple to explain.
10.What is the "inline function" ?
三.Find out the error in the following code and give the reason.
1.class X{
private:
int a;
};
Class Y: public X{
public:
void set(int c){
This->a=c;
}
};
int main(){
Y y1;
y1.set(10);
return 0;
}
2.class X{
public :
int func(void){
return a++;
}
int a;
};
class Y:public X{
public :
int describe () const{
return func();
}
};
四.1.Please put the content in the following array ia into a vector and sort the data in ascend ,then output the result into standard stream.
int ia[]={46,4,89,3,5,78,12}
2.Please design a complex(复数) class which can be presented as a+bi .It implements the complex operations :+ ,-,x,÷.The rule for complex addition as follow:
suppose:C1:a1+b1i
C2:a2+b2i
C3=C1+C2
then
C3=(a1+a2)+(b1+b2)i
You reasonably use the "cpevator overloading".
就是,太鄙视一楼的翻译了。顶二楼,不过还是希望看看有没有其他更好的答案 展开
4个回答
展开全部
一.1.Describe the differences between the "pointer" and "reference".
指针和引用的区别:1.指针是一个实体,而引用仅是个别名;
2.引用只能在定义时被初始化一次,之后不可变;指针可变;
3.引用不能为空,指针可以为空;
2.A class mainly contains two kinds of members.What are they?
一个累包含的2种成员:1:数据成员 2:成员函数.
3.Compare the two ways to define a constant .Decide which way is better and tell the reason:
#define BUFSIZE 256
Const int bufsize=256
答: Const int bufsize=256更好,因为使用#define没有只是代码替换没有数据
类型检查,可能会出错
4.Please tell the difference among "public","protected" and "private" in a class.
答:1公有成员public
在程序的任何地方都可以被访问
2私有成员private
只能被成员函数和类的友元访问
3被保护成员protected
可以被子类访问
对其他程序则表现得像private
5.Describe the "constructor" and "destructor" of class.
构造函数是实例化一个对象。
析构函数销毁一个对象。
6.How to define the "copy constructor" ? Give an exemple to explain.
例子:
Example::Example(const Example& t) //拷贝构造函数的定义
{
nSize=t.nSize; //复制常规成员
pBuffer=new char[nSize]; //复制指针指向的内容
memcpy(t.pBuffer,pBuffer,nSize*sizeof(char));
}
7.Give an example to implement the "polymorphism" in object-oriented programming.
#include <iostream>
using namespace std;
class B{
public:
void virtual vf() { cout << "This is class B" << endl; }
};
class D: public B{
public:
void vf() { cout << "This is class D" << endl; }
};
main(){
B b, *pb;
D d, *pd;
pb = &b; pb->vf();
pb = &d; pb->vf();
pd = (D*)&b; pd->vf();
pd = &d; pd->vf();
}
8.How to define a "pure virtual function" ? Give an example.
class B{
public:
void virtual vf() { } = 0;
};
9.How to define a "template function" ? Give an exemple to explain.
template<class T>
void fu(T,T){ cout < < "template version fun(T,T) called " < <endl;}
10.What is the "inline function" ?
内联函数:编译时,类似宏替换,使用函数体替换调用处的函数名。一般在代码
中用inline修饰,但是否能形成内联函数,需要看编译器对该函数定义的具体处理。
三.Find out the error in the following code and give the reason.
1.class X{
private: //这里错,,要用protected;
int a;
};
Class Y: public X{
public:
void set(int c){
This->a=c;
}
};
int main(){
Y y1;
y1.set(10);
return 0;
}
2.class X{
public :
int func(void){
return a++;
}
int a;
};
class Y:public X{
public :
int describe () const{ //这里错,不能有const
return func();
}
};
四.1.Please put the content in the following array ia into a vector and sort the data in ascend ,then output the result into standard stream.
int ia[]={46,4,89,3,5,78,12}
2.Please design a complex(复数) class which can be presented as a+bi .It implements the complex operations :+ ,-,x,÷.The rule for complex addition as follow:
suppose:C1:a1+b1i
C2:a2+b2i
C3=C1+C2
then
C3=(a1+a2)+(b1+b2)i
You reasonably use the "cpevator overloading".
答:
class RealNum{
public:
RealNum(double temp_x,double temp_y){
x = temp_x ;
y = temp_y ;
}
virtual double oper() = 0;
protected:
double x;
double y;
};
class Plus:public RealNum{
public:
Plus(double temp_x,double temp_y):RealNum(temp_x,temp_y){
}
double oper(){
return this ->x + this ->y;
}
};
class subtract:public RealNum{
public:
subtract(double temp_x,double temp_y):RealNum(temp_x,temp_y){
}
double oper(){
return this ->x - this ->y;
}
};
class multiply:public RealNum{
public:
multiply(double temp_x,double temp_y):RealNum(temp_x,temp_y){
}
double oper(){
return this ->x * this ->y;
}
};
class division:public RealNum{
public:
division(double temp_x,double temp_y):RealNum(temp_x,temp_y){
}
double oper(){
return this ->x / this ->y;
}
};
打了很久!希望你采纳!可能不是全对,但还是可信的
指针和引用的区别:1.指针是一个实体,而引用仅是个别名;
2.引用只能在定义时被初始化一次,之后不可变;指针可变;
3.引用不能为空,指针可以为空;
2.A class mainly contains two kinds of members.What are they?
一个累包含的2种成员:1:数据成员 2:成员函数.
3.Compare the two ways to define a constant .Decide which way is better and tell the reason:
#define BUFSIZE 256
Const int bufsize=256
答: Const int bufsize=256更好,因为使用#define没有只是代码替换没有数据
类型检查,可能会出错
4.Please tell the difference among "public","protected" and "private" in a class.
答:1公有成员public
在程序的任何地方都可以被访问
2私有成员private
只能被成员函数和类的友元访问
3被保护成员protected
可以被子类访问
对其他程序则表现得像private
5.Describe the "constructor" and "destructor" of class.
构造函数是实例化一个对象。
析构函数销毁一个对象。
6.How to define the "copy constructor" ? Give an exemple to explain.
例子:
Example::Example(const Example& t) //拷贝构造函数的定义
{
nSize=t.nSize; //复制常规成员
pBuffer=new char[nSize]; //复制指针指向的内容
memcpy(t.pBuffer,pBuffer,nSize*sizeof(char));
}
7.Give an example to implement the "polymorphism" in object-oriented programming.
#include <iostream>
using namespace std;
class B{
public:
void virtual vf() { cout << "This is class B" << endl; }
};
class D: public B{
public:
void vf() { cout << "This is class D" << endl; }
};
main(){
B b, *pb;
D d, *pd;
pb = &b; pb->vf();
pb = &d; pb->vf();
pd = (D*)&b; pd->vf();
pd = &d; pd->vf();
}
8.How to define a "pure virtual function" ? Give an example.
class B{
public:
void virtual vf() { } = 0;
};
9.How to define a "template function" ? Give an exemple to explain.
template<class T>
void fu(T,T){ cout < < "template version fun(T,T) called " < <endl;}
10.What is the "inline function" ?
内联函数:编译时,类似宏替换,使用函数体替换调用处的函数名。一般在代码
中用inline修饰,但是否能形成内联函数,需要看编译器对该函数定义的具体处理。
三.Find out the error in the following code and give the reason.
1.class X{
private: //这里错,,要用protected;
int a;
};
Class Y: public X{
public:
void set(int c){
This->a=c;
}
};
int main(){
Y y1;
y1.set(10);
return 0;
}
2.class X{
public :
int func(void){
return a++;
}
int a;
};
class Y:public X{
public :
int describe () const{ //这里错,不能有const
return func();
}
};
四.1.Please put the content in the following array ia into a vector and sort the data in ascend ,then output the result into standard stream.
int ia[]={46,4,89,3,5,78,12}
2.Please design a complex(复数) class which can be presented as a+bi .It implements the complex operations :+ ,-,x,÷.The rule for complex addition as follow:
suppose:C1:a1+b1i
C2:a2+b2i
C3=C1+C2
then
C3=(a1+a2)+(b1+b2)i
You reasonably use the "cpevator overloading".
答:
class RealNum{
public:
RealNum(double temp_x,double temp_y){
x = temp_x ;
y = temp_y ;
}
virtual double oper() = 0;
protected:
double x;
double y;
};
class Plus:public RealNum{
public:
Plus(double temp_x,double temp_y):RealNum(temp_x,temp_y){
}
double oper(){
return this ->x + this ->y;
}
};
class subtract:public RealNum{
public:
subtract(double temp_x,double temp_y):RealNum(temp_x,temp_y){
}
double oper(){
return this ->x - this ->y;
}
};
class multiply:public RealNum{
public:
multiply(double temp_x,double temp_y):RealNum(temp_x,temp_y){
}
double oper(){
return this ->x * this ->y;
}
};
class division:public RealNum{
public:
division(double temp_x,double temp_y):RealNum(temp_x,temp_y){
}
double oper(){
return this ->x / this ->y;
}
};
打了很久!希望你采纳!可能不是全对,但还是可信的
2011-07-20
展开全部
是清华的ACM试题吧,我刚做完,你试试看。
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
struct item{
char key;
int priority;
struct item** smaller;
struct item** greater;
};
typedef struct item Item;
int placeToAdd(Item** a,char b,int n){
int i;
for(i=0;i<n;i++){
if((a[i]->key)==b) return i;
else if((a[i]->key)==' ') {
a[i]->key=b;
return i;
}
}
if(i>=n) return -1;
}
int hasCompared(Item** a,int i,int j,int n){
int m=0;
if(i==j)return -1;
while((((a[i]->greater[m])!=0||a[i]->smaller[m])!=0)&&m<n){
if((a[i]->greater[m])==a[j]) return 1;
else if((a[i]->smaller[m])==a[j]) return -1;
m++;
}
if(m<n){
a[i]->greater[m]=a[j];
m=0;
while((a[j]->smaller[m])!=0&&m<n) m++;
if(m<n) a[j]->smaller[m]=a[i];
return 0;
}
}
int keySetting(int i,int j,Item** a,int n){
int m=hasCompared(a,i,j,n);
if(m==-1) return -1;
else if(m==1) return 1;
else{
if(a[i]->priority>=a[j]->priority) a[j]->priority=a[i]->priority+1;
int k=0;
while((a[j]->greater[k])!=0&&k<n){
a[j]->greater[k]->priority+=1;
k++;
}
return 0;
}
}
int main(){
int l,m,n,i,j;
int unsorted=0,inconsistent=0;
char sign,first,second;
cin>>m>>n;
if(m==0||n==0){
cout<<"Sorted sequence cannot be determined."<<endl;
return 1;
}
Item** a=new Item *[m];
for(i=0;i<m;i++){
a[i]=new Item;
a[i]->key=' ';
a[i]->priority=0;
a[i]->smaller= new Item *[m];
a[i]->greater=new Item *[m];
for(j=0;j<m;j++){
a[i]->smaller[j]=0;
a[i]->greater[j]=0;
}
}
l=n;
while(n>0){
cin>>first>>sign>>second;
i=placeToAdd(a,first,m);
j=placeToAdd(a,second,m);
if(i!=-1&&j!=-1){
if(keySetting(i,j,a,m)==-1) inconsistent=1;
}
else unsorted=1;
n--;
}
if(unsorted) cout<<"Sorted sequence cannot be determined."<<endl;
else if(inconsistent) cout<<"Inconsistency found after "<<l<<" relations."<<endl;
else{
int min;
for(i=0;i<m-1;i++){
min=i;
for(j=i+1;j<m;j++){
if((a[j]->priority)<(a[min]->priority)) min=j;
else if((a[j]->priority)==(a[min]->priority)) unsorted=1;
}
Item* temp=a[i];
a[i]=a[min];
a[min]=temp;
}
if(unsorted) cout<<"Sorted sequence cannot be determined."<<endl;
else{
cout<<"Sorted sequence determined after "<<l<<" relations: ";
for(i=0;i<m;i++)
cout<<(a[i]->key);
cout<<endl;
}
}
for(i=0;i<m;i++){
delete[] (a[i]->smaller);
delete[] (a[i]->greater);
delete a[i];
}
delete[] a;
return 0;
}
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
struct item{
char key;
int priority;
struct item** smaller;
struct item** greater;
};
typedef struct item Item;
int placeToAdd(Item** a,char b,int n){
int i;
for(i=0;i<n;i++){
if((a[i]->key)==b) return i;
else if((a[i]->key)==' ') {
a[i]->key=b;
return i;
}
}
if(i>=n) return -1;
}
int hasCompared(Item** a,int i,int j,int n){
int m=0;
if(i==j)return -1;
while((((a[i]->greater[m])!=0||a[i]->smaller[m])!=0)&&m<n){
if((a[i]->greater[m])==a[j]) return 1;
else if((a[i]->smaller[m])==a[j]) return -1;
m++;
}
if(m<n){
a[i]->greater[m]=a[j];
m=0;
while((a[j]->smaller[m])!=0&&m<n) m++;
if(m<n) a[j]->smaller[m]=a[i];
return 0;
}
}
int keySetting(int i,int j,Item** a,int n){
int m=hasCompared(a,i,j,n);
if(m==-1) return -1;
else if(m==1) return 1;
else{
if(a[i]->priority>=a[j]->priority) a[j]->priority=a[i]->priority+1;
int k=0;
while((a[j]->greater[k])!=0&&k<n){
a[j]->greater[k]->priority+=1;
k++;
}
return 0;
}
}
int main(){
int l,m,n,i,j;
int unsorted=0,inconsistent=0;
char sign,first,second;
cin>>m>>n;
if(m==0||n==0){
cout<<"Sorted sequence cannot be determined."<<endl;
return 1;
}
Item** a=new Item *[m];
for(i=0;i<m;i++){
a[i]=new Item;
a[i]->key=' ';
a[i]->priority=0;
a[i]->smaller= new Item *[m];
a[i]->greater=new Item *[m];
for(j=0;j<m;j++){
a[i]->smaller[j]=0;
a[i]->greater[j]=0;
}
}
l=n;
while(n>0){
cin>>first>>sign>>second;
i=placeToAdd(a,first,m);
j=placeToAdd(a,second,m);
if(i!=-1&&j!=-1){
if(keySetting(i,j,a,m)==-1) inconsistent=1;
}
else unsorted=1;
n--;
}
if(unsorted) cout<<"Sorted sequence cannot be determined."<<endl;
else if(inconsistent) cout<<"Inconsistency found after "<<l<<" relations."<<endl;
else{
int min;
for(i=0;i<m-1;i++){
min=i;
for(j=i+1;j<m;j++){
if((a[j]->priority)<(a[min]->priority)) min=j;
else if((a[j]->priority)==(a[min]->priority)) unsorted=1;
}
Item* temp=a[i];
a[i]=a[min];
a[min]=temp;
}
if(unsorted) cout<<"Sorted sequence cannot be determined."<<endl;
else{
cout<<"Sorted sequence determined after "<<l<<" relations: ";
for(i=0;i<m;i++)
cout<<(a[i]->key);
cout<<endl;
}
}
for(i=0;i<m;i++){
delete[] (a[i]->smaller);
delete[] (a[i]->greater);
delete a[i];
}
delete[] a;
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
自动检测中英文中译英英译中 百度翻译
翻译结果(英 > 中)复制结果
1.describe之间的差异的“指针”和“参考”。
2类。主要包含2种members.what他们?
3.compare的方法来定义一个常数。决定哪种方式更好,告诉原因:
#定义bufsize256
整型常量bufsize=256
4.please告诉之间的差异,“公共”,“保护”和“私人”在一个班级。
5.describe“建设者”和“破坏者”级。
6.how界定“复制构造函数”?为例说明。
7.give例子执行“多态性”在面向对象编程。
8.how定义一个“纯虚拟函数”?举一个例子。
9.how定义一个“模板”功能?为例说明。
10.what是“内联函数”?
三。找出错误在下面的代码和给予的原因。
1.class×{
私人的:
返回一个;
};
类:公共×{
公开:
设置(第三){
这- >=丙;
}
};
诠释主体(){
你日圆;
第一集(10);
返回0;
}
2.class×{
公开:
国际功能(无效){
返回一个+ +;
}
返回一个;
};
类:公共×{
公开:
在描述()常量{
返回函数();
}
};
四。1.please把内容在以下数组是成为一个向量和排序数据上,然后将结果输出到标准流。
国际自动化[]={46,4,89,3,5,78,12}
2.please设计一个复杂(复数)类,可以作为一个联系。它实现了复杂的操作:+,-,×,÷。规则复杂除了如下:
假设:C 1:A 1+b1i
芹菜:2+b2i
c=C 1+C 2
然后
c=(1+2)+(A+B)i
你合理地使用“cpevator超载”。
翻译结果(英 > 中)复制结果
1.describe之间的差异的“指针”和“参考”。
2类。主要包含2种members.what他们?
3.compare的方法来定义一个常数。决定哪种方式更好,告诉原因:
#定义bufsize256
整型常量bufsize=256
4.please告诉之间的差异,“公共”,“保护”和“私人”在一个班级。
5.describe“建设者”和“破坏者”级。
6.how界定“复制构造函数”?为例说明。
7.give例子执行“多态性”在面向对象编程。
8.how定义一个“纯虚拟函数”?举一个例子。
9.how定义一个“模板”功能?为例说明。
10.what是“内联函数”?
三。找出错误在下面的代码和给予的原因。
1.class×{
私人的:
返回一个;
};
类:公共×{
公开:
设置(第三){
这- >=丙;
}
};
诠释主体(){
你日圆;
第一集(10);
返回0;
}
2.class×{
公开:
国际功能(无效){
返回一个+ +;
}
返回一个;
};
类:公共×{
公开:
在描述()常量{
返回函数();
}
};
四。1.please把内容在以下数组是成为一个向量和排序数据上,然后将结果输出到标准流。
国际自动化[]={46,4,89,3,5,78,12}
2.please设计一个复杂(复数)类,可以作为一个联系。它实现了复杂的操作:+,-,×,÷。规则复杂除了如下:
假设:C 1:A 1+b1i
芹菜:2+b2i
c=C 1+C 2
然后
c=(1+2)+(A+B)i
你合理地使用“cpevator超载”。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
顶楼上...另外,,,鄙视一楼的...严重鄙视
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询