课程实践报告
设计题目: 程序设计(VC++)实践
设计时间 2013-1- 至 2013-1-
学院(系): 计算机科学与工程学院
2013年1月
一. 实践任务
选择题目,创新性题目可只选择1 题,仅选提高题应不少于3 题,仅选基础题应不少于6 题,也可组合选题,还可自行选择感兴趣的题目(须经指导老师审定)。对于提高题、创新题及游戏题可组成团队开发,但应制定详细的项目分工说明。
二.实验步骤及记录(题目,源程序代码及运行结果)
1. 与学号对应的题(必做题):基础题 12
题目:
建立一个STRING ,将一个字符串交叉插入到另一个字符串中(假定两字符串不
等长)。例如将字符串“abcde ” 交叉插入字符串“ABCDEFG ” 的结果为
“aAbBcCdDeEFG ”或“AaBbCcDdEeFG ”。
具体要求如下:
(1)私有数据成员
char str1[60] :存放被插入的字符串。
char str2[40] :存放待插入的字符串。
char str3[100] :存放插入后的字符串。
(2)公有成员函数
STRING (char *s1, char *s2 ):构造函数,用s1 和s2 初始化str1 和str2。
void process():将str2 中的字符串插入到str1 中,存放到str3 中。
void print():输出插入后的字符串。
(3)在主程序中定义STRING 类的对象test 对该类进行测试。
源程序代码:
#include
#include
class STRING{
char str1[60];
char str2[40];
char str3[100];
public:
STRING(char *s1,char *s2){
strcpy(str1,s1);
strcpy(str2,s2);
}
void process(){
char *p1=str1,*p2=str2;
for(int i=0;*p2;i=i+2){
for(int k=strlen(str1);k>=i;k--){
str1[k+1]=str1[k];
}
*p1=*p2;
p1=p1+2;
p2++;
}
}
void print(){
strcpy(str3,str1);
cout
}
};
void main(){
char s1[60]="ABCDEFG";
char s2[40]="abcde";
cout
cout
STRING test(s1,s2);
test.process();
test.print();
}
运行结果:
2-6为选做题,其中2,3,4为基础题;5,6为提高题。
2. 基础题 4
题目:
建立一个类MOVE ,将数组中最大元素的值与最小元素的值互换。
具体要求如下:
(1)私有数据成员
int *array:一维整型数组。
int n:数组中元素的个数。
(2)公有成员函数
MOVE(int b[],int m):构造函数,初始化成员数据。
void exchange():输出平均值,并将数组中的元素按要求重新放置。
void print():输出一维数组。
~MOVE():析构函数。
(3)在主程序中用数据{21,65,43,87,12,84,44,97,32,55}对该类进行测试。
源程序代码:
#include
class MOVE{
int *array;
int n;
public:
MOVE(int b[],int m){
n=m;
array=new int[m];
for(int i=0;i
array[i]=b[i];
}
void exchange(){
int b[10];
for(int k=0;k
b[k]=array[k];
for(int i=0;i
for(int j=i+1;j
if(b[j]>=b[i]){
int temp=b[i];
b[i]=b[j];
b[j]=temp;
}
int max=b[0],min=b[n-1];
for(int p=0;p
if(array[p]==max)array[p]=min;
else if(array[p]==min)array[p]=max;
}
}
void print(){
for(int i=0;i
coutcout
}
~MOVE(){delete [n]array;}
};
void main(){
int a[10]={21,65,43,87,12,84,44,97,32,55};
cout
for(int i=0;i
coutcout
cout
MOVE a1(a,10);
a1.exchange();
a1.print();
}
运行结果:
3. 基础题16
题目:
定义一个方阵类CMatrix ,并根据给定算法实现方阵的线性变换。方阵的变换形式 为:
F=W*fT
f 为原始矩阵,f T 为原始矩阵的转置,w 为变换矩阵,这里设定为
1 0 0 1
0 1 1 0
0 1 1 0
1 0 0 1
具体要求如下:
(1)私有数据成员
int (*a)[4]:a 指向方阵数组。
int w[4][4]:w 为变换矩阵。
int m:m 表示方阵的行和列数。
(2)公有成员函数
CMatrix (int a[][4],int m) :用给定的参数a 和m 初始化数据成员a 和m ;
对变换矩阵w 进行初始化,要求必须用循环实现。
void Transform () :根据上述变换算法,求出变换后的数组形式,存放在
原始数组内。
void show( ) :在屏幕上显示数组元素。
l~ CMatrix () :释放动态分配的空间。
(3)在主程序中定义数组int arr[][4]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}作为原 始数组。定义一个CMatrix 类对象test ,用arr 初始化test ,完成对该类的测试。 源程序代码:
#include
class CMatrix{
int (*a)[4];
int w[4][4];
int m;
public:
CMatrix(int a[][4],int m){
this->m=m;
this->a=new int[this->m][4];
for(int i=0;im;i++)
for(int j=0;jm;j++)
this->a[i][j]=a[i][j];
for(i=0;i
for( int j=0;j
if(i+j==3||i==j)w[i][j]=1;
else w[i][j]=0;
}
}
void Transform(){
int b[4][4];
for(int i=0;i
for(int j=0;j
b[i][j]=a[j][i];
}
for(int p=0;p
for(int q=0;q
a[p][q]=w[p][0]*b[0][q]+w[p][1]*b[1][q]+w[p][2]*b[2][q]+w[p][3]*b[3][q]; }
}
void show(){
for(int i=0;i
for(int j=0;j
coutcout
}
}
~CMatrix(){
delete [m]a;}
};
void main(){
int arr[][4]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
cout
for(int i=0;i
for(int j=0;j
coutcout
}
cout
CMatrix test(arr,4);
test.Transform();
test.show();
}
运行结果
4. 基础题 17
题目:
17.定义一个类SIN ,求 sin(x ) = x /1- x 3 / 3!+x 5 / 5!-x 7 / 7!+....+ (-1) n +1 x (2n -1) /(2n -1)! 具 体要求如下:
(1)私有成员数据。
int x:输入公式中x 的值,求sin(x)。
int n:输入公式中n 的值。
(2)公有成员函数。
SIN(int x, int n ):构造函数,用于初始化x 和n 的值。
int power( int q):求q! 的值。
l int mi( int m,int n):求m n 的值。
l int fun( ):用于求SIN(X)的值。
l void show( ):输出求得的结果。
(3)在主程序中定义对象test ,对该类进行测试
源程序代码:
#include
class SIN{
private: int x; int n;
public:
SIN(int x, int n){
this->x=x;
this->n=n;
}
int power(int q){
int s=1;
if(q
while(q>1){
s=s*q;
q--;
}
return s;
}
int mi(int m, int n){
int temp=1;
for(int i=1;i
{
temp*=m;
}
return temp;
}
int fun(){
int result=0;
for(int i=0;i
result+=mi(-1,i)*mi(x,2*i+1)/power(2*i+1);
}
return result;
}
void show(){
cout
};
void main(){
int x, n;
cout
cin>>x;
cout
cin>>n;
SIN test(x,n);
test.show();
}
运行结果:
5.提高题 9
题目:
设计一个程序通过虚函数求长方形的面积和长方体的表面积,具体要求如下:
(1)定义长方形类Rectangle
保护的数据成员
int l,w; //表示长方形的长和宽
int s; //表示长方形的面积
公有的构造函数
Rectangle(int x,int y):初始化长方形的长和宽;
公有的虚函数
virtual void fun():求长方形的面积;
virtual void show():输出长方形的长、宽和面积。
(2)定义长方形类A 的公有派生类Cuboid ,表示长方体类
私有的数据成员
int h; //表示长方体的高
公有的构造函数:
Cuboid(int x,int y,int z):初始化长方体的长、宽和高。
公有函数
void fun():求长方体的表面积;
void show():输出长方体的长、宽、高和表面积。
(3)在主函数中对定义的类进行测试,要求定义长方形对象a1(长为2,宽为3), 长方体对象b1(长、宽、高分别为2,3,4),通过基类的指针p 分别求长方形
的面积和长方体的表面积,输出数据成员,并体现运行的多态性。
源程序代码:
#include
class Rectangle{
protected:
int l,w;
int s;
public:
Rectangle(int x,int y){
l=x;
w=y;
}
virtual void fun(){
s=l*w;
}
virtual void show(){
cout
};
class Cuboid:public Rectangle{
int h;
public:
Cuboid(int x,int y,int z):Rectangle(x,y){
h=z;
}
void fun(){
s=2*(w*l+w*h+h*l);
}
void show(){
cout
}
};
void main(){
Rectangle *p;
Rectangle a1(2,3);
p=&a1;
p->fun();
p->show();
Cuboid b1(2,3,4);
p=&b1;
p->fun();
p->show();
}
运行结果:
6. 提高题10
题目:
设计一个程序,查询2000 年1 月1 日(星期六)后的某天是星期几,具体要求如 下:
(1)定义函数int leap(int year):判断某年year 是否为润年。能够被400 整除,或 者能够被4 整除但不能衩100 整除的年份是润年。
(2)定义函数int f(int y,int m,int d,int *m1,int *m2):判断输入的日期是否合法, 其中y 、m 、d 分别表示年、月、日,m1 表示非润年每月的天数,m2 表示润 年每月的天数。
(3)定义类date ,表示日期
私有数据成员
int year,month,day; //分别表示某年某月某日
公有成员函数:
date(int y,int m,int d):构造函数,用形参分别初始化数据成员;
int get_year():访问私有成员year ;
int get_month():访问私有成员month ;
int get_day():访问私有成员day ;
void show():以指定格式输出数据成员。
(4)定义类week ,判断某天是星期几
私有数据成员
date d1; //日期类的对象,表示某日
int m1[12];//存储非润年每月的天数31,28,31,30,31,30,31,31,30,31,30,31
int m2[12];//存储润年每月的天数31,29,31,30,31,30,31,31,30,31,30,31
int w;//表示用0 表示星期天,1 表示星期一,以此类推6 表示星期六
公有成员函数
week(int y,int m,int d,int *p1,int *p2):构造函数,用y,m,d 初始化日期,用
p1,p2 分别初始化m1,m2;
int days():计算d1 距2000 年1 月1 日的时间间隔(天数);
void fun():根据days()的计算结果判断d1 是星期几(求以0~6 表示w 的
值);
void print():输出判断结果。
(5)在主函数中对定义的类进行测试。从键盘输入一个日期,并检查输入数据的 合法性,然后用输入的数据和表示每月天数的数组初始化week 类的对象w ,
调用相关成员函数,输出判断结果。
程序运行结果如下:
请输入要查询的日期(年月日):2009 9 15
2009/9/15,是星期二。
源程序代码:
#include
int leap(int year){
if(year%400==0 || year%100!=0 && year%4==0)return 1;
else return 0;
}
int f(int y,int m,int d,int *m1,int *m2){
if((m==1||m==3||m==5||m==7||m==8||m==10||m==12)&&d>31)return 0;
else if((m==4||m==6||m==9||m==11)&&d>30)return 0;
else return 1;
while(leap(y))
if(m==2&&(d==28||d>=30))return 0;
else return 1;
while(!(leap(y)))
if(m==2&&(d==29||d>=30))return 0;
else return 1;
}
class date{
int year,month,day;
public:
date(int y,int m,int d){
year=y;
month=m;
day=d;
}
int get_year(){return year;}
int get_month(){return month;}
int get_day(){return day;}
void show(){
cout
}
};
class week{
date d1;
int m1[12];
int m2[12];
int w;
public:
week(int y,int m,int d,int *p1,int *p2):d1(y,m,d){
for(int i=0;i
m1[i]=p1[i];
for(int j=0;j
m2[i]=p2[i];
w=0;
}
int days(){
int i,j, result = 0;
for(j=2000;j
result+=(leap(j)+365);
for(i=1;i
if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)result+=31;
else if(i==4||i==6||i==9||i==11)result+=30;
else if(i==2)result+=(28+leap(j));
}
result=result+d1.get_day()-1;
return result;
}
void fun(){
switch(days()%7){
case 0:w=6;break;
case 1:w=0;break;
case 2:w=1;break;
case 3:w=2;break;
case 4:w=3;break;
case 5:w=4;break;
case 6:w=5;break;
}
}
void print(){
switch(w){
case 6:cout
case 0:cout
case 1:cout
case 2:cout
case 3:cout
case 4:cout
case 5:cout
}
}
};
void main(){
int m1[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int m2[12]={31,29,31,30,31,30,31,31,30,31,30,31};
cout
int a,b,c;
cin>>a>>b>>c;
cout
f(a,b,c,m1,m2);
week w(a,b,c,m1,m2);
date M(a,b,c);
M.show();
w.fun();
w.print();
}
运行结果:
三.实践小结
1. 通过选择不同类型,不同难度层次的题目,有效地复习了一学期以来C++的学习内容。
2. 实践过程中通过个人思考及小组合作,对细节之处和难点进行了有效的分析,极大地提
高了学习效率。
3. 通过对题目的分析和理解,我发现自己在字符串处理,指针等方面基础较好,而在虚函
数,友元函数等较琐碎的知识掌握得不太透彻,这是寒假期间我在准备等级考试所要留心的地方。
4. 这次的课程实践在一定程度上是为即将到来的计算机二级考试打下良好的基础。
5. 在最后一次的成果展示上,我发现自己的程序缺乏创新,追求实用性,却忽略了其潜在
价值。
课程实践报告
设计题目: 程序设计(VC++)实践
设计时间 2013-1- 至 2013-1-
学院(系): 计算机科学与工程学院
2013年1月
一. 实践任务
选择题目,创新性题目可只选择1 题,仅选提高题应不少于3 题,仅选基础题应不少于6 题,也可组合选题,还可自行选择感兴趣的题目(须经指导老师审定)。对于提高题、创新题及游戏题可组成团队开发,但应制定详细的项目分工说明。
二.实验步骤及记录(题目,源程序代码及运行结果)
1. 与学号对应的题(必做题):基础题 12
题目:
建立一个STRING ,将一个字符串交叉插入到另一个字符串中(假定两字符串不
等长)。例如将字符串“abcde ” 交叉插入字符串“ABCDEFG ” 的结果为
“aAbBcCdDeEFG ”或“AaBbCcDdEeFG ”。
具体要求如下:
(1)私有数据成员
char str1[60] :存放被插入的字符串。
char str2[40] :存放待插入的字符串。
char str3[100] :存放插入后的字符串。
(2)公有成员函数
STRING (char *s1, char *s2 ):构造函数,用s1 和s2 初始化str1 和str2。
void process():将str2 中的字符串插入到str1 中,存放到str3 中。
void print():输出插入后的字符串。
(3)在主程序中定义STRING 类的对象test 对该类进行测试。
源程序代码:
#include
#include
class STRING{
char str1[60];
char str2[40];
char str3[100];
public:
STRING(char *s1,char *s2){
strcpy(str1,s1);
strcpy(str2,s2);
}
void process(){
char *p1=str1,*p2=str2;
for(int i=0;*p2;i=i+2){
for(int k=strlen(str1);k>=i;k--){
str1[k+1]=str1[k];
}
*p1=*p2;
p1=p1+2;
p2++;
}
}
void print(){
strcpy(str3,str1);
cout
}
};
void main(){
char s1[60]="ABCDEFG";
char s2[40]="abcde";
cout
cout
STRING test(s1,s2);
test.process();
test.print();
}
运行结果:
2-6为选做题,其中2,3,4为基础题;5,6为提高题。
2. 基础题 4
题目:
建立一个类MOVE ,将数组中最大元素的值与最小元素的值互换。
具体要求如下:
(1)私有数据成员
int *array:一维整型数组。
int n:数组中元素的个数。
(2)公有成员函数
MOVE(int b[],int m):构造函数,初始化成员数据。
void exchange():输出平均值,并将数组中的元素按要求重新放置。
void print():输出一维数组。
~MOVE():析构函数。
(3)在主程序中用数据{21,65,43,87,12,84,44,97,32,55}对该类进行测试。
源程序代码:
#include
class MOVE{
int *array;
int n;
public:
MOVE(int b[],int m){
n=m;
array=new int[m];
for(int i=0;i
array[i]=b[i];
}
void exchange(){
int b[10];
for(int k=0;k
b[k]=array[k];
for(int i=0;i
for(int j=i+1;j
if(b[j]>=b[i]){
int temp=b[i];
b[i]=b[j];
b[j]=temp;
}
int max=b[0],min=b[n-1];
for(int p=0;p
if(array[p]==max)array[p]=min;
else if(array[p]==min)array[p]=max;
}
}
void print(){
for(int i=0;i
coutcout
}
~MOVE(){delete [n]array;}
};
void main(){
int a[10]={21,65,43,87,12,84,44,97,32,55};
cout
for(int i=0;i
coutcout
cout
MOVE a1(a,10);
a1.exchange();
a1.print();
}
运行结果:
3. 基础题16
题目:
定义一个方阵类CMatrix ,并根据给定算法实现方阵的线性变换。方阵的变换形式 为:
F=W*fT
f 为原始矩阵,f T 为原始矩阵的转置,w 为变换矩阵,这里设定为
1 0 0 1
0 1 1 0
0 1 1 0
1 0 0 1
具体要求如下:
(1)私有数据成员
int (*a)[4]:a 指向方阵数组。
int w[4][4]:w 为变换矩阵。
int m:m 表示方阵的行和列数。
(2)公有成员函数
CMatrix (int a[][4],int m) :用给定的参数a 和m 初始化数据成员a 和m ;
对变换矩阵w 进行初始化,要求必须用循环实现。
void Transform () :根据上述变换算法,求出变换后的数组形式,存放在
原始数组内。
void show( ) :在屏幕上显示数组元素。
l~ CMatrix () :释放动态分配的空间。
(3)在主程序中定义数组int arr[][4]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}作为原 始数组。定义一个CMatrix 类对象test ,用arr 初始化test ,完成对该类的测试。 源程序代码:
#include
class CMatrix{
int (*a)[4];
int w[4][4];
int m;
public:
CMatrix(int a[][4],int m){
this->m=m;
this->a=new int[this->m][4];
for(int i=0;im;i++)
for(int j=0;jm;j++)
this->a[i][j]=a[i][j];
for(i=0;i
for( int j=0;j
if(i+j==3||i==j)w[i][j]=1;
else w[i][j]=0;
}
}
void Transform(){
int b[4][4];
for(int i=0;i
for(int j=0;j
b[i][j]=a[j][i];
}
for(int p=0;p
for(int q=0;q
a[p][q]=w[p][0]*b[0][q]+w[p][1]*b[1][q]+w[p][2]*b[2][q]+w[p][3]*b[3][q]; }
}
void show(){
for(int i=0;i
for(int j=0;j
coutcout
}
}
~CMatrix(){
delete [m]a;}
};
void main(){
int arr[][4]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
cout
for(int i=0;i
for(int j=0;j
coutcout
}
cout
CMatrix test(arr,4);
test.Transform();
test.show();
}
运行结果
4. 基础题 17
题目:
17.定义一个类SIN ,求 sin(x ) = x /1- x 3 / 3!+x 5 / 5!-x 7 / 7!+....+ (-1) n +1 x (2n -1) /(2n -1)! 具 体要求如下:
(1)私有成员数据。
int x:输入公式中x 的值,求sin(x)。
int n:输入公式中n 的值。
(2)公有成员函数。
SIN(int x, int n ):构造函数,用于初始化x 和n 的值。
int power( int q):求q! 的值。
l int mi( int m,int n):求m n 的值。
l int fun( ):用于求SIN(X)的值。
l void show( ):输出求得的结果。
(3)在主程序中定义对象test ,对该类进行测试
源程序代码:
#include
class SIN{
private: int x; int n;
public:
SIN(int x, int n){
this->x=x;
this->n=n;
}
int power(int q){
int s=1;
if(q
while(q>1){
s=s*q;
q--;
}
return s;
}
int mi(int m, int n){
int temp=1;
for(int i=1;i
{
temp*=m;
}
return temp;
}
int fun(){
int result=0;
for(int i=0;i
result+=mi(-1,i)*mi(x,2*i+1)/power(2*i+1);
}
return result;
}
void show(){
cout
};
void main(){
int x, n;
cout
cin>>x;
cout
cin>>n;
SIN test(x,n);
test.show();
}
运行结果:
5.提高题 9
题目:
设计一个程序通过虚函数求长方形的面积和长方体的表面积,具体要求如下:
(1)定义长方形类Rectangle
保护的数据成员
int l,w; //表示长方形的长和宽
int s; //表示长方形的面积
公有的构造函数
Rectangle(int x,int y):初始化长方形的长和宽;
公有的虚函数
virtual void fun():求长方形的面积;
virtual void show():输出长方形的长、宽和面积。
(2)定义长方形类A 的公有派生类Cuboid ,表示长方体类
私有的数据成员
int h; //表示长方体的高
公有的构造函数:
Cuboid(int x,int y,int z):初始化长方体的长、宽和高。
公有函数
void fun():求长方体的表面积;
void show():输出长方体的长、宽、高和表面积。
(3)在主函数中对定义的类进行测试,要求定义长方形对象a1(长为2,宽为3), 长方体对象b1(长、宽、高分别为2,3,4),通过基类的指针p 分别求长方形
的面积和长方体的表面积,输出数据成员,并体现运行的多态性。
源程序代码:
#include
class Rectangle{
protected:
int l,w;
int s;
public:
Rectangle(int x,int y){
l=x;
w=y;
}
virtual void fun(){
s=l*w;
}
virtual void show(){
cout
};
class Cuboid:public Rectangle{
int h;
public:
Cuboid(int x,int y,int z):Rectangle(x,y){
h=z;
}
void fun(){
s=2*(w*l+w*h+h*l);
}
void show(){
cout
}
};
void main(){
Rectangle *p;
Rectangle a1(2,3);
p=&a1;
p->fun();
p->show();
Cuboid b1(2,3,4);
p=&b1;
p->fun();
p->show();
}
运行结果:
6. 提高题10
题目:
设计一个程序,查询2000 年1 月1 日(星期六)后的某天是星期几,具体要求如 下:
(1)定义函数int leap(int year):判断某年year 是否为润年。能够被400 整除,或 者能够被4 整除但不能衩100 整除的年份是润年。
(2)定义函数int f(int y,int m,int d,int *m1,int *m2):判断输入的日期是否合法, 其中y 、m 、d 分别表示年、月、日,m1 表示非润年每月的天数,m2 表示润 年每月的天数。
(3)定义类date ,表示日期
私有数据成员
int year,month,day; //分别表示某年某月某日
公有成员函数:
date(int y,int m,int d):构造函数,用形参分别初始化数据成员;
int get_year():访问私有成员year ;
int get_month():访问私有成员month ;
int get_day():访问私有成员day ;
void show():以指定格式输出数据成员。
(4)定义类week ,判断某天是星期几
私有数据成员
date d1; //日期类的对象,表示某日
int m1[12];//存储非润年每月的天数31,28,31,30,31,30,31,31,30,31,30,31
int m2[12];//存储润年每月的天数31,29,31,30,31,30,31,31,30,31,30,31
int w;//表示用0 表示星期天,1 表示星期一,以此类推6 表示星期六
公有成员函数
week(int y,int m,int d,int *p1,int *p2):构造函数,用y,m,d 初始化日期,用
p1,p2 分别初始化m1,m2;
int days():计算d1 距2000 年1 月1 日的时间间隔(天数);
void fun():根据days()的计算结果判断d1 是星期几(求以0~6 表示w 的
值);
void print():输出判断结果。
(5)在主函数中对定义的类进行测试。从键盘输入一个日期,并检查输入数据的 合法性,然后用输入的数据和表示每月天数的数组初始化week 类的对象w ,
调用相关成员函数,输出判断结果。
程序运行结果如下:
请输入要查询的日期(年月日):2009 9 15
2009/9/15,是星期二。
源程序代码:
#include
int leap(int year){
if(year%400==0 || year%100!=0 && year%4==0)return 1;
else return 0;
}
int f(int y,int m,int d,int *m1,int *m2){
if((m==1||m==3||m==5||m==7||m==8||m==10||m==12)&&d>31)return 0;
else if((m==4||m==6||m==9||m==11)&&d>30)return 0;
else return 1;
while(leap(y))
if(m==2&&(d==28||d>=30))return 0;
else return 1;
while(!(leap(y)))
if(m==2&&(d==29||d>=30))return 0;
else return 1;
}
class date{
int year,month,day;
public:
date(int y,int m,int d){
year=y;
month=m;
day=d;
}
int get_year(){return year;}
int get_month(){return month;}
int get_day(){return day;}
void show(){
cout
}
};
class week{
date d1;
int m1[12];
int m2[12];
int w;
public:
week(int y,int m,int d,int *p1,int *p2):d1(y,m,d){
for(int i=0;i
m1[i]=p1[i];
for(int j=0;j
m2[i]=p2[i];
w=0;
}
int days(){
int i,j, result = 0;
for(j=2000;j
result+=(leap(j)+365);
for(i=1;i
if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)result+=31;
else if(i==4||i==6||i==9||i==11)result+=30;
else if(i==2)result+=(28+leap(j));
}
result=result+d1.get_day()-1;
return result;
}
void fun(){
switch(days()%7){
case 0:w=6;break;
case 1:w=0;break;
case 2:w=1;break;
case 3:w=2;break;
case 4:w=3;break;
case 5:w=4;break;
case 6:w=5;break;
}
}
void print(){
switch(w){
case 6:cout
case 0:cout
case 1:cout
case 2:cout
case 3:cout
case 4:cout
case 5:cout
}
}
};
void main(){
int m1[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int m2[12]={31,29,31,30,31,30,31,31,30,31,30,31};
cout
int a,b,c;
cin>>a>>b>>c;
cout
f(a,b,c,m1,m2);
week w(a,b,c,m1,m2);
date M(a,b,c);
M.show();
w.fun();
w.print();
}
运行结果:
三.实践小结
1. 通过选择不同类型,不同难度层次的题目,有效地复习了一学期以来C++的学习内容。
2. 实践过程中通过个人思考及小组合作,对细节之处和难点进行了有效的分析,极大地提
高了学习效率。
3. 通过对题目的分析和理解,我发现自己在字符串处理,指针等方面基础较好,而在虚函
数,友元函数等较琐碎的知识掌握得不太透彻,这是寒假期间我在准备等级考试所要留心的地方。
4. 这次的课程实践在一定程度上是为即将到来的计算机二级考试打下良好的基础。
5. 在最后一次的成果展示上,我发现自己的程序缺乏创新,追求实用性,却忽略了其潜在
价值。