1、2.24.一元硬币换成1,2,5分硬币#include iomanipusing namespace std;int main() int a, b, c, S, i = 0, sum = 100, o = 1, t = 2, f = 5; for (a = 0; a = (sum / o); a+) for (b = 0; b = (sum / t); b+) for (c = 0; c = (sum / f); c+) S = a*o + b*t + c*f; if (S = sum) cout sum = setw(3) * o + setw(2) t f endl; i+; 结果分析及
2、心得体会 cout 1元兑换成1、2、5分总共有 i a b;由小到大输出: (ab) ? (cout n m) : m fstream in(file1.txt, ios:in); if (!in) cout = a&ch z ch = ch - 32; out.put(ch); else out.put(ch); /cout struct student string X, M; int score10;int main()in.txtError open file1;out.txtError open file2; student stu4; for (int i = 0; i stui
3、.X stui.M; out stui.X for (int j = 0; j stui.scorej; out sum += stui.scorej; /while(in.eof() break; avg = sum / 10.0; avg 实验结果:欧阳 浩辰 4 5 6 4 6 4 6 5 5 9 5.4上官 北 4 5 6 5 6 2 6 5 9 6 5.4季 微然 4 2 5 6 6 5 5 6 4 2 4.5李 维 5 8 5 4 5 8 6 4 6 5 5.6成绩评定教师签名: 年 月 日二、类与对象设计、友元函数与运算符重载要求1. 理解和对象的概念,掌握声明类和定义对象的方法
4、;2. 掌握构造函数和析构函数的实现方法;3. 掌握对象数组、对象指针和string类的使用方法;4. 掌握静态数据成员和静态成员函数的使用方法;5. 理解友元的概念和掌握友元的使用方法。教材P134第3.32、3.33、3.34题教材P134第3.35、3.36题3、选做题:参考第3.32题,建立类球体类Sphere和正方体类Cube,要求能够计算球体、正方体的体积。3.32圆柱体积class cylinderprivate: double r; double h;public: cylinder(double i,double j) r=i; h=j; double vol() doubl
5、e V; const double PI=3.14; V=PI*r*r*h; return V; cylinder A(1.1,2.2); cout圆柱体积:A.vol();8.358683.33显示qu*priceclass book int qu,price; book(int i) qu=i; price=10*qu; int show() return price*qu; book A5=1,2,3,4,5; for(int i=0;i5;i+) coutAi.show()10 40 90 160 2503.34显示qu*price(对象数组) book *pa; pa=A+4; co
6、utshow() pa-;250 160 90 40 103.35.显示Stock的值class Stock char stockcode10; int quan; double price; Stock(char na,int q=1000,double p=8.98); void print();Stock:Stock(char na,int q,double p) /类外定义,不带默认参数值 for(int i=0; stockcodei=nai; /while(stockcodei=0) break; quan=q; price=p;void Stock:print() if(stoc
7、kcodei= coutstockcodei;quanpriceendl; Stock sto1(600001,3000,5.67); sto1.print(); Stock sto2( sto2.print();600001 3000 5.67600001 1000 8.983.36学生成绩class Student string name; string stu_no; float score; static int count; static float sum; static float avg; Student(string str1,string stu_no1,float sco
8、re1); void show(); void show_count_avg();Student:Student(string str1,string stu_no1,float score1) name=str1; stu_no=stu_no1; score=score1; count+; sum+=score1; avg=sum/count;void Student:show()n姓名:name;n学号:stu_no;n成绩:score;show_count_avg()n总人数:count;n平均分:avg;n*int Student:count=0;float Student:sum=0
9、.0;avg=0.0; Student stu1(里美,20140001,90); stu1.show(); stu1.show_count_avg(); Student stu2(欧浩20140002,80); stu2.show(); stu2.show_count_avg(); Student stu3(网飞20140003,75); stu3.show(); stu3.show_count_avg();姓名:里美学号:20140001成绩:90总人数:1平均分:*欧浩2014000280285网飞2014000375总人数:3成绩:81.6667提高题:求球和正方体体积const do
10、uble PI = 3.14;class Sphere Sphere(double r) radius = r; V_Sphere = 4.0 / 3 * PI*radius*radius*radius; void vol()Spheres volume is: V_Sphere double radius, V_Sphere;class Cube Cube(double r) V_Cube = radius*radius*radius;Cube V_Cube area() oi;isosceles 50 124.22学生老师信息class person person(); string nu
11、m;class student :public person int class_num; student(); void print_stu(); ;class teacher : string job; string section; teacher(); void print_teh();person:person() string num1; string name1;输入编号: num1;输入姓名: name1; num = num1; name = name1;void person:编号: num 姓名: name student:student() int class_num1
12、; float score1;输入班号: class_num1;输入成绩: score1; class_num = class_num1; score = score1;void student:print_stu()*学生信息:* print();班号: class_num score teacher:teacher() string job1; string section1;输入职称: job1;输入部门: section1; job = job1; section = section1;void teacher:print_teh()*老师信息:职称: job 部门: section student stu; stu.print_stu(); teacher teh; teh.print_teh();偶偶0196*0001大大
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1