第五章 作业 ╰半夏微凉° 2022-08-01 01:20 322阅读 0赞 ![Center][] 第五章 作业 1、 \#include <iostream> using namespace std; class Student\{ public: void get\_value() \{cin>>num>>name>>sex;\} void display() \{ cout<<"num:"<<num<<endl; cout<<"name:"<<name<<endl; cout<<"sex:"<<sex<<endl; \} private: int num; char name\[10\]; char sex; \}; class Student1:public Student\{ public: void getvalue() \{ get\_value(); cin>>age>>addr; \} void show() \{ display(); cout<<"age:"<<age<<endl; cout<<"address:"<<addr<<endl; \} private: int age; char addr\[10\]; \}; int main() \{ Student1 stud; stud.getvalue(); stud.show(); return 0; \} ![Center 1][] 2. \#include <iostream> using namespace std; class Student\{ public: void get\_value() \{cin>>num>>name>>sex;\} void display() \{ cout<<"num:"<<num<<endl; cout<<"name:"<<name<<endl; cout<<"sex:"<<sex<<endl; \} private: int num; char name\[10\]; char sex; \}; class Student1:private Student\{ public: void getvalue() \{ get\_value(); cin>>age>>addr; \} void show() \{ display(); cout<<"age:"<<age<<endl; cout<<"address:"<<addr<<endl; \} private: int age; char addr\[10\]; \}; int main() \{ Student1 stud; stud.getvalue(); stud.show(); return 0; \} ![Center 2][] 3.\#include <iostream> using namespace std; class Student\{ public: void get\_value() \{cin>>num>>name>>sex;\} void display() \{ cout<<"num:"<<num<<endl; cout<<"name:"<<name<<endl; cout<<"sex:"<<sex<<endl; \} protected: int num; char name\[10\]; char sex; \}; class Student1:protected Student\{ public: void getvalue() \{ get\_value(); cin>>age>>addr; \} void show() \{ cout<<"num:"<<num<<endl; cout<<"name:"<<name<<endl; cout<<"sex:"<<sex<<endl; cout<<"age:"<<age<<endl; cout<<"address:"<<addr<<endl; \} private: int age; char addr\[10\]; \}; int main() \{ Student1 stud; stud.getvalue(); stud.show(); return 0; \} ![Center 3][] 4. \#include <iostream> using namespace std; class Student\{ public: void get\_value() \{cin>>num>>name>>sex;\} void display() \{ cout<<"num:"<<num<<endl; cout<<"name:"<<name<<endl; cout<<"sex:"<<sex<<endl; \} protected: int num; char name\[10\]; char sex; \}; class Student1:public Student\{ public: void getvalue() \{ get\_value(); cin>>age>>addr; \} void show() \{ cout<<"num:"<<num<<endl; cout<<"name:"<<name<<endl; cout<<"sex:"<<sex<<endl; cout<<"age:"<<age<<endl; cout<<"address:"<<addr<<endl; \} private: int age; char addr\[10\]; \}; int main() \{ Student1 stud; stud.getvalue(); stud.show(); return 0; \} ![Center 4][] ![Center 4][] 5、 \#include <iostream> using namespace std; class Student\{ public: void get\_value() \{cin>>num>>name>>sex;\} void display() \{ cout<<"num:"<<num<<endl; cout<<"name:"<<name<<endl; cout<<"sex:"<<sex<<endl; \} protected: int num; char name\[10\]; char sex; \}; class Student1:public Student\{ public: void getvalue() \{ get\_value(); cin>>age>>addr; \} void show() \{ cout<<"num:"<<num<<endl; cout<<"name:"<<name<<endl; cout<<"sex:"<<sex<<endl; cout<<"age:"<<age<<endl; cout<<"address:"<<addr<<endl; \} private: int age; char addr\[10\]; \}; int main() \{ Student1 stud; stud.getvalue(); stud.show(); return 0; \}![Center 5][] 5. \#include <iostream> using namespace std; class A \{ public: void f1(); int i; protected: void f2(); int j; private: int k; \}; class B:public A \{ public: void f3(); protected: int m; private: int n; \}; class C:public B \{ public: void f4(); private: int p; \}; int main() \{ A a1; B b1; C c1; return 0; \} ![Center 6][] 6、 \#include <iostream> using namespace std; class A \{ public: void f1(); protected: void f2(); private: int i; \}; class B:public A \{ public: void f3(); int k; private: int m; \}; class C:protected B \{ public: void f4(); protected: int n; private: int p; \}; class D:private C \{ public: void f5(); protected: int q; private: int r; \}; int main() \{ A a1; B b1; C c1; D d1; return 0; \} ![Center 6][] 7、 \#include <iostream> using namespace std; class A \{ public: A()\{a=0;b=0;\} A(int i)\{a=i;b=0;\} A(int i,int j)\{a=i;b=j;\} void display() \{cout<<"a="<<a<<endl; cout<<"b="<<b<<endl;\} private: int a; int b; \}; class B:public A \{ public: B()\{c=0;\} B(int i):A(i)\{c=0;\} B(int i,int j):A(i,j)\{c=0;\} B(int i,int j,int k):A(i,j)\{c=k;\} void show() \{ display(); cout<<"c="<<c<<endl; \} private: int c; \}; int main() \{ B b1; B b2(1); B b3(1,2); B b4(1,2,3); b1.show(); b2.show(); b3.show(); b4.show(); return 0; \} ![Center 7][] 8、 \#include <iostream> using namespace std; class A \{ public: A()\{cout<<"constructing A "<<endl;\} ~A()\{cout<<"destructing A "<<endl;\} \}; class B:public A \{ public: B()\{cout<<"constructing B "<<endl;\} ~B()\{cout<<"destructing B "<<endl;\} \}; class C:public B\{ public: C()\{cout<<"constructing C "<<endl;\} ~C()\{cout<<"destructing C "<<endl;\} \}; int main() \{ C c1; return 0; \}![Center 8][] 9. \#include <string> \#include <iostream> using namespace std; class Teacher\{ public: Teacher(string nam,int a,char s,string ti,string ad,string t); void display(); protected: string name; int age; char sex; string title; string addr; string tel; \}; Teacher::Teacher(string nam,int a,char s,string ti,string ad,string t) \{ name=nam; age=a; sex=s; title=t; addr=ad; tel=t; \} void Teacher::display() \{ cout<<"name:"<<name<<endl; cout<<"age:"<<age<<endl; cout<<"sex:"<<sex<<endl; cout<<"title:"<<title<<endl; cout<<"addr:"<<addr<<endl; cout<<"tel:"<<tel<<endl; \} class Cadre\{ public: Cadre(string nam,int a,char s,string p,string ad,string t); void display(); protected: string name; int age; char sex; string post; string addr; string tel; \}; Cadre::Cadre(string nam,int a,char s,string p,string ad,string t):name(nam), age(a),sex(s),post(p),addr(ad),tel(t)\{\} void Cadre::display() \{ cout<<"name:"<<name<<endl; cout<<"age:"<<age<<endl; cout<<"sex:"<<sex<<endl; cout<<"post:"<<post<<endl; cout<<"addr:"<<addr<<endl; cout<<"tel:"<<tel<<endl; \} class Teacher\_Cadre:public Teacher,public Cadre \{ public: Teacher\_Cadre(string nam,int a,char s,string ti,string p,string ad,string t,float w); void show(); private: float wage; \}; Teacher\_Cadre::Teacher\_Cadre(string nam,int a,char s,string ti,string p,string ad,string t,float w): Teacher(nam,a,s,ti,ad,t),Cadre(nam,a,s,p,ad,t),wage(w)\{\} void Teacher\_Cadre::show() \{ Teacher::display(); cout<<"post:"<<Cadre::post<<endl; cout<<"wage:"<<wage<<endl; \} int main() \{ Teacher\_Cadre tc("yenianfeng",20,'m',"xuesheng","nanchang","100086","lihang",10000); tc.show(); return 0; \} ![Center][] \#include <string> \#include <iostream> using namespace std; class Teacher\{ public: Teacher(int,string,char); void display(); private: int num; string name; char sex; \}; Teacher::Teacher(int n,string nam,char s) \{ num=n; name=nam; sex=s; \} void Teacher::display() \{ cout<<"num:"<<num<<endl; cout<<"name:"<<name<<endl; cout<<"sex:"<<sex<<endl; \} class BirthDate\{ public: BirthDate(int,int,int); void display(); void change(int,int,int); private: int year; int month; int day; \}; BirthDate::BirthDate(int y,int m,int d) \{ year=y; month=m; day=d; \} void BirthDate::display() \{ cout<<"year:"<<year<<endl; cout<<"month:"<<month<<endl; cout<<"day:"<<day<<endl; \} void BirthDate::change(int y,int m,int d) \{ year=y; month=m; day=d; \} class Professor:public Teacher \{ public: Professor(int,string,char,int,int,int,float); void display(); void change(int,int,int); private: float area; BirthDate birthday; \}; Professor::Professor(int n,string nam,char s,int y,int m,int d,float a): Teacher(n,nam,s),birthday(y,m,d),area(a)\{\} void Professor::display() \{ Teacher::display(); birthday.display(); cout<<"area:"<<area<<endl; \} void Professor::change(int y,int m,int d) \{ birthday.change(y,m,d); \} int main() \{ Professor prof1(1,"yenianfeng ",'m',1995,5,28,100); prof1.display(); prof1.change(2008,3,3); prof1.display(); return 0; \} ![Center 9][] [Center]: /images/20220801/cab432ad757245658c522edc31e2955f.png [Center 1]: /images/20220801/26ff9d3047e547a89909592628f6ae95.png [Center 2]: /images/20220801/825182d1e5cc4b6ab6cf5f8ed1f6f4ad.png [Center 3]: /images/20220801/c74aa9bcd9224bf7b1a7808afaefad51.png [Center 4]: /images/20220801/404013526bc346f8b0ed3443be6a903e.png [Center 5]: /images/20220801/5132ff00371843f09fe2efc17404d186.png [Center 6]: /images/20220801/f7fe39d7408b43e4b93399fa8dffb031.png [Center 7]: /images/20220801/cfcd995876134c49a317d5cb9aa4a51c.png [Center 8]: /images/20220801/f73878039b244909a6bf8f6be8785fa0.png [Center 9]: /images/20220801/90157321c4e44a14ad920a4e8e13a457.png
相关 【web应用系统实践】第五章作业 > 仅供参考 1. 设计一个页面,用户在上面输入圆的半径,提交后显示出圆的周长和面积,要求使用例 5-1 的 JavaBean 类。 (两个页面 + 1个Java类) 谁践踏了优雅/ 2023年10月03日 19:22/ 0 赞/ 60 阅读
相关 第五周作业 <table> <thead> <tr> <th>这个课程属于哪个课程</th> <th>C语言程序设计II</th> </tr> </th 末蓝、/ 2022年01月07日 09:53/ 0 赞/ 392 阅读
相关 第五周作业 ![1581840-20190329124817262-1330362741.png][] 本题目要求编写程序统计一行字符中单词的个数。所谓“单词”是指连续不含空格的字符串 痛定思痛。/ 2022年01月06日 08:37/ 0 赞/ 382 阅读
相关 第五周作业 第四周预习题 7-1 统计一行文本的单词个数 (15 分) 本题目要求编写程序统计一行字符中单词的个数。所谓“单词”是指连续不含空格的字符串,各单词之间用空格分隔,空格数可 「爱情、让人受尽委屈。」/ 2021年12月24日 16:17/ 0 赞/ 631 阅读
相关 第五周作业 <table> <tbody> <tr> <td><span style="font-size:18pt;">这个作业属于那个课程</span></td> 悠悠/ 2021年12月16日 03:09/ 0 赞/ 453 阅读
相关 第五周作业 7-1 统计一行文本的单词个数 (15 分) 本题目要求编写程序统计一行字符中单词的个数。所谓“单词”是指连续不含空格的字符串,各单词之间用空格分隔,空格数可以是多个。 不念不忘少年蓝@/ 2021年10月23日 06:59/ 0 赞/ 500 阅读
还没有评论,来说两句吧...