有以下程序: Class Date { public: Date(int y,int m,mt d); { year=y; month=m; day=d; } Date(int y=2000) { year=y; month=10; day=1; } Date(Date &D) { year=d.year; month=d.month; day=d.day; } Void prin
A.2
B.3
C.4
D.5
下列程序的运行结果是( )。
#include<stdio.h>
main()
{stmct date
{int year,month,day;
}today;
primf("%d\n",sizeof(struct date));
}
A.8
B.6
C.10
D.12
下列程序的运行结果为( )
#include<stdio.h>
main()
{ struc tdate
{int year,month,day;
)today;
printf("%d\n",sizeof(struct date));
}
A.8
B.6
C.10
D.12
已知学生记录描述为 struct student { int no; char name[20]; char sex; struct { int year; int month; int day; } birth; }; struct student s;变量s中的“生日”应是“1985年4月4日”,下列对“生日”的正确赋值方式是______。
A.year=1985;month=4;day=4;
B.birth.year=1985;birth.month=4;birth.day=4;
C.s.year=1985;s.month=4;s.day=4;
D.s.birth.year=1985;s.birth.month=4;s.birth,day=4;
有以下程序:
class Date
{
public:
Date(int y,int m,int d);
{
year=y;
month=m
day=d;
}
Date(int y=2000)
{
year=y;
month=10;
day=1;
}
Date(Date &d)
{
year=d.year;
month=d.month;
day=d.day;
}
void print( )
{
cout<<year<<"."<<month<<"."<<day<<endl;
}
private:
int year,month,day;
};
Date fun(Date d)
{
Date temp;
temp=d;
return temp;
}
int main( )
{
Date datel(2000,1,1),date2(0,0,0);
Date date3(datel);
date2=fun(date3);
return 0;
}
程序执行时,Date类的拷贝构造函数被调用的次数是
A.2
B.3
C.4
D.5
系统测试题51.输入某年某月某日,判断这一天是这一年的第几天?#include main() int day,month,year,sum,leap; printf(nplease input year,month,dayn); scanf(%d,%d,%d,&year,&month,&day); switch(month) case 1:sum=0;break; case 2:sum=31;break; case 3:sum=59;break; /*SPACE*/ case 4:【?】;break; case 5:sum=120;break; case 6:sum=151;break; case 7:sum=181;break; case 8:sum=212;break; case 9:sum=243;break; case 10:sum=273;break; case 11:sum=304;break; case 12:sum=334;break; default:printf(data error);break; /*SPACE*/ 【?】; /*SPACE*/ if(year%400=0|(【?】) leap=1; else leap=0; /*SPACE*/ if(【?】) sum+; printf(it is the %dth day.,sum);2.已知X、Y、Z分别表示09中不同的数字,编程求出使算式 XXXX+YYYY+ZZZZ=YXXXZ成立时X、Y、Z的值,并要求打印该算式。#include #include main() int x,y,z; /*SPACE*/ for(x=0;【?】;x+) for(y=0;y10;y+) if(y=x) continue; for(z=0;z10;z+) /*SPACE*/ if(z=x【?】z=y) continue; /*SPACE*/ if(1111*(x+y+z)=【?】+1110*x+z) printf(x=%d,y=%d,z=%dn,x,y,z); /*SPACE*/ printf(%d+%d+%d=%dn,1111*x,1111*y,1111*z,【?】); exit(0); 3.编程求任意给两个日期(Y0年M0月DO日和Y1年M1月D1日)相差的天数。#include #include int f(int y) return(y%4=0&y%100!=0|y%400=0);int mday(int y,int m) return(31-(m=4)+(m=6)+(m=9)+(m=11)-(3-f(y)*(m=2);int yday(int y,int m,int d) return(d+31*(m1)+(m3)+(m5)+(m7)+(m8)+(m10)+30*(m4)+(m6)+(m9)+(m11)+(28+f(y)*(m2);int yend(int y,int m,int d) return(365+f(y)-yday(y,m,d);main() int y1,m1,d1,y2,m2,d2,n,i; printf(y1,m1,d1=); scanf(%d,%d,%d,&y1,&m1,&d1); /*SPACE*/ if(m112|d1【?】) exit(0); printf(y2,m2,d2=);scanf(%d,%d,%d,&y2,&m2,&d2); /*SPACE*/ if(m212|d2【?】) exit(0); if(y1y2|y1=y2&m1m2|y1=y2&m1=m2&d1d2) n=y1; y1=y2; y2=n; n=m1; m1=m2; m2=n; n=d1; d1=d2; d2=n; else /*SPACE*/ n=yend(y1,m1,d1)+【?】; /*SPACE*/ for(i=【?】;i%d.%d.%d:n=%dn,y1,m1,d1,y2,m2,d2,n);4.用二分法求方程2X3+4X2+3X-6=0在(-10,10)之间的根 ,其中 Xn代表X的n次方。#include # include main() float x0,x1,x2,fx0,fx1,fx2; do printf(Enter x1&x2:); scanf(%f,%f,&x1,&x2); fx1=x1*(2*x1-4)*x1+3)-6; fx2=x2*(2*x2-4)*x2+3)-6; /*SPACE*/ while (fx1*fx2【?】); do x0=(x1+x2)/2; fx0=x0*(2*x0-4)*x0+3)-6; /*SPACE*/ if(fx0*fx1【?】) x2=x0; fx2=fx0; else x1=x0; fx1=fx0; /*SPACE*/ while(【?】=1e-5); printf(x=%6.2fn,x0);5.不用第三个变量,实现两个数的对调操作。#include main() int a,b; scanf(%d %d,&a,&b); printf(a=%d,b=%dn,a,b); /*SPACE*/ a= 【?】 ;
已知学生记录描述为:
struct student
{ int no;
char name[20],sex;
struct
{ int year,month,day;
} birth;
};
struct student s;
设变量s中的"生日"是"1984年11月12日",对"birth"正确赋值的程序段是
A.year=1984;month=11;day=12;
B.s.year=1984;s.month=11;s.day=12;
C.birth.year=1984;birth.month=11;birth.day=12;
D.s.birth.year=1984;s.birth.month=11;s.birth.day=12;
已知学生记录描述为: struct student { int no; char name[20],sex; struct { int year,month,day; } birth; }; struct student s; 设变量s中的“生日”是“1984年11月12日”,对“birth”正确赋值的程序段是( )。
A.year=1984;month=11;day=12;
B.s.year=1984;s.month=11;s.day=12;
C.birth.year=1984;birth.month=11;birth.day=12;
D.s.birth.year=1984;s.birth.month=11;s.birth.day=12;
有以下程序: class Date { public: Date(int y,int m,int D) ; { year =y; month=m; day=d; } Date(int y=2000) { year=y; month=10; day=1; } Date(Date &D) { year=d.year; month=d.month; day=d.day; } void print () { cout<<year<<"."<<month<<"."<<day<<end1; } private: int year,month,day; }; Date fun(Date D) { Date temp; temp=d; return temp; } int main() { Date date1(2000,1,1),date2(0,0,0); Date date3(date1); date2=fun(date3); return 0; } 程序执行时,Date类的拷贝构造函数被调用的次数是
A.2
B.3
C.4
D.5
下面结构体的定义语句中,不正确的是______。
A.structdate { int month; int day; int year; } Struct date datel;
B.stmctdate { intmonth; int day; int year; } datel;
C.struct { int month; int day; int year; } date 1;
D.#define DATE stmct date DATE { int month; int day; int year; }datel;
有以下程序 #include <iostream> using namespace std; static int days[]= { 31,28,31,30,31,30,31,31,30,31,30,31 }; class date { private: int month, day, year; public: date( int m, int d, int y ) { month = m; day = d; year = y; } date() {} void disp() { cout<<year<<"-"<<month<<"-"<<day<<end1; } date operator+( int day ) { date dt = *this; day+= dt.day; while ( day > days[dt.month - 1 ] ) { day -= days[ dt.month - 1 ]; if ( ++dt.month == 13 ) { dt.month = 1; dt.year++; } } dt.day = day; return dt; }; int main() { date d1( 6, 20, 2004 ), d2; d2: d1 + 20; d2.disp(); return 0; } 执行后的输出结果是
A.2004-7-10
B.2004-6-20
C.2004-7-20
D.程序编译时出错