注册 登录
编程论坛 C++教室

建立人员管理的程序,面向对象。动态数组指针和重载

洌改 发布于 2017-12-17 11:30, 1270 次点击
•    实验目的
1、    掌握运算符重载的方法。
2、    掌握拷贝构造方法。
•    学时分配:4学时
•    实验任务
1.设计一个用于人事管理的People(人员)类。考虑到通用性,这里只抽象出所有类型人员都具有的属性:number(编号)、name(姓名)、sex(性别)、birthday(出生日期)、id(身份证号)、years入职年数,averagesalary每年平均工资等等。其中“出生日期”定义为一个“日期”类内嵌子对象, averagesalary是一个动态数组的指针,该数组的元素个数的多少根据入职年数决定。用成员函数实现对人员信息的录入和显示。要求包括:构造函数和析构函数、拷贝构造函数、内联成员函数、聚集。
2、对people类重载“==”运算符和“=”运算符,“==”运算符判断两个people类对象的id属性是否相等;“=”运算符实现people类对象的赋值操作。
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
class Date
{
    public:
    int year;
    int month;
    int day;
};
class People
{
    public:
        Peolpe(int n,int y,char ID[18])
        {
            number=n;
            strcpy(id,ID);
            years=y;
            ave=new float[y];
        };
        ~People()
        {
            cout<<" "<<number<<"号人员已经录入"<<endl;
        }
        void set();
        void input()
        {
            cin>>number>>name>>sex>>birthday.year >>birthday.month >>birthday.day;
            cin>>id;
            id[18]='\0'    ;
            cin>>years;
        }
        People(People& p)//拷贝构造函数
        {
            number=p.number ;
            sex=p.sex ;
            birthday=p.birthday ;
            strcpy(id,p.id );
            
        }
        People operator=(const People& pl);
    private:
        int number;
        string name;
        string sex;
        char id[18];
        Date birthday;
        int years;
        int average;
        float *ave;
};
void People::set()
{
    cout<<"编号"<<number<<endl;
   
    cout<<"姓名"<<name<<endl;
   
    cout<<"性别"<<sex<<endl;

    cout<<"出生年月"<<birthday.year <<birthday.month <<birthday.day <<endl;
   
    cout<<"身份证号"<<id<<endl;

    cout<<"入职年数"<<years<<endl;

    cout<<"平均工资"<<average<<endl;
}
bool operator==(const People&p,const People&pl)
{
    return p.id==pl.id[18];
}
int main()
{
    People p1();
    p1.input();
    p1.set();
    return 0;
}
程序没有写完,重载比较的没有思路,求大佬指点,而且main函数里的调用也有问题
0 回复
1