c++第三次作业
来源:互联网 发布:mysql frm hy000 编辑:程序博客网 时间:2024/06/05 12:39
3.#include <iostream> using namespace std; class Date { public: Date(int=1,int=1,int=2005); void display(); private: int month; int day; int year; }; Date::Date(int m,int d,int y):month(m),day(d),year(y){} void Date::display() { cout<<month<<":"<<day<<":"<<year<<endl; } int main() { Date d1(10,13,2005); Date d2(12,30); Date d3(10); Date d4; d1.display(); d2.display(); d3.display(); d4.display(); return 0; } 4. #include <iostream> using namespace std; class Student { public: Student(int n,int s):num(n),score(s){} void display(); private: int num; int score; }; void Student::display() { cout<<num<<" "<<score<<endl; } int main() { Student stud[5]={Student(1,98),Student(2,97),Student(3,96),Student(4,95),Student(5,94)}; Student *p=stud; for(i=0;i<3;p=+2,i++) p->display(); return 0; } 5. #include <iostream> using namespace std; class Student { public: Student(int n,int s):num(n),score(s){} int num; int score; }; void max(Student *a) { int i,k=0,max_score=a[0].score; for(i=1;i<5;i++) { if(a[i].score>max_score) {max_score=a[i].score;k++;} } cout<<a[k].num<<" "<<max_score<<endl; } int main() { Student stud[5]={Student(1,98),Student(2,97),Student(3,96),Student(4,95),Student(5,94)}; Student *p=stud; max(p); return 0; } 6. #include <iostream> using namespace std; class Student { public: Student(int n,float s):num(n),score(s){} void change(int n,float s) { num=n; score=s; } void display() { cout<<num<<" "<<score<<endl; } private: int num; float score; }; int main() { Student stud(101,78.5); stud.display(); stud.change(101,80.5); stud.display(); return 0; } 7.(1) #include <iostream> using namespace std; class Student { public: Student(int n,float s):num(n),score(s){} void change(int n,float s) { num=n; score=s; } //void display() void display()const { cout<<num<<" "<<score<<endl; } private: int num; float score; }; int main() { //Student stud(101,78.5); const Student stud(101,78.5); stud.display(); //stud.change(101,80.5); //stud.display(); return 0; } (2) #include <iostream> using namespace std; class Student { public: Student(int n,float s):num(n),score(s){} //void change(int n,float s) void change(int n,float s)const { num=n; score=s; } //void display() void display()const { cout<<num<<" "<<score<<endl; } private: //int num; mutable int num; //float score; mutable float score; }; int main() { //Student stud(101,78.5); const Student stud(101,78.5); stud.display(); stud.change(101,80.5); stud.display(); return 0; } (3) #include <iostream> using namespace std; class Student { public: Student(int n,float s):num(n),score(s){} void change(int n,float s) { num=n; score=s; } void display() { cout<<num<<" "<<score<<endl; } private: int num; float score; }; int main() { Student stud(101,78.5); Student *p=&stud; p->display(); p->change(101,80.5); p->display(); return 0; } (4) #include <iostream> using namespace std; class Student { public: Student(int n,float s):num(n),score(s){} //void change(int n,float s) void change(int n,float s)const { num=n; score=s; } //void display() void display()const { cout<<num<<" "<<score<<endl; } private: //int num; mutable int num; //float score; mutable float score; }; int main() { //Student stud(101,78.5); const Student stud(101,78.5); stud.display(); const Student *p = &stud; //stud.change(101,80.5); p->change(101,80.5); //stud.display(); p->display(); return 0; } (5)#include <iostream> using namespace std; class Student { public: Student(int n,float s):num(n),score(s){} //void change(int n,float s) void change(int n,float s)const { num=n; score=s; } //void display() void display()const { cout<<num<<" "<<score<<endl; } private: //int num; mutable int num; //float score; mutable float score; }; int main() { //Student stud(101,78.5); const Student stud(101,78.5); stud.display(); const Student *p = &stud; //stud.change(101,80.5); p->change(101,80.5); //stud.display(); p->display(); return 0; } (5)#include <iostream> using namespace std; class Student { public: Student(int n,float s):num(n),score(s){} //void change(int n,float s) void change(int n,float s)const { num=n; score=s; } //void display() void display() const { cout<<num<<" "<<score<<endl; } private: //int num; mutable int num; //float score; mutable float score; }; int main() { //Student stud(101,78.5); const Student stud(101,78.5); stud.display(); //const Student *p = &stud; Student * const p=&stud; //stud.change(101,80.5); //p->change(101,80.5); //stud.display(); p->display(); return 0; } 8. #include <iostream> using namespace std; class Student { public: Student(int n,float s):num(n),score(s){} void change(int n,float s) { num=n; score=s; } void display() { cout<<num<<" "<<score<<endl; } private: int num; float score; }; int main() { Student stud(101,78.5); void fun(Student &); fun(stud); return 0; } void fun(Student &stu) { stu.display(); stu.change(101,80.5); stu.display(); } 9. #include <iostream> using namespace std; class Product { public: Product(int n,int q,float p):num(n),quantity(q),price(p){} void total(); static float average(); static void display(); private: int num; int quantity; float price; static float discount; static float sum; static int n; }; void Product::total() { float rate=1.0; if(quantity>10) rate=rate*0.98; sum=sum+quantity*price*rate*(1-discount); n=n+quantity; } void Product::display() { cout<<sum<<endl; cout<<average()<<endl; } float Product::average() { return (sum/n); } float Product::discount=0.05; float Product::sum=0.0; int Product::n=0; int main() { Product prod[3]={Product(101,5,23.5),Product(102,12,24.56),Product(103,100,21.5)}; for(int i=0;i<3;i++) prod[i].total(); Product::display(); return 0; } 10. #include <iostream> using namespace std; class Date; class Time { public: Time(int ,int ,int ); friend void display(const Date &,const Time &); private: int hour; int minute; int sec; }; Time::Time(int h,int m,int s) { hour=h; minute=m; sec=s; } class Date { public: Date(int ,int ,int ); friend void display(const Date &,const Time &); private: int day; int month; int year; }; Date::Date(int d,int m,int y) { day=d; month=m; year=y; } void display(const Date &d,const Time &t) { cout<<d.day<<" "<<d.month<<" "<<d.year<<endl; cout<<t.hour<<" "<<t.minute<<" "<<t.sec<<endl; } int main() { Time t(10,13,56); Date d(10,25,2004); display(d,t); return 0; } 11.#include <iostream> using namespace std; class Time; class Date { public: Date(int ,int ,int); friend Time; private: int day; int month; int year; }; Date::Date(int d,int m,int y) { int day=d; int month=m; int year=y; } class Time { public: Time(int,int,int); void display(const Date &); private: int hour; int minute; int sec; }; Time::Time(int h,int m,int s) { hour=h; minute=m; sec=s; } void Time::display(const Date &d) { cout<<d.day<<" "<<d.month<<" "<<d.year<<endl; cout<<hour<<" "<<minute<<" "<<sec<<endl; } int main() { Time t(10,13,56); Date d(12,25,2004); t.display(d); return 0; } 12. #include <iostream> using namespace std; template<class numtype> class Compare { public: Compare(numtype a,numtype b); numtype max(); numtype min(); private: numtype x,y; }; template<class numtype> Compare<numtype>::Compare(numtype a,numtype b) { x=a; y=b; } template<class numtype> numtype Compare<numtype>::max() { return (x>y)?x:y; } template<class numtype> numtype Compare<numtype>::min() { return (x<y)?x:y; } int main() { Compare<int> cmp1(3,7); cout<<cmp1.max()<<"is the Maximum of two integer numbers."<<endl; cout<<cmp1.min()<<"is the Minimum of two integer numbers."<<endl; Compare<float> cmp2(45.78,93.6); cout<<cmp2.max()<<"is the Maximum of two integer numbers."<<endl; cout<<cmp2.min()<<"is the Minimum of two integer numbers."<<endl; Compare<char> cmp3('a','A'); cout<<cmp3.max()<<"is the Maximum of two characters."<<endl; cout<<cmp3.min()<<"is the Minimum of two characters."<<endl; }
0 0
- c语言作业第三次
- 第三次c程序作业
- 第三次C语言程序设计作业
- C语言第三次作业
- 第三次C程序语言设计作业
- c语言程序设计第三次作业 2
- 第三次C程序课堂作业
- C语言第三次课堂作业
- 第三次c程序课后作业
- C语言程序设计第三次课堂作业
- C语言第三次作业练习
- 第三次作业
- 第三次作业
- 第三次作业
- 第三次作业
- 第三次作业
- 第三次作业
- 第三次作业
- OGG "Loading data from file to Replicat"table数据的静态同步配置过程
- Oracle基础(no.2)
- live555-让你的h264文件支持seek
- viewpage嵌套listview, 效果:滑动listview删除,滑动非listview区域viewpage翻页
- 7zip 压缩文件 分析
- c++第三次作业
- c++第四次作业
- 不同的按钮提交到同一个地址,只是地址所带的参数值不一样的HTML和JS语句
- 猫猫学IOS(一)UI之Hello World与加法计算器
- 网络状态监测之 Reachability的使用
- using the easy connect naming method 简单连接测试
- leetcode--19Remove Nth Node From End of List
- php学习随记4
- AES加密解密(使用php扩展mcrypt实现AES加密)