Pease help

W

Wahoo

Dear All,

Hello! I am new to C++

my teacher had give me a homework and I found there are problem in my code,
please give advise if possible, thanks!

question:
he ABC Human Resources Management System has a class called Employee which
provided each employee a unique 4-digits ID when an employee record was
created. The system also keeps each employee's first name, last name, hourly
salary and total working hour of the month as record. The system obtains
each
employee's monthly salary by calling Employee class's member function,
CalculateSalary(), which multiply total working hour of the month and hourly
salary then output the result.
Write the class Employee by C++


My code:
#include <iostream>
#include <stdlib.h>
#include <string>

class Employee {

public:
string first_name;
string last_name;
int hourly_salary;
int total_work_hour;

public:
class CalculateSalary() {
return hourly_salary * total_work_hour;
}

}}


~ Let us linux ~
 
S

Severin Ecker

hi!
My code:
#include <iostream>
#include <stdlib.h>
#include <string>

class Employee {

public:

i think you don't want to make the members public. OOP gives you an easy way
of data hiding, use it (-> just drop the public, so your members are
private -> not visible outside the class, or better, only visible within an
object and it's memberfunctions)
string first_name;
string last_name;

you eighter have to use one of the following 3 possibilities:
use namespace std;
using std::string;
std::string first_name;

int hourly_salary;
int total_work_hour;

public:
class CalculateSalary() {
return hourly_salary * total_work_hour;
}

this should be a member function: therefore it needs a return value. the
class keyword isn't correctly used here. try something like
int CalculateSalary() { ... }

the second '}' has to be a ';'

regards,
sev
 
W

Wahoo

Thanks!!!

Severin Ecker said:
hi!


i think you don't want to make the members public. OOP gives you an easy way
of data hiding, use it (-> just drop the public, so your members are
private -> not visible outside the class, or better, only visible within an
object and it's memberfunctions)


you eighter have to use one of the following 3 possibilities:
use namespace std;
using std::string;
std::string first_name;



this should be a member function: therefore it needs a return value. the
class keyword isn't correctly used here. try something like
int CalculateSalary() { ... }


the second '}' has to be a ';'

regards,
sev


~ Let us linux ~
 
B

Bill Seurer

Wahoo said:
int hourly_salary;
int total_work_hour;

In addition to what Severin mentions here're some more things think
about the above two fields:

Are hourly salaries always whole numbers, e.g., $5 and not $5.25?
If so, can they ever earn negative salaries?
Do employees always work exactly whole hours, e.g., 8 and not 8:07?
If so, can they ever work negative hours?
 
W

Wahoo

Dear All,

I had changed some code, but still don't work, please help to check...

Code:
#include <iostream>
#include <stdlib.h>
#include <string>

using namespace std;

class Employee {

public:
string first_name;
string last_name;
double hourly_salary;
double total_work_hour;

public:
double CalculateSalary() {
return hourly_salary * total_work_hour;
}
};

Thanks!!!!!!!!!!

Bill Seurer said:
In addition to what Severin mentions here're some more things think
about the above two fields:

Are hourly salaries always whole numbers, e.g., $5 and not $5.25?
If so, can they ever earn negative salaries?
Do employees always work exactly whole hours, e.g., 8 and not 8:07?
If so, can they ever work negative hours?


~ Let us linux ~
 
A

Alan Johnson

Wahoo said:
Dear All,

I had changed some code, but still don't work, please help to check...

Code:
#include <iostream>
#include <stdlib.h>
#include <string>

using namespace std;

class Employee {

public:
string first_name;
string last_name;
double hourly_salary;
double total_work_hour;

public:
double CalculateSalary() {
return hourly_salary * total_work_hour;
}
};

Thanks!!!!!!!!!!

What exactly doesn't work? I am able to use your class just fine (and
get the expected result). Here is the program I used to test your class:

int main()
{
Employee e;
double gross, tax;

// Minimum wage.
e.hourly_salary = 5.15;

// Long hours.
e.total_work_hour = 80;

// Calculate gross income.
gross = e.CalculateSalary();

// Calculate tax.
tax = .95 * gross;

// Display amount earned. Expected: 20.6
cout << "Earned: " << gross - tax << endl;

return 0;
}


Alan
 
S

Severin Ecker

hi!
double CalculateSalary() {
return hourly_salary * total_work_hour;
}

whats probably missing is a semicolon here, if i'm not completly wrong,..
bus as alan said: what exactly doesn't work

regards,
sev
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,460
Latest member
eibafima

Latest Threads

Top