第五章
来源:互联网 发布:苏州园区网络托管 编辑:程序博客网 时间:2024/04/30 07:52
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 get_value_1()
{get_value();
cin>>age>>addr;}
void display_1()
{
cout<<"age: "<<age<<endl;
cout<<"address: "<<addr<<endl;
}
private:
int age;
char addr[30];
};
int main()
{Student1 stud1;
stud1.get_value_1();
stud1.display();
stud1.display_1();
return 0;
}
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 get_value_1()
{get_value();
cin>>age>>addr;}
void display_1()
{display();
cout<<"age: "<<age<<endl;
cout<<"address: "<<addr<<endl;
}
private:
int age;
char addr[30];
};
int main()
{Student1 stud1;
stud1.get_value_1();
stud1.display_1();
return 0;
}
3.
#include<iostream>
using namespace std;
class Student
{public:
void get_value();
void display( );
protected :
int num;
char name[10];
char sex;
};
void Student::get_value()
{cin>>num>>name>>sex;}
void Student::display( )
{cout<<"num: "<<num<<endl;
cout<<"name: "<<name<<endl;
cout<<"sex: "<<sex<<endl;
}
class Student1: protected Student
{public:
void get_value_1();
void display1( );
private:
int age;
char addr[30];
};
void Student1::get_value_1()
{get_value();
cin>>age>>addr;
}
void Student1::display1( )
{cout<<"num: "<<num<<endl;
cout<<"name: "<<name<<endl;
cout<<"sex: "<<sex<<endl;
cout<<"age: "<<age<<endl;
cout<<"address: "<<addr<<endl;
}
int main( )
{Student1 stud1;
stud1.get_value_1();
stud1.display1( );
return 0;
}
4.
#include<iostream>
using namespace std;
class Student
{public:
void get_value();
void display( );
protected :
int num;
char name[10];
char sex;
};
void Student::get_value()
{cin>>num>>name>>sex;}
void Student::display( )
{cout<<"num: "<<num<<endl;
cout<<"name: "<<name<<endl;
cout<<"sex: "<<sex<<endl;
}
class Student1: public Student
{public:
void get_value_1();
void display1( );
private:
int age;
char addr[30];
};
void Student1::get_value_1()
{get_value();
cin>>age>>addr;
}
void Student1::display1( )
{cout<<"num: "<<num<<endl;
cout<<"name: "<<name<<endl;
cout<<"sex: "<<sex<<endl;
cout<<"age: "<<age<<endl;
cout<<"address: "<<addr<<endl;
}
int main( )
{Student1 stud1;
stud1.get_value_1();
stud1.display1( );
return 0;
}
10.
#include <cstring>
using namespace std;
class Teacher
{public:
Teacher(int,char [],char);
void display();
private:
int num;
char name[20];
char sex;
};
Teacher::Teacher(int n,char nam[],char s)
{num=n;
strcpy(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<<"birthday:"<<month<<"/"<<day<<"/"<<year<<endl;}
void BirthDate::change(int y,int m,int d)
{year=y;
month=m;
day=d;
}
class Professor:public Teacher
{public:
Professor(int,char [],char,int,int,int,float);
void display();
void change(int,int,int);
private:
float area;
BirthDate birthday;
};
Professor::Professor(int n,char nam[20],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(3012,"Zhang",'f',1949,10,1,125.4);
cout<<endl<<"original data:"<<endl;
prof1.display();
cout<<endl<<"new data:"<<endl;
prof1.change(1950,6,1);
prof1.display();
return 0;
}
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- #笔记#圣思园 JavaSE 第48讲——Map映射
- 课堂作业1
- POJ2406寻找循环节
- NSUserDefaults重置数据
- android Application Component研究之Activity(一)
- 第五章
- erlang 实现并行奇偶排序
- 启动内核,运行到Freeing init memory: 120K卡死的解决方法
- How to convert Java object to / from JSON (Gson)
- poj1961与poj2406同都是寻找循环节
- maven 打zip包
- weblogic启停脚本
- 1036. 跟奥巴马一起编程(15)
- SpringMVC-08 @InitBinder注解