By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,305 Members | 1,588 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,305 IT Pros & Developers. It's quick & easy.

Pease help

P: n/a
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 ~
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 22 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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
Jul 22 '05 #2

P: n/a
Thanks!!!

"Severin Ecker" <se****@gmx.at> 在郵件
news:40***********************@aconews.univie.ac.a t 中撰寫...
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

~ Let us linux ~
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 22 '05 #3

P: n/a
Wahoo wrote:
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?
Jul 22 '05 #4

P: n/a
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" <se****@us.ibm.com> 在郵件
news:c8***********@news.rchland.ibm.com 中撰寫...
Wahoo wrote:
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?

~ Let us linux ~
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 22 '05 #5

P: n/a
Wahoo wrote:
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
Jul 22 '05 #6

P: n/a
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
Jul 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.