《C++程序设计》课程设计说明书

上传人:沈*** 文档编号:41516243 上传时间:2021-11-20 格式:DOC 页数:27 大小:167KB
收藏 版权申诉 举报 下载
《C++程序设计》课程设计说明书_第1页
第1页 / 共27页
《C++程序设计》课程设计说明书_第2页
第2页 / 共27页
《C++程序设计》课程设计说明书_第3页
第3页 / 共27页
资源描述:

《《C++程序设计》课程设计说明书》由会员分享,可在线阅读,更多相关《《C++程序设计》课程设计说明书(27页珍藏版)》请在装配图网上搜索。

1、 《C++程序设计》 课 程 设 计 说 明 书 题目名称: 学生学号: 学生姓名: 指导老师: 2011年3月 25 目 录 第一部分 基础程序 1 一、程序代码 1 二、运行结果及分析 16 第二部分 综合问题 20 一、需求分析 20 二、设计 21 三、编码与调试 22 四、结果分析 23 五、参考资料 24 六、总结 25 第一部分 基础程序 一、 程序代码 (1) #include <iostream> using namespace std;

2、 const int max=100; void main() { int s[max],i,x,q,n=10; cout<<"输入个有序数列"<<endl; for(i=0;i<n;i++) cin>>s[i]; cout<<"数列为: "; for(i=0;i<n;i++) cout<<s[i]<<" "; cout<<"输入一个要插入的数"; cin>&g

3、t;x; for(i=0;i<n;i++) if(x<s[i]) { q=i; break; } else q=n; n++; for(i=n-2;i>=q;i--) s[i+1]=s[i]; s[q]=x; cout<<"输出"<<n<<"个有序数列为"; for(i=0;i<n;i++) cout<<s[i]<<" &q

4、uot;; } (2) #include <iostream> using namespace std; const int max=100; void main() { int s[max],i; int sum=0; cout<<"输入个数"<<endl; for(i=0;i<20;i++) cin>>s[i]; cout<<"数列为:"<<" "; for(i=0;i<

5、20;i++) cout<<s[i]; for(i=0;i<20;i++) if(s[i]%2==0) { cout<<s[i] <<" "; sum=s[i]+sum; } cout<<"和为"<<sum; } (3) #include <iostream> using namespace std; int lj(int i); void main () { int resul

6、t=0,n,i; cout<<"1+(1+2)+(1+2+3)+(1+2+..+n)"; cout <<"输入n:"<<endl; cin>>n; for(i=1;i<=n;i++) result=lj(i)+result; cout<<"和为"<<result<<endl; } int lj(int i) { int sum=0,a; for(a=1;a<=i;a++)

7、 sum=sum+a; return sum; } (4) #include <iostream> using namespace std; double ss(int n); void main () { int i; cout<<"50-100的素数有:"; for(i=50;i<=100;i++) if(ss(i)) cout<<i<<" "; } double ss(int n) { int i; for(i=2;i<

8、;n;i++) if(n%i==0)break; if(i==n) return 1; else return 0; } (5) #include <iostream> using namespace std; const int max=100; double aveage(int s[]); void main() { int s[max],i; double ave; cout<<"enter 10 students’ score"; for(i=0;i<10;i++)

9、 cin>>s[i]; ave=aveage(s); cout <<"ave is:"<<ave<<endl; } double aveage(int s[]) { int ave=0,i; for(i=0;i<10;i++) ave=ave+s[i]; return double (ave)/10; } (6) #include <iostream> using namespace std; double leg(char str[]);

10、void main () { char str[81]; cout <<"enter a char "; cin>>str; leg(str); cout<<str; } double leg(char str[]) { int n,i,temp; n=strlen(str); for(i=0;i<n/2;i++) { temp=str[i]; str[i]=str[n-1-i]; str[n-1-i]=temp; } r

11、eturn *str; } (7) #include <iostream> using namespace std; const int max=100; void main () { int n=10; int*p,s[max],*max,*min; int sum=0; double ave; cout<<"enter "<<n<<" numbers"; for(p=s;p<s+n;p++) cin>>*p; cout<&

12、lt;"number is: "; for(p=s;p<s+n;p++) cout<<*p<<" "; cout<<endl; max=s; min=s; for(p=s;p<s+n;p++) if(*p>*max)max=p; for(p=s;p<s+n;p++) if(*p<*min)min=p; cout<<"max is "<<*max<<endl; co

13、ut<<"min is "<<*min<<endl; for(p=s;p<s+n;p++) sum+=*p; ave=(1.0*sum)/n; cout<<"aveage is "<<ave<<endl; } (8) #include <iostream> using namespace std; const int max=100; void main() { char str1[81],str2[8

14、1]; char *p,*q; cout <<"enter a string"<<endl; cin>>str1; cout<<"enter another string"<<endl; cin>>str2; for(p=str1;*p!='\0';p++); for(q=str2;*p=*q;p++,q++); cout<<str1<<endl; } (9) #include &

15、lt;iostream> using namespace std; class score { private: int number; int computer; int English; double average; public: void inscore(double xx,double yy ,double zz); void showscore(); }; void score::inscore(double xx,double yy,double zz) { number=xx; compu

16、ter=yy; English=zz; average=(English+computer)/2.0; } void score::showscore() { cout<<"number"<<" "<<"computer"<<" "<<"English"<<endl; cout<<number<< " "<<comput

17、er<<" "<< English<<endl; cout<<"average is : "<< average<<endl; } void main() { int x,y,z; int x1,y1,z1; score stu1,stu2,*p=&stu2; cout<<"enter number and computer score .English score"<<e

18、ndl; cin>>x>>y>>z; cout<<"enter another number and computer score .English score"<<endl; cin>>x1>>y1>>z1; stu1.inscore(x,y,z); stu1.showscore(); stu2.inscore(x1,y1,z1); p->showscore(); } (10) #include<iostre

19、am> using namespace std; class student { int num; char sname[50]; double score; public: void setdata(); void display(); double getscore() { return score; } }; void student::setdata() { cout<<"enter student's number:"<<endl; cin>>

20、;num; cout<<"enter student's name:"<<endl; cin>>sname; cout<<"enter the score:"<<endl; cin>>score; } void student::display() { cout<<"number"<<" name"<<" "<<"sco

21、re"<<" "<<endl; cout<<num<<" "<<sname<<" " <<score<<endl; } class manage { int i,num; student s[80]; public: void input(int n); void sort(); void output(); }; void manage::input

22、(int n) { num=n; for(i=0;i<num;i++) s[i].setdata(); } void manage::sort() { student temp; int pos,j; for(i=0;i<num;i++) { pos=i; for( j=i;j<num;j++) if(s[j].getscore()>s[pos].getscore()) pos=j; if(pos!=j) { temp=s[pos];

23、 s[pos]=s[i]; s[i]=temp; } } } void manage:: output() { sort(); for(i=0;i<num;i++) { s[i].display(); } } void main() { int n; manage M; cout<<"how many students do you want to enter:"<<endl; cin>>n; M.input(n); M.output()

24、; } (11) #include<iostream> #include<string> using namespace std; class object { public: char name[50]; int number; }; class book:public object { private: char autour[50]; public: void set(); void display(); }; void book::set() { cout<<&qu

25、ot;书名:"<<endl; cin>>name; cout<<"作者:"<<endl; cin>>autour; } void book::display() { cout<<"书名: "; cout<<name<<endl; cout<<"作者: "; cout<<autour<<endl; cout<<"

26、;书号: "; cout<<number<<endl; } class reader:public object { private: int max; public: void set(); void display(); }; void reader::set() { cout<<"读者姓名:"<<endl; cin>>name; cout<<"最多借书数量:"&

27、lt;<endl; cin>>max; } void reader::display() { cout<<"读者姓名: "; cout<<name<<endl; cout<<"借书证号: "; cout<<number<<endl; cout<<"最多借书数量: "; cout<<max<<endl; }

28、 void main() { book p; reader q; cout<<"输入书号:\n"; cin>>p.number; p.set(); p.display(); cout<<"输入借书证号:\n"; cin>>q.number; q.set(); q.display(); } (12) #include<iostream> #include<cmath> using namespac

29、e std; const double PI=3.14; class shape { public: virtual double area()=0; }; class square:public shape { public: square(int m); double area(); private: int n; }; square::square(int m) { n=m; }; double square::area() { return n*n; } class circle:public shape { publi

30、c: circle(double r); double area() ; private: double radius; }; circle::circle(double r) { radius=r; } double circle::area() { return PI*radius*radius; } class Chang:public shape { public: Chang (int a,int b); double area(); private: int x; int y; }; Chang::Chang(in

31、t a,int b) { x=a; y=b; } double Chang::area() { return x*y; }class Triangle:public shape { public: Triangle(double x,double y,double z) ; double area(); private: double a; double b; double c; }; Triangle::Triangle(double x,double y,double z) { a=x; b=y; c=z; } doub

32、le Triangle::area() { double m,s; m=(a+b+c)/2; s=sqrt(m*(m-a)*(m-b)*(m-c)); return s; } void main() { int a,b,c,d,e,f,g; cout <<"输入 正方形边长 " ; cin>>a; shape *s=new square(a); cout<<"正方形面积:"<<s->area()<<endl; delet

33、e s; cout <<" 输入圆半径" ; cin>>b; shape *p=new circle(b); cout<<"圆面积:"<<p->area()<<endl; delete p; cout <<" 输入长,宽 " ; cin>>c>>d; shape *C=new C24hang(c,d); cout<<"长方形面积:"

34、<<C->area()<<endl; delete C; cout <<" 输入 三条边" ; cin>>e>>f>>g; shape *T=new Triangle(e,f,g); cout<<"三角形面积:"<<T->area()<<endl; delete T; } (13) #include<iostream.h> const int maxsize=100; t

35、emplate<class T> void sort(T s[],int n); void main() { int i,n; int s[maxsize]; char m[20]; cout<<"enter a numbers:\n"; cin>>n; cout<<"enter "<<n<<" numbers\n"; for(i=0;i<n;i++) cin>>s[i]; sort(s,n); c

36、out<<"sorted numbers:"<<endl; for(i=0;i<n;i++) cout<<s[i]<<" "; cout<<endl; cout<<"enter a numbes:\n"; cin>>n; cout<<"enter "<<n<<" string:\n"; for(i=0;i<n;i++) cin&

37、gt;>m[i]; sort(m,n); cout<<"sorted char:"<<endl; for(i=0;i<n;i++) cout<<m[i]<<" "; cout<<endl; } template<class T> void sort(T s[],int n) { int i,j,pos; for(i=0;i<n-1;i++) { pos=i; for(j=i;j<n;j++)

38、 if(s[j]>s[pos]) pos=j; if(pos!=i) { T t; t=s[i]; s[i]=s[pos]; s[pos]=t; } } } (14) #include<iostream> #include<fstream> using namespace std; void main() { char str[100]; int i=0; ifstream data("data.txt",ios::

39、in); ofstream data1("data1.txt",ios::out); if(!data) { cerr<<"cannor open file!"<<endl; abort(); } while(!data.eof()) { data.getline(str,100); data1<<++i<<"\t"<<str<<endl; cout<<str<<endl; }

40、 data.close(); data1.close(); cout<<"共"<<i<<" 行"; } 二、 运行结果及分析 第一题: 分析:需要 n++ 不然 丢一个数。 输入10个有序数列 1 2 3 4 5 6 7 8 9 10 数列为 : 1 2 3 4 5 6 7 8 9 10 输入一个要插入的数100 输出11个有序数列为 1 2 3 4 5 6 7 8 9 10 100 Press any key to continue 第二题: 输入20个数 1 2

41、 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 数列为 : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 偶数有: 2 4 6 8 10 12 14 16 18 20 和为110 Press any key to continue 第三题: 1+(1+2)+(1+2+3)+...+(1+2+3+....n)输入n: 5 和为35 Press any key to continue 第四题: 50-100之间的素数有:53 59 61

42、 67 71 73 79 83 89 97 Press any key to continue 第五题: enter 10 students' score1 2 3 4 5 6 7 8 9 10 ave is:5.5 Press any key to continue 第六题: 分析:先求串长 再将元素b[i]与 b[n-i]互换 结果: enter a char: abcd dcba Press any key to continue 第七题: 分析 enter 10 numbers1 2 3 4 5 6 7 8 9 10 number is: 1

43、 2 3 4 5 6 7 8 9 10 max is 10 min is 1 aveage is 5.5 Press any key to continue 第八题: 分析:先找到 ‘\0’再把第二个串的首地址接到\0上 。 enter a string cong enter another string bin congbin Press any key to continue 第九题: 分析:computer、english、average 。number是私有变量 指针型“score stu1,stu2,*p=&stu2; p->shows

44、core();” 结果: enter number and computer score .English score 1 99 100 enter another number and computer score .English score 2 78 98 number computer English 1 99 100 average is : 99.5 number computer English 2 78 98 average is : 88 Press any k

45、ey to continue 第十题: 分析: enter number and computer score .English score 1 99 100 enter another number and computer score .English score 2 78 98 number computer English 1 99 100 average is : 99.5 number computer English 2 78 98 average is : 88

46、 Press any key to continue 第十一题: 分析: 输入书号: 1 书名: sheeeeee 作者: cong 书名: sheeeeee 作者: cong 书号: 1 输入借书证号: 2008 读者姓名: bin 最多借书数量: 5 读者姓名: bin 借书证号: 2008 最多借书数量: 5 Press any key to continue 第十二题: 分析: 输入 正方形边长 2 正方形面积:4 输入 圆半径 2 圆面积:12.56 输入 长, 宽 2 3 长方形面积:6 输入 三条

47、边 3 4 5 三角形面积:6 Press any key to continue 第十三题: 分析: enter a numbers: 2 enter 2 numbers 12 23 sorted numbers: 23 12 enter a numbes: 2 enter 2 string: d g sorted char: g d Press any key to continue 第十四题: 分析:要新建 data。Txt文件夹 cong bin 共 2 行Press any key to continue 第二部分 综合问题

48、一、需求分析 需求分析即问题的描述,根据设计题目的要求,充分地分析和理解问题,明确问题要求做什么,限制条件是什么。在确定解决方案框架过程中,综合考虑系统功能,考虑怎样使系统结构清晰、合理、简单和易于调试。最后确定系统的功能模块以及模块之间的调用关系。 二、设计 分析对问题描述中涉及的操作对象定义相应的类,并按照以数据结构为中心的原则划分模块,定义主程序模块和各抽象数据类型。逻辑设计的结果应写出每个抽象数据类型的定义(包括数据结构的描述和每个基本操作的功能说明),各个主要模块的算法,定义相应的存储结构并写出伪

49、码算法。抽象数据类型的实现尽可能做到数据封装,基本操作的规格说明尽可能明确具体。确定每一个模块的算法流程,画出流程图。 把详细设计的结果进一步求精为程序设计语言程序,同时加入一些注解,使程序中逻辑概念清楚; 三、编码与调试 采用自底向上,分模块进行,即先调试低层函数。能够熟练掌握调试工具的各种功能,设计测试数据确定疑点,通过修改程序来证实它。调试正确后,认真整理源程序及其注释,形成格式和风格良好的源程序清单和结果;根据系统功能选择有代表性的数据进行测试,发现系统存在的不足并逐步改进。 注意:此部分不需要粘贴所有程序代码,对于程序主要运

50、行界面需要粘贴(如:主界面、查询界面等)。 四、结果分析 程序运行结果包括正确的输入及其输出结果和含有错误的输入及其输出结果,并加以文字分析。 五、参考资料 所查阅的书籍或资料 按下列例子中的格式书写: [1]王国荣编.Active Server Page &Web数据库.人民邮电出版社 [2]阮家栋等编.WEB数据库技术.科学出版社.2002.3 [3]贺利坚等编.数据库技术及应用.北京希望电子出版社.2002.7 [4]魏应彬等.网页设计与WEB数据库发布技术.清华大学出版社.2001.1 [5]张文增, 孙振国, 赵冬斌等.基于Web数据库的子集合查询技术.计算机应用.2002 Vol.22 No.1 六、总结 1.经验 2.存在的问题及进一步改进

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

相关资源

更多
正为您匹配相似的精品文档
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!