题目内容

使用VC++6.0打开考生文件夹下的源程序文件3.cpp,其中定义了用于表示矩形的CRect类,但类CRect的定义并不完整。请按要求完成下列操作,将类CRect的定义补充完整。 (1)定义私有数据成员leftPoint、topPoint、rightPoint、bottomPoint,分别用于表示矩形左上角及右下角的点的坐标,它们都是double型的数据。请在注释1之后添加适当的语句。 (2)完成默认构造函数CRect的定义,指定默认实参为0,它们都是double型的数据。请在注释2之后添加适当的语句。 (3)定义函数体为空的析构函数。请在注释3之后添加适当的语句。 (4)在main函数中定义GReet类的实例rect2,并把re- ct1的值赋给rect2。请在注释4之后添加适当的语句。 注意:除在指定位置添加语句之外,不要改动程序中的其他内容。 试题程序: include<iostream.h> classCRect { private: //********1******** public: //********2******** //********3******** voidSetPoints(double,double,double,double); voidSetLeftPoint(doublem){leftPoint=m;} voidSetRightPoint(doublem){rightPoint=m;} voidSetTopPoint(doublem){topPoint=m;} voidSetBottomPoint(doublem){bottomPoint=m;} voidDisplay(); }; CReet::CRect(double1,doublet,doubler,doubleb) { leftPoint=1;topPoint=t; rightPoint=r;bottomPoint=b; } voidCRect::Setpoints(double1,doublet,doubler,doubleb) { leftPoint=1;topPoint=t; rightPoint=n;bottomPoint=b; } voidCRect::Display() { cout<<"left-toppointis("<<leftPoint<<","<<top- Point<<")"<<\n; cout<<"right-bottompointis("<<rightPoint<<"," <<bottomPoint<<")"<<\n; } voidmain() { CRectrect0; rect0.Display(); rect0.SetPoints(20,20.6,30,40); rect0.Display(); CRectrectl(0,0,150,150); rect1.SetTopPoint(10.5); rect1.SetLeftPoint(10.5); //********4******** rect2.Display();}

查看答案
更多问题

使用VC++6.0打开考生文件夹下的源程序文件3.cpp,其中定义了类A、A1和A2,其中A1类由A类公有派生,A2类由A1类公有派生。 (1)定义类A的构造函数,该构造函数有一个整型的参数x,在构造函数中请将x赋值给数据成员a。请在注释“//********1********”之后添加适当的语句。 (2)定义类A1的构造函数,该构造函数有两个整型的参数x和y,在构造函数中请将x赋值给数据成员b,将y作为基类A构造函数的参数值传人。请在注释“//********2********”之后添加适当的语句。 (3)定义类A2的构造函数,该构造函数有3个整型的参数x,y和z,在构造函数中请将x赋值给数据成员C,将y和z分别赋值给基类A1构造函数的参数x和y。请在注释“//********3********”之后添加适当的语句。 (4)完成类A2的成员函数show的定义,该函数调用基类成员函数,输出基类数据成员a和b及类A2自身的数据成员C的值,上述3个值在输出时以空格隔开。请在注释“//********4********”之后添加适当的语句。 程序输出结果如下: 7 3 738 注意:除在指定的位置添加语句之外,请不要改动程序的其他部分。 试题程序: include<iostream.h> classA { inta; public: //********1******** intgeta{returna;} }; classA1:publicA { intb; public: //********2******** intgetb{returnb;} }; classA2:publicA1 { intC; public: //****,****3******** voidshow { //********4******** } }; voidmain { A2a(8.3.7): cout<<a.geta<<endl: cout<<a.getb<<endl: a.show; }

请补充main函数,该函数的功能是:先以只写方式打开文件file.dat,再把字符串S中的字符保存到这个磁盘文件中。请勿改动main函数与其他函数中的任何内容,仅在的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 试题程序: include<stdlib.h> include<stdio.h> define N 100 void main { FILE*f: int i=0: char ch; char s[N]="Welcome!"; if((f=fopenl("【1】","w"))==NULL) { printf("cannot open file.dat\n"); exit(0); } while(s[i]) { ch=s[i]; 【2】 ; putchar(ch); i++: } 【3】 ; }

请补充函数proc,该函数的功能是:把从主函数中输入的由数字字符组成的字符串转换成一个无符号长整数,并且逆序输出。结果由函数返回。例如,输入:1234567,结果输出:7654321。 注意:部分源程序给出如下。 请勿改动main函数和其他函数中的任何内容,仅在函数proc的横线上填人所编写的若干表达式或语句。 试题程序: include<stdlib.h> include<conio.h> include stdio.h> include<string.h> unsigned long proc(char*str) { unsigned long t=0: int k: int i=0; i=str|en(str); for(【1】 ;i>=0;i--) { k= 【2】 ; t= 【3】 ; } return t; } void main { char str[8]; system("CLS"); printf("Enter a string made up of0to 9 digital character:\n"); gets(str); printf("The string,is:%s\n",str); if(strlen(str)>8) printf("The string is too tong!"); else printf("The result:%1u\n", proc(str)); }

下列给定程序的功能是:读入一个整数n(2<=n<= 5000),打印它的所有为素数的因子。例如,若输入整数1234,则应输出:2,617。 请修改程序中的错误,使程序能得出正确的结果。 注意:不要改动main函数,不能增选或删行,也不能匿改程序的结构。 试题程序: include<conio.h> include<stdio.h> //****found**** Prime(int m); { int j,P; p=1; //****found**** for(j=2;j<m;j++) if!(m%j) { p=0; break; } return(p);
int i,n; printf("\nplease enter an integer number between2 and 5000:"); scanf("%d",&n); printf("\n\nThe prime factor(s)of%d is(are):",n): for(i=2;i<n;i4+) if((!(n%i))&&(Prime(i))) printf("%4d,",i); printf("\n"); }

答案查题题库