ImageVerifierCode 换一换
格式:DOCX , 页数:25 ,大小:21.10KB ,
资源ID:10619080      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/10619080.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(这学期c++习题电子科大版.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

这学期c++习题电子科大版.docx

1、这学期c+习题电子科大版这学期c+习题,全是自己写的,绝对正确!适用于西安电子科大的教材P35 T(1)完数#include#includeint main() int i,j; for(i=2;i=999;i+) inttemp=0; for(j=1;ji;j+) if(i%j=0) temp+=j; if(i=temp) coutiendl; P35 T(2)九九乘法表#include#includeint main() int i,j,k,m; cout*t; for(m=1;m=9;m+) coutmt; coutn; for(m=0;m=24;m+) cout_; coutn; fo

2、r(i=1;i=9;i+)/控制行 coutit; for(j=1;j=9;j+)/控制列 k=j*i;coutkt; coutn; P36 T(3)判断成绩#include#include#includebool IsNum(char *s);void main() int N; char s100; do/判断是否为数字,是,IsNum(S)返回true coutPleaseinput a score!s; while(!IsNum(s); N=atoi(s);/把字符串转为整型数 if(N=100) coutAendl; else switch(N/10) case6:coutDendl

3、;break; case7:coutCendl;break; case8:coutBendl;break; case9:coutAendl;break; default:coutEendl; bool IsNum(char *s) for(inti=0;istrlen(s);i+) if(siint(9) returnfalse; return true;P64 T(1)递归求10以内加法#includeint add(int k) int num; if(k=0) num=0; else num=k+add(k-1); return num;void main() int i; i=10;

4、i=add(i); couti;P64 T(2)递归求Fibonacci级数#includeint js(int n) if(n=1 |n=2) return 1; else returnjs(n-1)+js(n-2);int main() int n; coutn; int *a= newintn; for(inti=1;i=n;i+ ai-1=js(i); coutai-1 ; return 0;P64 T(3)绝对值函数模板#includetemplate/利用函数模板求绝对值double absolute(X j) if (j=0) return j; else return -1*j

5、;void main() double i; couti; i=absolute(i); couti;P64 T(4)非类实现Rectangle的面积和周长#include#includevoid computeTriangle(float &a,float &p,floatx,float y,float z) float m; a=x+y+z; m =0.5*(x+y+z); p =sqrt(m*(m-x)*(m-y)*(m-z);/海伦公式void main() floati,j,k,s,c; c=0,s=0; coutPleaseenter the length of the three

6、 sides of the triangle ijk; computeTriangle(c,s,i,j,k); coutcsendl;P64 T(7)小于1000平方和#includevoid main() int i,d; d=0; for(i=1;d1000;i+) d+=(i*i); couti-2;P120 T(1)类实现rectangle#includeclass rectangle private: floatx1,y1,x2,y2; public: rectangle(floatxx1 ,float yy1,float xx2,float yy2); floatarea();re

7、ctangle:rectangle(float xx1 ,float yy1,float xx2,floatyy2)x1=xx1;y1=yy1;x2=xx2;y2=yy2;float rectangle:area()return (x1-x2)*(y1-y2);void main() floatx1,y1,x2,y2; float result; coutPleaseenter the coordinate values of the rectangle on the upper left corner!(forexample:0 0) x1y1; coutPleaseenter the co

8、ordinate values of the rectangle on the lower right corner!(forexample:1 1) x2y2; rectanglePo(x1,y1,x2,y2); result =Po.area(); coutresult;P120 T(2) complex类的构造和拷贝构造函数#includeclass complex private: floatreal; floatimaginary; public: complex(floata=0,float b=0) real=a;imaginary=b; complex(complex&temp

9、); floatPrintReal() returnreal; floatPrintimaginary() returnimaginary;complex:complex(complex &temp) real=temp.real; imaginary=temp.imaginary; cout拷贝构造函数被调用!;void f(complex temp) couttemp.PrintReal()temp.Printimaginary()endl;complex r(float a, float b) complexq(a,b); return q;void main() float a,b;

10、coutPleaseenter the real part of the complex!a; coutPleaseenter the imaginary part of the complex!b; complexq(a,b); complex m(q); coutm.PrintReal()m.Printimaginary()endl; f(m); m=r(a,b); coutm.PrintReal()m.Printimaginary()endl;P120类组合求复数加法#includeclass complex private: floatreal; floatimaginary; pub

11、lic: complex(floata,float b) real=a; imaginary=b; floatget_real() returnreal; floatget_imaginary() returnimaginary;class plus private: floatplus_real,plus_imaginary; complexa,b; public: plus(complexxa,complex xb ):a(xa),b(xb) plus_real=a.get_real()+b.get_real(); plus_imaginary=a.get_imaginary()+b.ge

12、t_imaginary(); floatget_r() returnplus_real; floatget_i() returnplus_imaginary; ;void main() float m,n,o,p; coutPleaseenter the real value of the complexm; coutPleaseenter the imaginary value of the complexn; complexsa(m,n); coutPleaseenter the real value of the complexo; coutPleaseenter the imagina

13、ry value of the complexp; complexsb(o,p); plussc(sa,sb); coutTheresult is endl; coutsc.get_r()+sc.get_i()eendl;P120类模板求最大最小值#includetemplateclass compare private: Ta,b; public: compare(Tx,T y) a=x;b=y; voidprint() if(ab) coutThemaximum is aand the minimum is bendl; elseif(a=b) couta=bendl; else cout

14、Themaximum is band the minimum is aendl; ;void main() int x,y; float m,n; coutPleaseenter two Integers !xy; compare p(x, y); p.print(); coutPleaseenter two decimals !mn; compare q( m, n); q.print();P154 T(1)静态数据成员cat#includeclass Cat private: staticint HowManyCats; public: Cat()HowManyCats+; Cat(Cat

15、 &c)HowManyCats+; staticvoid GetHowMany() coutHowManyCatsendl;int Cat:HowManyCats=0;void main() Cat a; a.GetHowMany(); Cat b(a); b.GetHowMany(); Cat c; c.GetHowMany();P154 T(2)友元实现学生成绩#include#includeclass student private: charname20; floatEnglish_score; floatComputerScience_score; floatsum_score; p

16、ublic: student(char c20,float E_score,floatCS_score) strcpy(name,c); English_score= E_score; ComputerScience_score= CS_score; floatsum() sum_score=English_score+ComputerScience_score; return sum_score; friendvoid DescendingOrder(student p1,student p2);void DescendingOrder(student p1,student p2) if(p

17、1.sum()p2.sum() coutp1.namep1.sum()endlp2.name p2.sum()endl; else coutp2.namep2.sum()endlp1.namep1.sum()endl;void main() char c120,c220; floatE_score1, CS_score1, E_score2, CS_score2; coutc1; coutPleaseenter the students English score:E_score1; coutPleaseenter the students Computer Sciencescore!CS_s

18、core1; studentm(c1,E_score1,CS_score1); coutPleaseenter another students name!c2; coutPleaseenter the students English score!E_score2; coutPleaseenter the students Computer Sciencescore!CS_score2; studentn(c2,E_score2, CS_score2); DescendingOrder(m,n);P193 T(6)指针数组比较字符串#include#includevoid sort_country(char *c,int n) int i,

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1