华科面向对象的程序设计题库

2026/4/26 22:03:46

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 class Counter{

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 class Sample {

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 class Sample {

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 #include using namespace std;

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<<\


华科面向对象的程序设计题库.doc 将本文的Word文档下载到电脑
搜索更多关于: 华科面向对象的程序设计题库 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219