谁帮忙写段完整C++程序,不要太空

来源:百度知道 编辑:UC知道 时间:2024/05/23 17:50:33
1 自定义一个类 要有类的继承
2 动态定义该类的对象
3 动态删除该类对象
4 函数的重载/运算苻重载
5 定义友元
6 定义类的继承与组合
7 定义虚函数

//间单的给你写了个框架,不过你要的功能都有了,你可以打它完善

#include <iostream>
#include <string>
using namespace std;

class person
{
public :
person(string name = "", string id = ""):m_name(name), m_id(id){}
virtual string get() const {return m_name;}//虚函数
~person(){}
protected :
string m_name;//姓名
string m_id;//身份证号
};

class student:public person//类的继承
{
friend istream & operator >> (istream &in, student &stu);//友元运算符重载
public :
student(string name = "", string id = "", string num = ""):person(name, id), m_num(num){}
string get() const {return m_num;}
private :
string m_num;//学号
};
istream & operator >> (istream &in, student &stu)
{
cout << "input student infomation:" << endl;
cout << "name:";
in >> stu.m_name;
cout <<