C++程序设计-实践报告

课程实践报告

设计题目: 程序设计(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. 在最后一次的成果展示上,我发现自己的程序缺乏创新,追求实用性,却忽略了其潜在

价值。


相关内容

  • 超市管理系统 C++实验报告
  • 信息学院 <C++程序设计实践课程> 实践报告 题目: 食品管理系统 专业: 信息管理与信息系统 班级: 0802班 学号: 完成日期: 2011年 6 月 1 日 姓名: 指导教师: 1.实践题目 食品管理系统:通过对C++的继承和派生的运用,开发一个管理食品,实现对基类食品的管理及对 ...

  • c++课程设计报告 掷骰子游戏
  • 目录 一.课题设计的内容与主要功能 . ............................ 2 1.1题目内容 ............................................ 2 1.2 功能 ..................................... ...

  • c++程序实习报告
  • 针对我们这学期学的c++,假期进行了五天的实习.第一天听老师讲实习内容和提示的时候觉得思路挺明确的一个程序,哪有传说中的那么难.下午和同学讨论的时候觉得很有目的,只要按部就班的完成各步操作就可以了,有难度的也只是第二步.这一步要进行判断,这就需要多个输出函数:还要冒泡法给工作排序,工资的计算不是在类 ...

  • 短信收发管理系统开题报告
  • 天津理工大学中环信息学院 本科毕业设计开题报告 届:2012系:计算机工程专业:软件工程2011年11月8日毕业设计 短信收发管理系统 题目 学生姓名 指导教师 一.课题研究背景 随着移动通信技术的迅速发展,作为移动通信的一种重要增值业务的SMS也得到了迅速的发展.随着使用SMS短信息业务的人越来越 ...

  • C++数据类型与表达式实验报告
  • <数据类型与表达式>实验报告 上机内容: 关于数据类型与表达式的练习 专业班级: 学 号: 姓 名: 日 期: 目录 ·1. 实验目的 (1)掌握C++语言数据类型,熟悉如何定义变量,以及对它们赋值的方法. (2)学会使用C++有关运算符,以及包含这些运算符的表达式. (3)进一步熟悉C ...

  • CC++经典书籍的经典点评
  • 初学者必备:C++经典入门详细教程 面的是学C++时要注意的. 1.把C++当成一门新的语言学习(和C没啥关系!真的.): 2.看<Thinking In C++>,不要看<C++变成死相>: 3.看<The C++ Programming Language>和& ...

  • C++高校人员信息管理系统
  • <基于C++的面向对象程序设计实例> 课程设计报告 课题名称 高校人员信息管理系统 专 业 计算机科学与技术 班 级 1220541 学 号 122054113 姓 名 苗鹏程 指导教师 (一).课程设计题目: 高校人员信息管理系统 (二).目的与要求: 1.目的: (1)要求学生达到熟 ...

  • C语言与C的区别
  • C语言与C++的区别.txt两人之间的感情就像织毛衣,建立的时候一针一线,小心而漫长,拆除的时候只要轻轻一拉....C/C++是指C语或C++,是指一系列的语言 C和C++的关系: 正如楼上所说的是win98跟winXP的关系.C++是在C的基础上增加了新的理论,玩出了新的花样.所以叫C加加. C和 ...

  • C++实验报告格式(1)
  • 福建农林大学东方学院 实验报告 课程名称: 面向对象程序设计 姓 名: 蔡燕双 系: 计算机系 专 业: 计算机科学与技术 年 级: 2010 学 号: 1060303034 指导教师: 王李进 职 称: 讲师 2011年 11 月 27 日 实验项目列表 福建农林大学东方学院实验报告 系: 计算机 ...