class Sample {
char c1,c2; public:
Sample(char a){c2=(c1=a)-32;} void disp() {
cout< void main() { Sample a('a'),b('b'); a.disp(); b.disp(); } 答案: a转换为A b转换为B 8、 #include static long counter; public : Counter( ){ counter++; } long GetCounter( ) { return counter; } ~Counter( ){ counter--; } }; long Counter::counter = 5; Counter c1, c2, c3; void main( ) { cout<<\ c3.GetCounter( ))< Cout<<\ c5.GetCounter( ))< (1) The object counter is 8 (2) The object counter is 11 9、 #include int n; public: Sample(){} Sample (int m){n=m;} friend void square(Sample &s) { s.n=s.n*s.n; } void disp() { cout<<\ } }; void main() { Sample a(10); square(a); a.disp(); } 答案: n=100 10、 #include int x; public: Sample(){ }; Sample(int a){x=a;} Sample(Sample &a){x=a.x++ +10;} void disp() {cout<<\}; void main() { Sample s1(2), s2(s1); s1.disp(); s2.disp(); } 答案: x=3 x=12 11、 #include class Person { public: Person(char *nam,int ag) { strcpy(name,nam); age = ag; cout<<\类构造函数---\ } Person(char *nam) { strcpy(name,nam); cout<<\类构造函数(char *nam)---\ } ~Person() { cout<<\类析构函数---\ } void display() { cout<<\姓名:\ } protected: char name[100]; int age; }; class Teacher: public Person // 声明Teacher(教师)类 { public: // 公用部分 Teacher(char *nam,int a,char *t):Person(nam,a) // 构造函数 { strcpy(title,t); cout<<\类构造函数\ } ~Teacher() { cout<<\类析构函数\ } void display1() // 输出教师有关数据 { cout<<\姓名:\ cout<<\年龄\ cout<<\职称:\ } protected: // 保护部分 char title[10]; // 职称 }; class Student: public Person { public: Student(char *nam,char s,float sco):Person(nam) { sex=s; score=sco; cout<<\类构造函数---\ } Student(char *nam, char s):Person(nam) { sex=s; cout<<\类构造函数---班长:\ } ~Student() { cout<<\类析构函数---\ } void display2() // 输出学生有关数据 { cout<<\姓名:\ cout<<\性别:\ cout<<\成绩:\ } char *get_name() { return name; } protected: // 保护部分 char sex; float score; // 成绩 }; class Graduate: public Teacher, public Student { public: Graduate(char *nam,int a,char s,char *t,float sco,float w):Teacher(nam,a,t),Student(nam,s,sco),wage(w),monitor(\ { cout<<\类构造函数\ } ~Graduate() { cout<<\类析构函数\ } void show( ) // 输出人员的有关数据 { cout<<\

