佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

搜索
查看: 1204|回复: 7

该怎样做的啊?

[复制链接]
发表于 15-5-2009 05:07 PM | 显示全部楼层 |阅读模式
题目为
a) Construct a class definition that can be used to represent an employee of a company.
Each employee is defined by an integer id number, a floating-point pay rate, and the
maximum number of hours the employee should work each week. The services
provided by the class should be the ability to enter data for a new employee, the
ability to change data for a new employee, and the ability to display the existing data
for a new employee.
b) Write the main() that asks the user to enter data for three employees and displays
the entered data.

#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include EMPLOYEE_H
class Employee{
        private:
                int idNo;
                float pay;
                float maxHours;
        public:
                Employee(int, float, float);
                void setEmplotee(int, float, float);
                void display(void);
        };
        #endif
        
Employee::Employee(int id, float payout, float maxH){
        idNo = id;
        pay = payout;
        maxHours = maxH;
}

void Time::setEmployee(int id, float payout, float maxH){
        idNo = id;
        pay = payout;
        maxHours = maxH;
}
void Employee::display(){
cout<<idNo<<","<<pay<<","<<maxHours<<endl;
}

int main()
{

Employee x,y,z(1,2,3);
cout<<"Please enter employee data"<<endl;
cout<<"Please enter ID"<<endl;
cin>> idNo;
cout<<"Please enter pay rate"<<endl;
cin>> pay;
cout<<"Please enter maximum number of working hours for each week"<<endl;
cin>> maxHours;
x.display();
cout<<endl;
return 0;
}

[ 本帖最后由 ahmen9 于 15-5-2009 05:12 PM 编辑 ]
回复

使用道具 举报


ADVERTISEMENT

发表于 15-5-2009 05:31 PM | 显示全部楼层
You can't. You couldn't get the desired output from what's in your code.
If you notice, the code you wrote never update/insert the employee details to the correct instance of employee after you input them.

    cout<<"Please enter employee data"<<endl;
    cout<<"Please enter ID"<<endl;
    cin>> idNo;          <=== to which employee are you trying to input?

You created 3 instances of object Employee, which are x, y and z. So you have to specify which one are you giving the inputs. I m not familiar with C++, but in Java, you will have to do something like

    id = 005 (Not a proper one, I just hard-coding it here)
    x.idNo = id

From the question you ask, I can actually see that you are not so familiar with the concept of OOP. You really need to do a little bit more of study into this topic. This is just the basic of OOP, and if you can't master it, it will be very tough for you in your future studies in C++.

Employee x,y,z(1,2,3) <===== What does this means?

Sorry but I never did OOP in C++, or more precisely, I never really used C++ before. So I can't check your syntax errors.

[ 本帖最后由 td00164306 于 15-5-2009 05:32 PM 编辑 ]
回复

使用道具 举报

 楼主| 发表于 16-5-2009 06:09 PM | 显示全部楼层
LOL...华语..
其实我现在并不是C++学生,
我也很久没用C++了...
所以很多东西我都忘了...
谢谢你=)
回复

使用道具 举报

发表于 16-5-2009 06:50 PM | 显示全部楼层
void Time::setEmployee(int id, float payout, float maxH){

time 从哪来的?
回复

使用道具 举报

 楼主| 发表于 18-5-2009 04:51 PM | 显示全部楼层
那一part是我朋友做的也...
不太清楚...
time 应该是给maximum hours of working time.
回复

使用道具 举报

发表于 18-5-2009 07:26 PM | 显示全部楼层

回复 5# ahmen9 的帖子

在回去看清楚。 那个time。 你的 error。 真么会出现个 time class, 而你却没有define time class
回复

使用道具 举报

Follow Us
 楼主| 发表于 20-5-2009 11:37 AM | 显示全部楼层
所以我应该要这样?

   public:
                Employee(int, float, float);
                void setEmplotee(int, float, float);
                void time(int);
                void display(void);
回复

使用道具 举报

 楼主| 发表于 20-5-2009 11:39 AM | 显示全部楼层
我现在没读C++了。。所以很多东西我都忘了。
可以直接告诉我该怎样type一个完整的么?
回复

使用道具 举报


ADVERTISEMENT

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2026 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 28-4-2026 04:15 AM , Processed in 0.070701 second(s), 12 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表