
南航c++(a)试卷.doc
11页南 京 航 空 航 天 大 学第 1 页 (共 11 页)《C++语言程序设计》考试试题 试卷代号:A班号 学号 姓名 题号 一 二 三 四 五 六 七 八 九 十 总分得分一.选择题: ( 每题 2 分,共 30 分, 请将正确答案写在题号左边 )1.在下列成对的表达式中,运算结果类型相同的一对是( ) A.7/2 和 7.0/2.0 B.7 /2.0 和 7/2C.7.0/2 和 7/2 D.7.0 /2.0 和 7.0/2 2.能正确表示“当 x 的取值在[1, 10]和[200, 210]范围内为真,否则为假”的表达式是( )A.(x>=1)&&(x=200)&&(x=1)||(x=200)||(x=1)&&(x=200)&&(x=1)||(x=200)||(xvoid main( ){ int x=4 ;if ( x++ > 5) coutvoid fun(int &x,int y,int *z){ int t=y; x=*z; *z=t; }void main( ){int a[3]={23,42,56};fun(a[0],a[1],cout int dtoh (int c[],int n){int i=0; while(n){ c[i++]=n%16; n/=16; }return(i);}void main() { int c[20], n=698, i;i=dtoh (c,n);本题分数 24得 分 第 4 页(共 11 页)for(i--;i>=0 ; i--) if (0#includeclass Student{ char Num[10]; char *Name; int Score; public:Student(char *nump, char *namep, int score) { if(nump) strcpy(Num, nump); else strcpy(Num, "");if(namep) { Name=new char[strlen(namep)+1];strcpy(Name, namep);}else Name=0;Score=score;cout class A{ int num1;static int num2;public:A( ) { num1=1; num2--; cout class A{protected: int x;public: A(int a=0){ x=a; }void Show( ) { cout class Sample{ int x, y;public: Sample( int a=0, int b=0){ x=a; y=b; coutadd( ); delete ptr;} 程序运行结果为: 。
8. #include class A{ int x;public:A() { x=10; }virtual void print() { coutprint(); pa= pa= } 程序运行结果为: 三.完善程序(每空 2 分,共 16 分)1.以下程序是用选择法对对数组 a 中的元素按由小到大顺序排序请填空:#include void sort(int a[],int n){ int i,j,p, t;for(i=0;iclass Node{ int data;(4) ;public: friend class List;};class List { Node *head;public:List(int d){ head = new Node; head->data = d; head->next = NULL; }List( ) { head = NULL; }void print( ) //输出链表{ Node *p;p=head;while(p!=NULL){ coutdatanext;delete p;}}};void main(){ List a(100); a.print(); } 第 8 页(共 11 页)3.将数值 1~100 及其平方根写入文件 sqrttable.txt #include (6) #include void main( ){ double x;ofstream out; (7) ; for(x=1; xnext (6) #include (7) out.open("sqrttable.txt ")(8) out.close()四、编程题(每题 10 分,共 30 分)1. #include void my_strcpy(char s1[],char s2[]) { int i;for(i=0;s2[i]!='\0';i++) s1[i]=s2[i];s1[i]='\0'; }void main(){ char a[20],b[10]; cin>>a>>b; 第 10 页(共 11 页)my_strcpy(a,b); coutclass Point{ int x,y; public: Point(int a=0,int b=0) { x = a; y = b; }friend Point operator ++(Point }friend Point operator ++(Point &m,int) { Point t=m;m.x++;m.y++;return t;}void Show() { cout#include class Point{protected: int x,y;public:Point(int a=0,int b=0){ x = a; y = b; } };class Line: public Point {protected: 第 11 页(共 11 页)int x1,y1;public:Line(int a=0,int b=0,int c=0,int d=0):Point(a,b) { x1 = c; y1 = d; }float LineLen() { return sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1)); } };class Rectangle: public Point {protected:int x1,y1;public:Rectangle(int a=0,int b=0,int c=0,int d=0):Point(a,b) { x1 = c; y1 = d; }float Area() { return float(abs(x-x1)*abs(y-y1)); } };void main(){ Line a(0,0,1,1); Rectangle b(2,2,4,4);cout<<"length="<
