473,383 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Pease help

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
6 1422
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
Thanks!!!

"Severin Ecker" <se****@gmx.at> ¦b¶l¥ó
news:40***********************@aconews.univie.ac.a t ¤¤¼¶¼g...
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
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
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> ¦b¶l¥ó
news:c8***********@news.rchland.ibm.com ¤¤¼¶¼g...
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
2
by: Wayfarer | last post by:
I am new to Access - classes were all in Oracle. Now I am trying to actually real world set up and run an Access database for a club I belong to. I have a couple of books on Access but unable to...
7
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
5
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
7
by: getmadhu | last post by:
@sql =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.