《《C++程序设计》课程设计说明书》由会员分享,可在线阅读,更多相关《《C++程序设计》课程设计说明书(27页珍藏版)》请在金锄头文库上搜索。
1、C+程序设计课 程 设 计 说 明 书题目名称:学生学号:学生姓名:指导老师:2011年3月4目 录第一部分 基础程序1一、程序代码1二、运行结果及分析16第二部分 综合问题20一、需求分析20二、设计21三、编码与调试22四、结果分析23五、参考资料24六、总结25第一部分 基础程序一、 程序代码(1) #include using namespace std;const int max=100;void main()int smax,i,x,q,n=10; cout输入个有序数列endl;for(i=0;isi;cout数列为: ;for(i=0;in;i+)coutsi ; coutx;
2、for(i=0;in;i+) if(x=q;i-) si+1=si; sq=x; cout输出n个有序数列为; for(i=0;in;i+) coutsi ; (2) #include using namespace std;const int max=100;void main()int smax,i;int sum=0; cout输入个数endl; for(i=0;isi;cout数列为: ;for(i=0;i20;i+)coutsi; for(i=0;i20;i+)if(si%2=0)coutsi ; sum=si+sum; cout和为sum; (3) #include using n
3、amespace std;int lj(int i);void main () int result=0,n,i; cout1+(1+2)+(1+2+3)+(1+2+.+n);cout 输入n:n;for(i=1;i=n;i+)result=lj(i)+result;cout和为resultendl;int lj(int i) int sum=0,a;for(a=1;a=i;a+) sum=sum+a;return sum; (4) #include using namespace std;double ss(int n);void main ()int i;cout50-100的素数有:;
4、for(i=50;i=100;i+)if(ss(i) couti ;double ss(int n)int i;for(i=2;in;i+)if(n%i=0)break;if(i=n)return 1;else return 0;(5) #include using namespace std;const int max=100;double aveage(int s);void main()int smax,i;double ave; coutenter 10 students score;for(i=0;isi;ave=aveage(s);cout ave is:aveendl;doubl
5、e aveage(int s)int ave=0,i;for(i=0;i10;i+)ave=ave+si;return double (ave)/10;(6) #include using namespace std;double leg(char str);void main () char str81; cout str; leg(str); coutstr;double leg(char str) int n,i,temp;n=strlen(str);for(i=0;in/2;i+) temp=stri; stri=strn-1-i; strn-1-i=temp;return *str;
6、(7)#include using namespace std;const int max=100;void main ()int n=10; int*p,smax,*max,*min;int sum=0;double ave;coutenter n numbers;for(p=s;p*p;coutnumber is: ;for(p=s;ps+n;p+)cout*p ;coutendl;max=s;min=s; for(p=s;p*max)max=p; for(p=s;ps+n;p+)if(*p*min)min=p; coutmax is *maxendl;coutmin is *minend
7、l; for(p=s;ps+n;p+)sum+=*p; ave=(1.0*sum)/n;coutaveage is aveendl;(8) #include using namespace std;const int max=100;void main() char str181,str281; char *p,*q; cout enter a stringstr1; coutenter another stringstr2; for(p=str1;*p!=0;p+); for(q=str2;*p=*q;p+,q+); coutstr1endl;(9) #include using names
8、pace std;class scoreprivate: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; computer=yy;English=zz;average=(English+computer)/2.0;void score:showscore()coutnumber c
9、omputer Englishendl;coutnumber computer Englishendl;coutaverage is : averageendl;void main()int x,y,z;int x1,y1,z1; score stu1,stu2,*p=&stu2;coutenter number and computer score .English scorexyz;coutenter another number and computer score .English scorex1y1z1; stu1.inscore(x,y,z);stu1.showscore(); s
10、tu2.inscore(x1,y1,z1);p-showscore(); (10) #includeusing namespace std;class studentint num; char sname50; double score;public:void setdata();void display();double getscore()return score;void student:setdata()coutenter students number:num;coutenter students name:sname;coutenter the score:score;void student:display()coutnumber name score endl;coutnum sname scoreendl;class manageint i,num;student s80;public: void input(int n); void sort(); void output();void manage:input(int n)nu