收藏 分享(赏)

北邮信通C++上机实验 第七章.doc

上传人:HR专家 文档编号:11670176 上传时间:2020-11-05 格式:DOC 页数:28 大小:281.50KB
下载 相关 举报
北邮信通C++上机实验 第七章.doc_第1页
第1页 / 共28页
北邮信通C++上机实验 第七章.doc_第2页
第2页 / 共28页
北邮信通C++上机实验 第七章.doc_第3页
第3页 / 共28页
北邮信通C++上机实验 第七章.doc_第4页
第4页 / 共28页
北邮信通C++上机实验 第七章.doc_第5页
第5页 / 共28页
点击查看更多>>
资源描述

1、第七章实验题一基础题1.#include using namespace std; class CSample double a; CSample()a=2.5; public: CSample(int val); CSample(); ;2.#include using namespace std; class cubepublic: cube();/构造函数cube();/析构函数int volume(); /定义整形函数private:int height, width, depth;/定义私有数据成员; cube:cube() height = 100; depth = 4; widt

2、h = 2; coutConstructor called.endl; cube:cube() cout Destructor called. endl; system(pause); int cube:volume() return height*width*depth; void main() cube cubeone; /定义对象cout立方体的体积为:cubeone.volume()endl; system(pause);3.#include using namespace std;class CCounterint value;public:CCounter()cout CCount

3、er Constructor1 endl;value = 0; CCounter(int val)cout CCounter Constructor2 endl;value = val;CCounter() cout CCounter Destructor endl; system(pause);class CExampleint value;public:CCounter car;CExample()cout CExample Constructor1 endl;value = 0;CExample(int val)cout CExample Constructor2 endl;value

4、= val;CExample() cout CExample Destructor endl; system(pause);void Display() cout value= value endl; ;void main()CExample obj(350);obj.Display();system(pause);/调用顺序:CCounter()-CExample(int val)-CExample()-CCounter()4.#include using namespace std;class Pointprotected:int x;public:int Getx() return x;

5、 int Y;void init(int a, int b) x = a; Y = b; int Gety() return Y; void Setx(int a) x = a; void Sety(int b) Y = b; ;void main()Point A, B;A.init(25, 27);B.init(29, 31);cout A.x= A.Getx() endl;cout B.x= B.Getx() endl;cout A.Y= A.Y endl;cout A.y= A.Gety() endl;cout B.y= B.Y endl;cout B.y= B.Gety() endl

6、;system(pause);5.#include using namespace std;class baseprivate:int i;static int k; /定义静态变量k public:base() i = 0; k+; /定义构造函数void Display();void base:Display()k = k + 10;i+;cout i= i ,k= k 0)cout Its a positive number endl;positive+;else if (x = 0)zero+;cout Its zero endl;elsenegative+;cout Its a ne

7、gative number n)num test(n);test.decision();test.print();system(pause);2.#include using namespace std;class dianqipublic:void getprice(int x , int y, int z )colorcast = x;ridge = y;washer = z;void total(int a , int b , int c )int t = a*colorcast + b*ridge + c*washer;cout t endl;private:int colorcast

8、;int ridge;int washer;void main()dianqi dian;dian.getprice(4200, 2800, 1500);cout a;cout b;cout c;cout endl;cout 总营业额为:;dian.total(a, b, c);system(pause);3.#include#includeusing namespace std;class carpublic:void disp_parameters()cout 型号: type endl;cout 颜色: colour endl;cout 车门数: door endl;cout 座位数:

9、seat endl;cout 轴距: distance endl;void change(string a, char b, int c, int d, int e)type = a;colour = b;door = c;seat = d;distance = e;private:string type;char colour;int door;int seat;int distance;void main()car gundam;gundam.change(Double O GUNDAM, b, 1, 5, 6);gundam.disp_parameters();system(pause)

10、;4.#include using namespace std;class studentpublic:int num;char name20;char sex;int age;void main()student stu5;student temp;for (int i = 0; i5; i+)cout 输入第 i + 1 stui.num;cout 输入第 i + 1 stui.name;cout 输入第 i + 1 stui.sex;cout 输入第 i + 1 stui.age;for (int a = 1; a 5; a+)for (int b =0 ; b 5-a; b+)if (

11、stub.agestub + 1.age)temp.age = stub + 1.age;stub + 1.age = stub.age;stub.age = temp.age;for (int i = 0; i5; i+)cout num: stui.num name: stui.name sex: stui.sex age: stui.age endl;system(pause);5.#include using namespace std;class ATMpublic:void s_balance(void)cout The balance is balance endl;void d

12、eposit(float a)balance += a;void withdraw(float a)balance -= a;int checking(int a)if (key = a)return 1;elsereturn 0;private:int key = 328;static float balance;float ATM:balance = 0.0f;void main()ATM sys1;int k,m;float num;cout k;if (sys1.checking(k) != 1)cout Error endl;elsecout Please choose the fu

13、nction: endl (1) Depositing money endl (2) Withdrawing money endl (3) Check the balance endl (4) Return to the main interface m)switch (m)case 1:cout num;sys1.deposit(num);cout You have deposited num endl;sys1.s_balance();cout Please choose the function: endl (1) Depositing money endl (2) Withdrawin

14、g money endl (3) Check the balance endl (4) Return to the main interface endl;break;case 2:cout num;sys1.withdraw(num);cout You have withdrawed num endl;sys1.s_balance();cout Please choose the function: endl (1) Depositing money endl (2) Withdrawing money endl (3) Check the balance endl (4) Return t

15、o the main interface endl;break;case 3:sys1.s_balance();cout Please choose the function: endl (1) Depositing money endl (2) Withdrawing money endl (3) Check the balance endl (4) Return to the main interface endl;break;case 4:cout Please choose the function: endl (1) Depositing money endl (2) Withdra

16、wing money endl (3) Check the balance endl;break;default:cout Error1 endl;break;system(pause);6.#include #includeusing namespace std;class studentpublic:friend void sort(student &a, student &b, student &temp);void change(string a, int b, float c)name=a;num = b;score = c;float show()return score;priv

17、ate:int num;string name;float score;void sort(student &a, student &b,student &temp)if (a.score b.score)temp = a; a= b;b = temp;void main()student stu5;student temp;string q= ;int w = 0;float e=0.0f;for (int i = 0; i5; i+)cout 输入第 i + 1 位学生的姓名,学号,成绩:endl;cout q;cout w;cout e;stui.change(q, w, e);cout endl;for (int i = 1; i5; i+)for (int j = 0; j(5 - i); j+)sort(stuj, stuj + 1, temp);cout 最高分 stu0.show() endl;cout 最低分 stu4.show() endl;system(pause);

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 网络科技 > 其他相关文档

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报