C++正在考试改错题 在线等答案 急!!
一、改错1.#include<iostream.h>classMyClass{public:MyClass(inti){member=i;}voidSetMember(i...
一、 改错
1.
#include <iostream.h>
class MyClass
{ public:
MyClass(int i){member=i;}
void SetMember(int m){member=m;}
int GetMember()const{return menber;}
void print()cont{cout<<"member="< }
private:
int member;
};
voed main()
{
/* * * * * * * * * * found * * * * * * * * * */
MyClass obj1;
obj1.print();
MyClass obj2(3);
/* * * * * * * * * * found * * * * * * * * * */
obj1.member=5;
/* * * * * * * * * * found * * * * * * * * * */
MyClass.SetMember(10);
obj1.print();
obj2.print();
}
2.
#include <iostream.h>
class A
{
public:
A(char *s) { cout << s << endl; }
~A() {}
};
class B:public A
{
public:
B(char *sl,char *s2) :A(sl)
{
cout << s2 << endl;
}
};
class C:public A
{
public:
C(char *sl,char *s2) :A(sl)
{
cout << s2 << endl;
}
};
class D:public B,public C
{
public:
D(char *sl,char *s2,char *s3,char *s4) :B(sl,s2),C(sl,s3)
{
cout << s4 << endl;
} ;
void main ()
{
D d("class A","class B","class C","class D");
cout<<"welcome to you"<<endl;
system("pause");
}
能运行成功就性了 展开
1.
#include <iostream.h>
class MyClass
{ public:
MyClass(int i){member=i;}
void SetMember(int m){member=m;}
int GetMember()const{return menber;}
void print()cont{cout<<"member="< }
private:
int member;
};
voed main()
{
/* * * * * * * * * * found * * * * * * * * * */
MyClass obj1;
obj1.print();
MyClass obj2(3);
/* * * * * * * * * * found * * * * * * * * * */
obj1.member=5;
/* * * * * * * * * * found * * * * * * * * * */
MyClass.SetMember(10);
obj1.print();
obj2.print();
}
2.
#include <iostream.h>
class A
{
public:
A(char *s) { cout << s << endl; }
~A() {}
};
class B:public A
{
public:
B(char *sl,char *s2) :A(sl)
{
cout << s2 << endl;
}
};
class C:public A
{
public:
C(char *sl,char *s2) :A(sl)
{
cout << s2 << endl;
}
};
class D:public B,public C
{
public:
D(char *sl,char *s2,char *s3,char *s4) :B(sl,s2),C(sl,s3)
{
cout << s4 << endl;
} ;
void main ()
{
D d("class A","class B","class C","class D");
cout<<"welcome to you"<<endl;
system("pause");
}
能运行成功就性了 展开
2个回答
展开全部
#include <iostream>
using namespace std;
class MyClass
{ public:
MyClass(int i=0){member=i;}//带默认值的构造函数
void SetMember(int m){member=m;}
int GetMember()const{return member;}
void print()const{cout<<"member="<<member<<endl; }
private:
int member;
};
void main()
{
/* * * * * * * * * * found * * * * * * * * * */
MyClass obj1;
obj1.print();
MyClass obj2(3);
/* * * * * * * * * * found * * * * * * * * * */
obj1.SetMember(5);
/* * * * * * * * * * found * * * * * * * * * */
obj2.SetMember(10);
obj1.print();
obj2.print();
}
------------------------------------------
#include <iostream>
using namespace std;
class A
{
public:
A(char *s) { cout << s << endl; }
~A() {}
};
class B:public A
{
public:
B(char *sl,char *s2) :A(sl)
{
cout << s2 << endl;
}
};
class C:public A
{
public:
C(char *sl,char *s2) :A(sl)
{
cout << s2 << endl;
}
};
class D:public B,public C
{
public:
D(char *sl,char *s2,char *s3,char *s4) :B(sl,s2),C(sl,s3)
{
cout << s4 << endl;
}
};
void main ()
{
D d("class A","class B","class C","class D");
cout<<"welcome to you"<<endl;
system("pause");
}
using namespace std;
class MyClass
{ public:
MyClass(int i=0){member=i;}//带默认值的构造函数
void SetMember(int m){member=m;}
int GetMember()const{return member;}
void print()const{cout<<"member="<<member<<endl; }
private:
int member;
};
void main()
{
/* * * * * * * * * * found * * * * * * * * * */
MyClass obj1;
obj1.print();
MyClass obj2(3);
/* * * * * * * * * * found * * * * * * * * * */
obj1.SetMember(5);
/* * * * * * * * * * found * * * * * * * * * */
obj2.SetMember(10);
obj1.print();
obj2.print();
}
------------------------------------------
#include <iostream>
using namespace std;
class A
{
public:
A(char *s) { cout << s << endl; }
~A() {}
};
class B:public A
{
public:
B(char *sl,char *s2) :A(sl)
{
cout << s2 << endl;
}
};
class C:public A
{
public:
C(char *sl,char *s2) :A(sl)
{
cout << s2 << endl;
}
};
class D:public B,public C
{
public:
D(char *sl,char *s2,char *s3,char *s4) :B(sl,s2),C(sl,s3)
{
cout << s4 << endl;
}
};
void main ()
{
D d("class A","class B","class C","class D");
cout<<"welcome to you"<<endl;
system("pause");
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询