node f1(5,6); node f2(f1); f2.Show();
}
问题一:类中定义了两个构造函数,其中一个是缺省参数的构造函数。但主函数中的对象要求有对应的形参,这个形参的正确定义是(5)
问题二:当对应的形参被正确定义后,执行结果依次是(6)
4. 程序输出的第一行是 7 ,第三行是 8 。
#include
#include
p1=s;p2=s+m-1;
cout<<\cout<<\while(p1 char s[]=”china”; fun(s,5); cout< 5. (6分) #include { x=a; cout<<\ A(A &s) { x=s.x+1; cout<<\ ~A(){cout<<\}; void main(void) { A f1(1), f2(f1); } 问题一:本程序共输出(9)行,类中的析构函数被访问(10)次 问题二: 各行的输出结果依次是(11) 6. (10分) #include 9. 4行 10. 2次 11. x=1 *A1* *A2* x=2 -A- x=1 -A- temp=*p1++; *p1=*p2--; *p2=temp; 7. china 8. caaca void main(){ enum ec{a,b,c,d,e}; char cp[]={'a','b','c','d','e'}; class Rect{ private: int width,hight,color; public: Rect(int x=10,int y=10,int c=a):width(x),hight(y),color(c){}; void SetRec(int w,int h,int c){width=w;hight=h;color=c;} int Area(){return width*hight;} Rect operator +(Rect b); void Display(); }; Rect Rect::operator +(Rect b){ Rect s; s.width=width+b.width; s.hight=hight+b.hight; s.color=(color+b.color)%5; return s; } void Rect::Display(){ cout<<\} void main(){ 12. 6行 Rect A(20,40,b),B(30,50,d); A.Display(); B.Display(); B.SetRec(50,70,e); B.Display(); A=A+B; A.Display(); cout<<\cout<<\ 13. w=20 h=40 c=b w=30 h=50 c=d w=50 h=70 c=e w=70 h=110 c=a A:7700 B:3500 } 问题一:本程序共输出(12)行 问题二: 各行的输出结果依次是(13) 7. (5分) #include long int f(int n) { if(n>1)return n-f(n-1); else return (1); } void main() { cout< 问题一:执行以上递归函数时,执行过程包括递推和回归两个过程,其中递推过程可分为以下4个步骤: 递推:① 5-f(4) ② 4-f(3) ③ 3-f(2) ④ 2-f(1) 当执行回归过程时,有两个步骤产生的结果相同。根据回归顺序,这两个步骤依次是第(14) 3 15.○2 步和第(15)步 14.○ 问题二:当递归函数执行完毕后,将结果返回给主函数调用语句的是以上步骤中的第(16)步,它执行的return语句是:return (17) 1 17. 5-f(4) 18. 3 问题三:程序的输出结果是(18) 16.○ 三、完善程序,并回答问题:(每空1分,共28分) 1. 确定一个数(例如i)是否为素数的算法是,只要2~i之间的所有自然数都不能整除i (其中i取整数),则i必为素数。显然,只要i能被其中任一个数整除,i必然不是素数。以下程序用于求300以内的素数,并按每行5个素数的格式输出。(9分) #include prime(int _(1)_,int _(2)_){ // 1.a 2. b int n; for(n=2;n<=a;n++)if(b%n==0)_(3)_ ; 3.break return(n); } void main(){ int k,i,j; cout<<2<<'\\t'<<3; for(k=2,i=5;i<300;i+=2){ j=sqrt(i); if(prime(j,i)>=_(4)_){ //4.j cout<<'\\t'< _(5)_; //5. k++ if(k%5==0)cout<<'\\n'; } } cout<<'\\n'; } 问题一:算法中是把(6)作为待求素数 A) 300以内的所有自然数 B) 300以内的所有奇数 C) 2~300之间的所有自然数 D) 5~300之间的所有奇数 问题二:算法中有一个变量用作求素数的除数,这个变量是(7),其中作为最大除数的变量是(8) 7. n 8. a 问题三:与A行预处理指令有关的语句是(9) //9.j=sqrt(i) 2. ball是关于球的类定义,其数据成员包括半径和重量。通过运算符重载实现对象的初始化(赋值)、两个对象相加和判断两个对象是否相等的运算。 #include float radii; float weight; ball(float x=0,float y=0) { _(10)_} //10. radii=x;weight=y; float getr( ){return radii;} float getw( ){return weight;} int operator ==(ball); public: void operator ( )(float,float); void operator +=(ball B); }; int ball::operator ==(ball B){ if(_(11)_) //11. radii==B.radii && weight==B.weight return 1; else return 0; } void ball::operator ( )(float a,float b){ _(12)_=a; //12. radii _(13)_=b; //13. weight } void ball::operator +=(ball B){ radii+=_(14)_; 14. B.radii weight+=_(15)_; 15. B.weight } void main( ){ ball a,b(30,500),c(40,600); a(b.getr()+10,b.getw()+100); cout<<\b+=c; cout<<\if(a==c) cout<<\球和c球相等!\else cout<<\球和c球不相等!\} 3. 使用结构体和指针建立链式成绩表,表中每个结点中包含的信息有学号,姓名,数学成绩和链指针。输入数据时指定学生人数,调用函数Addnew( ) 输入每个学生的信息,新结点插在链首。从键盘输入一个学号key,调用函数Search( )在已建立的结构链表中查找该学号所在的结点,若找到则输出姓名和成绩以及该结点在链表中的序号;若找不到则返回-1,输出提示信息。 #include int snum; char name[8]; float math; pupil *next; }; void Addnew(pupil *&head, int k){ pupil *p= 16 ; //16. new pupil cout<<\输入第\个学生的学号、姓名和数学成绩:\ } cin>>p->snum>>p->name>>p->math; if(head==0){p->next=0; head=p;} else{ p->next= 17 ; 17. head head = 18 ; 18. p } int Search(const pupil *head,const pupil *&t, int k){ const pupil *p; int i=0; p=head; while(p!=0){ } i++; if( 19 ) {t=p; return i;} //19.p.snum==k else p= 20 ; // 20. p->next return -1; } void main() { pupil *s=0,*first=0; int i, total, key; cout<<\请输入学生人数:\cin>> total ;