| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1081 人关注过本帖
标题:建立人员管理的程序,面向对象。动态数组指针和重载
只看楼主 加入收藏
洌改
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2017-10-10
结帖率:50%
收藏
 问题点数:0 回复次数:0 
建立人员管理的程序,面向对象。动态数组指针和重载
    实验目的
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函数里的调用也有问题
搜索更多相关主题的帖子: 重载 People number int cout 
2017-12-17 11:30
快速回复:建立人员管理的程序,面向对象。动态数组指针和重载
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014586 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved