C++第四天

  1. 定义一个Person类,私有成员int age,string &name,定义一个Stu类,包含私有成员double *score,写出两个类的构造函数、析构函数、拷贝构造和拷贝赋值函数,完成对Person的运算符重载(算术运算符、条件运算符、逻辑运算符、自增自减运算符、插入/提取运算符)
    //主程序
    #include"stuper.h"
    int main()
    {
        cout<q2)
        {
            cout<<"q1>q2"<>p5;
        cout<<"p5:"<
    //头文件
    #ifndef STUPER_H
    #define STUPER_H
    #include 
    using namespace std;
    class Person;
    const Person operator++(Person &O,int);
    ostream &operator<<(ostream &cout, const Person &p);
    istream &operator>>(istream &cin, Person &p);
    
    class Person
    {
        friend istream &operator>>(istream &cin, Person &p);
        friend const Person operator++(Person &O,int);
        friend ostream &operator<<(ostream &cout, const Person &p);
    private:
        int age;
        int age1;
        string n="df";
        string &name=n;
    public:
        //无参构造
        Person(){cout<<"Person无参构造"<//函数体
    #include "stuper.h"
    
    
        //全局函数实现前置++运算符重载
        const Person operator++(Person &O,int)
        {
            Person temp;
            temp.age=O.age++;
            temp.age1=O.age1++;
            return temp;
        }
    
        //全局函数实现插入<<运算符重载
        ostream &operator<<(ostream &cout, const Person &p)
        {
            cout << "age = " << p.age << " age1 = " << p.age1<<"name = "<>运算符重载
        istream &operator>>(istream &cin, Person &p)
        {
            cin >> p.age >> p.age1>>p.name;
            return cin;
        }
    
    

    C++第四天_第1张图片C++第四天_第2张图片

你可能感兴趣的:(c++,算法,开发语言)