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

开通VIP
 

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

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

开通VIP折扣优惠下载文档

            查看会员权益                  [ 下载后找不到文档?]

填表反馈(24小时):  下载求助     关注领币    退款申请

开具发票请登录PC端进行申请

   平台协调中心        【在线客服】        免费申请共赢上传

权利声明

1、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
2、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,个别因单元格分列造成显示页码不一将协商解决,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
3、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
4、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前可先查看【教您几个在下载文档中可以更好的避免被坑】。
5、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
6、文档遇到问题,请及时联系平台进行协调解决,联系【微信客服】、【QQ客服】,若有其他问题请点击或扫码反馈【服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【版权申诉】”,意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:0574-28810668;投诉电话:18658249818。

注意事项

本文(2024年C编程题库.doc)为本站上传会员【快乐****生活】主动上传,咨信网仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知咨信网(发送邮件至1219186828@qq.com、拔打电话4009-655-100或【 微信客服】、【 QQ客服】),核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载【60天内】不扣币。 服务填表

2024年C编程题库.doc

1、31.定义盒子Box类,要求具备如下组员:长、宽、高分别为x,y,z,可设置盒子形状;可计算盒子体积;可计算盒子的表面积。 #include #include using namespace std; class Box{ public: int weight; int length; int hight; void box_shape(int w, int l, int h); int box_volume(int w, int l, int h); int box_area(int w

2、 int l, int h); }; int main() { Box mybox; cout << "Please Enter weight and length and hight:"; cin >> mybox.weight >> mybox.length >> mybox.hight; int box_v, box_a; mybox.box_shape(mybox.weight, mybox.length, mybox.hight); box_v = mybox.box_volume(mybox.weight, mybox.length,

3、mybox.hight); cout << "This box's volume =" << box_v << endl; box_a = mybox.box_area(mybox.weight, mybox.length, mybox.hight); cout << "This box's area = " << box_a << endl; } void Box::box_shape(int w, int l, int h) { if(w == l && l == h) cout << "This is a Cube!" << endl; else

4、 cout << "This is a cuboid!" << endl; } int Box::box_volume(int w, int l, int h) { return w * l * h; } int Box::box_area(int w, int l, int h) { return 2 * w * l + 2 * l * h + 2 * w * h; } 32. 有两个长方柱,其长、宽、高分别为:(1)30,20,10;(2)12,10,20。分别求他们的体积。编一个基于对象的程序,在类中用带参数的结构函数。 #i

5、nclude class Box{ private: int length; int weight; int hight; public: Box(int, int, int); int volume(); }; int main() { using namespace std; Box mybox1(30, 20, 10); cout << "The first Box's volume = " << mybox1.volume() << endl; Box mybox2(12, 10, 30);

6、 cout << "The second Box's volume = " << mybox2.volume() << endl; return 0; } Box::Box(int l, int w, int h) { length = l; weight = w; hight = h; } int Box::volume() { return (hight * weight * length); } 33. 有两个长方柱,其长、宽、高分别为:(1)12,20,25;(2)10,30,20。分别求他们的体积。编一个基于对象的程序,且定义两

7、个结构函数,其中一个有参数,一个无参数。 #include class Box{ private: int length; int wight; int height; public: Box(); Box(int, int, int); int volume(); }; int main() { using namespace std; Box mybox1; cout << "The first box's volume = " << mybox1.volume() << endl; Box mybox2(10,

8、30, 20); cout << "The second box's volume = " << mybox2.volume() << endl; return 0; } Box::Box() { length = 12; wight = 20; height = 25; } Box::Box(int l, int w, int h) { length = l; wight = w; height = h; } int Box::volume() { return length * wight * height; } 34

9、. 申明一个类模板,利用它分别实现两个整数、浮点数和字符的比较,求出大数和小数。 #include using namespace std; template class Compare {public: Compare(numtype a,numtype b){x=a;y=b;} numtype max(){return (x>y)?x:y;} numtype min(){return (x

10、>cmp1(3,4); cout< cmp2(45.78,93.6); cout<

11、float numbers."< cmp3('a','A'); cout< u

12、sing namespace std; class Student { public: Student(int n,int s):num(n),score(s){} void display() {cout<

13、stud; for(int i=0;i<=2;p=p+1,i++) p->display(); return 0; } 36. 建立一个对象数组,内放5个学生的数据(学号、成绩),设置一个函数max,用指向对象的指针作函数参数,在max函数中找出5个学生中成绩最高者,并输出其学号。初值自拟。 #include using namespace std; class Student { public: Student(int n,int s):num(n),score(s){} int num; int score

14、 }; int main() { Student stud[5]={Student(01,70),Student(02,71),Student(03,72),Student(04,73),Student(05,74)}; void max(Student *); Student *p=&stud[0]; max(p); return 0; } void max(Student *arr) { float max_score=arr[0].score; for(int i=0;i<5;i++) if(max_score

15、score) {max_score=arr[i].score;} cout< class Complex{ private: double real; double image; public: Complex(); Complex(dou

16、ble, double); double get_real(); double get_image(); }; Complex operator + (Complex &, Complex &); int main() { Complex s1(3, 4); Complex s2(5, -10); Complex c3; c3 = s1 + s2; std::cout << "s1 + s2 = "; std::cout << "(" << c3.get_real() << ", " << c3.get_image() << "i)" <

17、< std::endl; // Complex s1(3, 4); // std::cout << s1.get_real() << std::endl; return 0; } Complex::Complex(double r, double i) { real = r; image = i; } Complex::Complex() { real = 0; image = 0; } double Complex::get_real() { return real; } double Complex::get

18、image() { return image; } Complex operator + (Complex & s1, Complex & s2) { Complex c(s1.get_real() + s2.get_real(), s1.get_image() + s2.get_image()); return c; } 39. 定义一个复数类Complex,重载运算符“+”,“—”,使之能用于复数的加,减运算,运算符重载函数作为Complex类的组员函数。编程序,分别求出两个复数之和,差。初值自拟。 #include clas

19、s Complex{ private: double real; double image; public: Complex(); Complex(double, double); Complex operator + (Complex &); Complex operator - (Complex &); void display(); }; int main() { Complex s1(3, 4), s2(5, 6), c; c = s1 + s2; c.display(); c = s1 - s2;

20、 c.display(); return 0; } Complex::Complex() { real = 0; image = 0; } Complex::Complex(double r, double i) { real = r; image = i; } Complex Complex::operator + (Complex & s1) { Complex c; c.real = s1.real + real; c.image = s1.image + image; return c; } Com

21、plex Complex::operator - (Complex & s1) { Complex c; c.real = real - s1.real; c.image = image - s1.image; return c; } void Complex::display() { using namespace std; cout << real << " " << image << endl; } 40. 定义一个复数类Complex,重载运算符“+”,使之能用于复数的加法运算。参加运算的两个运算量能够都是类对象,也能够其中有一个是整数,次序

22、任意。例如:c1+c2,i+c1,c1+i均合法(设i为整数,c1,c2为复数)。编程序,分别求两个复数之和、整数和复数之和。初值自拟。 #include class Complex { private: double real; double imag; public: Complex(){real=0;imag=0;} Complex(double r,double i){real=r;imag=i;} Complex operator+(Complex &c2); Complex operator+(int

23、 &i); friend Complex operator+(int&,Complex &); void display(); }; Complex Complex::operator+(Complex &c) { return Complex(real+c.real,imag+c.imag); } Complex Complex::operator+(int &i) { return Complex(real+i,imag); } void Complex::display() { using namespace std; cout<<"

24、"<>mat[i][j]; } void Matrix::display() //定义输出数据函数 {for (int i=0;i<2;i++) {for(int j=0;j<3;j++) {cout<

29、} int main() {Matrix a,b,c; a.input(); b.input(); cout<

30、rn 0; } 42. 将运算符“+”重载为适合用于复数加法,重载函数不作为组员函数,而放在类外,作为Complex类的友元函数。初值自拟。 #include class Compare { private: int real; int imag; public: Compare(); Compare(int, int); friend Compare operator+(Compare & c1, Compare & c2); void display(); }; int main() {

31、Compare c1(3, 4), c2(2, 5), c3; c3 = c1 + c2; c3.display(); return 0; } Compare::Compare() { real = 0; imag = 0; } Compare::Compare(int r, int i) { real = r; imag = i; } void Compare::display() { using namespace std; cout << real << " " << imag << "i" << endl;

32、 } Compare operator+(Compare & c1, Compare & c2) { Compare c(c1.real + c2.real, c1.imag + c2.imag); return c; } 43. 定义一个字符串类String,用来存储不定长的字符串,重载运算符“==”,,用于两个字符串的等于比较运算。初值自拟。 44. 定义一个字符串类String,用来存储不定长的字符串,重载运算符"<",用于两个字符串的小于的比较运算。初值自拟。 45. 定义一个字符串类String,用来存储不定长的字符串,重载运算符">",用于两

33、个字符串的不小于的比较运算。初值自拟。 #include #include using namespace std; class String { public: String() { p=NULL;} String(char *str); friend bool operator>(String &string1,String &string2); friend bool operator<(String &string1,String &string2); friend bool operator==(String

34、string1,String &string2); void display(); private: char *p; }; String::String(char *str) { p=str; } void String::display() { cout<(String &string1,String &string2) { if(strcmp(string1.p,string2.p)>0) return true; else return fals

35、e; } bool operator<(String &string1,String &string2) { if(strcmp(string1.p,string2.p)<0) return true; else return false; } bool operator==(String &string1,String &string2) { if(strcmp(string1.p,string2.p)==0) return true; else return fals

36、e; } void compare(String &string1,String &string2) { if(operator>(string1,string2)==1) { string1.display();cout<<">";string2.display();} else if(operator<(string1,string2)==1) { string1.display();cout<<"<";string2.display(); } else if(operator==(string1

37、string2)==1) { string1.display();cout<<"=";string2.display(); } cout<

38、string4); return 0; } 46. 定义一个描述学生基本情况的类,数据组员包括姓名、学号、C++成绩、英语和数学成绩,组员函数包括输出数据,求出总成绩和平均成绩。数据自拟。 #include class Student { private: char * name; int id; int cpp_source; int eng_source; int math_source; public: Student(char *, int, int, int, int); vo

39、id sum_source(); void avg_source(); }; int main() { Student s("John", 1, 90, 80, 97); s.sum_source(); s.avg_source(); return 0; } Student::Student(char * n, int i, int cs, int es, int ms) { name = n; id = i; cpp_source = cs; eng_source = es; math_source = ms; }

40、 void Student::sum_source() { std::cout << name << " The sum of source: " << cpp_source+eng_source+math_source << std::endl; } void Student::avg_source() { double avg; avg = (cpp_source + eng_source + math_source) / 3; std::cout << "The avg of source: " << avg << std::endl; }

41、 47. 先建立一个Point(点)类,包括数据组员x,y(坐标点)。以它为基类,派生出一个Circle(圆)类,增加数据组员r(半径),再以Circle类为直接基类,派生出一个Cylinder(圆柱体)类,在增加数据组员h(高)。编写程序,重载运算符“<<”和“>>”,使之能够用于输出以上类对象。 #include class Point { protected: int x, y; public: Point(){x = 0, y = 0;} Point(int a, int b) { this->x = a;

42、 this->y = b; } void setX(int a){x = a;} void setY(int b){y = b;} int getX(){return x;} int getY(){return y;} }; class Circle:public Point { protected: int r; public: Circle(int x, int y, int r):Point(x, y){this->r = r;} void setR(int a){r = a;} int getR(){return

43、r;} }; class Cylinder:public Circle { protected: int h; public: Cylinder():Circle(0, 0, 0),h(0){} Cylinder(int x, int y, int r, int h):Circle(x, y, r){this->h = h;} void setH(int a){h = a;} int getH(){return h;} friend std::istream & operator>>(std::istream &, Cylinder &);

44、 friend std::ostream & operator<<(std::ostream &, Cylinder &); }; std::istream & operator>>(std::istream & input, Cylinder & cc) { int _x, _y, _r, _h; std::cout << "Enter the Cylinder: " << std::endl; input >> _x >> _y >> _r >> _h; cc.setX(_x); cc.setY(_y); cc.setR(_r); cc.se

45、tH(_h); return input; } std::ostream & operator<<(std::ostream & os, Cylinder & cc) { os << cc.getX() << cc.getY() << cc.getR() << cc.getH() << std::endl; return os; } int main() { using namespace std; Cylinder cc; cin >> cc; cout << cc; return 0; } 48. 写一个程序,定义抽象

46、类型Shape,由他派生三个类:Circle(圆形),Rectangle(矩形),Trapezoid(梯形),用一个函数printArea分别输出三者的面积,3个图形的数据在定义对象是给定。 #include class Shape { public: virtual double area() const = 0; }; class Circle:public Shape { private: double r; public: Circle(double a):r(a){} virtual double ar

47、ea() const { return 3.14 * r * r; } }; class Rectangle:public Shape { private: double h, w; public: Rectangle(double a, double b):h(a),w(b){} virtual double area() const { return h * w; } }; class Trapezoid:public Shape { private: double h, w; public

48、 Trapezoid(double a, double b):h(a), w(b){} virtual double area() const { return 0.5 * h * w; } }; void printArea(const Shape & c) { std::cout << c.area() << std::endl; } int main() { Circle c(2); printArea(c); Rectangle r(2, 4); printArea(r); Trapezoid t(3

49、 5); printArea(t); return 0; } 49. 定义一个人员类Cperson,包括数据组员:姓名、编号、性别和用于输入输出的组员函数。在此基础上派生出学生类CStudent(增加成绩)和老师类Cteacher(增加教龄),并实现对学生和教师信息的输入输出。 #include class Cperson { protected: char name[10]; int id; int sex; public: virtual void getInfor() = 0; virtual v

50、oid printInfor() = 0; }; class CStudent:public Cperson { protected: int course; public: virtual void getInfor() { using namespace std; cout << "Enter the student's inforamtion" << endl; cout << "Enter the name: "; cin >> name ; cout << "Enter the id: "; cin

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服