这是我们大二的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".
展开
 我来答
21jieyu
2011-07-19
知道答主
回答量:20
采纳率:0%
帮助的人:8万
展开全部
前面都是概念性的问题,你把英文翻译过来就知道很简单了!

帮你坐下第二个大题吧

四:2.
#include <iostream>
using namespace std;
class Complex
{
public:
Complex()
{
real=virt=0;
}

Complex(double r, double v)
{
real = r, virt = v;
}
Complex operator +(const Complex &c);
Complex operator -(const Complex &c);
Complex operator *(const Complex &c);
Complex operator /(const Complex &c);
friend void Display(const Complex &c);
friend int Start();
private:
double real, virt;
};
inline Complex Complex::operator +(const Complex &c)
{
return Complex(real + c.real, virt + c.virt);
}
inline Complex Complex::operator -(const Complex &c)
{
return Complex(real - c.real, virt - c.virt);
}
inline Complex Complex::operator *(const Complex &c)
{
return Complex(real * c.real - virt * c.virt, real * c.virt + virt * c.real);
}
inline Complex Complex::operator /(const Complex &c)
{
return Complex((real * c.real + virt + c.virt) / (c.real * c.real + c.virt * c.virt),
(virt * c.real - real * c.virt) / (c.real * c.real + c.virt * c.virt));
}
void Display(const Complex &c)
{
if(c.virt<0)
cout<<c.real<<c.virt<<'i'<<endl;
else
cout<<c.real<<'+'<<c.virt<<'i'<<endl;
}
int Start()
{
char m;
float a,b,c,d;
cout<<"请输入第一个复数的实部与虚部:"<<endl;
cin>>a>>b;
cout<<endl;
cout<<"请出入第二个复数的实部和虚部:"<<endl;
cin>>c>>d;
Complex c1(a,b);
Complex c2(c,d);
Complex c3;
while(1)
{
cout<<"请输入运算符操作:(+)(-)(*)(/):"<<endl;
cin>>m;
cout<<endl;
if(m=='+')
{
c3 = c1 + c2;
cout<<"\nc1+c2=";
Display(c3);

return 0;
}
else if(m=='-')
{
c3 = c1 - c2;cout<<"\nc1-c2=";
Display(c3);

return 0;
}
else if(m=='*')
{
c3 = c1 * c2;cout<<"\nc1*c2=";
Display(c3);

return 0;
}
else if(m=='/')
{
c3 = c1 / c2;cout<<"\nc1/c2=";
Display(c3);

return 0;

}
else
{
cout<<"您的输入有误!请重新输入!"<<endl;
}
}
cout<<endl;
return 0;
}
int main()
{
Start();
return 0;
}
匿名用户
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;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
慈高轩0fs
2011-07-21 · TA获得超过219个赞
知道答主
回答量:163
采纳率:0%
帮助的人:130万
展开全部
这么浪费感情的东西10分啊@@!
前边都是些基础知识,后边的也。。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式