ok all i am at a loss here and am in need of some major help. the homework problem is this:
1. Employee Class: Write a class named Employee that has the following member variables:
· name – a string that holds the employee’s name
· idNumber – an int variable that holds the employee’s id number
· department – a string that holds the name of the department where the employee works
· position – a string that holds the employee’s job title
The class should have the following constructors:
· A constructor that accepts the following values as arguments and assigns them to the appropriate member variables: employee’s name, employee’s ID number, department, and position.
· A constructor that accepts the following values as arguments and assigns them to the appropriate member variables: employee’s name and ID number. The department and position fields should be assigned the empty string, (“ “).
· A default constructor that assigns empty strings to the name, department, and position member variables, and 0 to the idNumber member variable.
Write appropriate mutator functions that store values in these member variables and accessor functions that return the values in these member variables. Once you have written the class, write a separate program that creates three Employee objects to hold the following data:
Name
ID Number
Department
Position
Susan Meyers
47899
Accounting
Vice President
Mark Jones
39119
IT
Programmer
Joy Rogers
81774
Manufacturing
Engineer
The program should store this data in the three objects and then display the data for each employee on the screen.
2. Payroll Class: Design a Payroll class that has data members for an employee’s hourly pay rate, number of hours worked, and total pay for the week. Write a program with an array of seven Payroll objects. The program should ask the user for the number of hours each employee has worked and will then display the amount of gross pay each has earned. Include an input validation feature in which the class rejects any input value for hours greater than 60 hours.
class payroll
{
int hours;
int hourlyrate;
double grosspay;
int maxhours;
};
and
/*
christopher bruce
employee class header file
*/
#include <string>
using namespace std;
class employee
{
string firstname;
string lastname;
int idnum;
string dept;
string position;
};
the main so far is:
/*
christopher bruce
classes intro.cpp
the classes here are in the header files
this uses classes, header files and constructors
*/
#include <string>
#include <iostream>
#include <fstream>
#include "employee.h"
#include "payrollclass.h"
using namespace std;
1) On these programs, it's better to use [ code ] and [ / code ] to put your code in; it preserves indentation and makes it much more readable, like this:
1 2 3 4 5 6 7 8 9 10
#include <string>
usingnamespace std;
class payroll{
int hours;
int hourlyrate;
double grosspay;
int maxhours;
};
2) You never actually said what you want help with...please elaborate.
1. i have no idea how to appropriatly use the constructors for this,
2. i have no idea how to take the input from the information in a text file and get it into the appropriate identifiers i.e. takeing a text file that says susan meyers 47899 accounting vice president into employee 1 firstname, last name, id, department and position, and thank you for the code and /code
i've looked at those, and im scratching my head here.
the text file has 3 lines, each with the first and last name, id, department and position, and the tutorial has a generic input, im not sure how to get from thier to inputing those values into 3 lines into the appropriate values.
So, there are 4 different entries: The name, id, department, and position. You can create variables for each, say:
string name
int id
string department
string position
Read and store the info into each of these variables , (not objects, yet) using your ifstream object text.
After each 'person' is read, call a member function from the employee class that sets the object's data. Follow these steps:
read a person's data from a file and store into the variables
call a member function, say setInfo, to store this data into the employee object - employee1.setInfo(name, id, department, position)
Do this for each employee object..it looks like you have three of them
You are going to have to supply the member functions in the employee class definition and write the definitions of them as well (including the constructors which set the info to some state the moment the object is declared).
The tutorial on this site should show you how to write member function definitions..
/*
christopher bruce
classes intro.cpp
the classes here are in the header files
this uses classes, header files and constructors
*/
#include <string>
#include <iostream>
#include <fstream>
#include "employee.h"
#include "payrollclass.h"
usingnamespace std;
int hours;
double hourlyrate;
double grosspay;
void getpay (hours, hourlyrate, grosspay);
void main ()
{
ifstream text;
text.open ("text.txt");
employee employee1;
employee employee2;
employee employee3;
employee1.setInfo(firstname, lastname, idnum, dept, position);
employee2.setInfo(firstname, lastname, idnum, dept, position);
employee3.setInfo(firstname, lastname, idnum, dept, position);
}
void getpay ()
{
cout <<" how many hours did this person work?";
cin >> hours >> endl;
cout <<"how much do they get paid per hour?";
cin >> hourlyrate >> endl;
if (hourlyrate) > 60
cout <<"please reenter the hours worked, it must be less then 60"else;
grosspay = hours * hourlyrate;
cout <<" their paycheck will be " << grosspay << "minus taxes" << endl;
}
here are the errors:
3 IntelliSense: class "employee" has no member "setInfo" c:\documents and settings\allisa\my documents\visual studio 2010\projects\classes intro\classes intro\classes intro.cpp 25 12 classes intro
9 IntelliSense: class "employee" has no member "setInfo" c:\documents and settings\allisa\my documents\visual studio 2010\projects\classes intro\classes intro\classes intro.cpp 26 12 classes intro
10 IntelliSense: class "employee" has no member "setInfo" c:\documents and settings\allisa\my documents\visual studio 2010\projects\classes intro\classes intro\classes intro.cpp 27 12 classes intro
2 IntelliSense: expected a ')' c:\documents and settings\allisa\my documents\visual studio 2010\projects\classes intro\classes intro\classes intro.cpp 17 19 classes intro
14 IntelliSense: expected a ';' c:\documents and settings\allisa\my documents\visual studio 2010\projects\classes intro\classes intro\classes intro.cpp 40 2 classes intro
13 IntelliSense: expected an expression c:\documents and settings\allisa\my documents\visual studio 2010\projects\classes intro\classes intro\classes intro.cpp 38 18 classes intro
7 IntelliSense: identifier "dept" is undefined c:\documents and settings\allisa\my documents\visual studio 2010\projects\classes intro\classes intro\classes intro.cpp 25 48 classes intro
4 IntelliSense: identifier "firstname" is undefined c:\documents and settings\allisa\my documents\visual studio 2010\projects\classes intro\classes intro\classes intro.cpp 25 20 classes intro
6 IntelliSense: identifier "idnum" is undefined c:\documents and settings\allisa\my documents\visual studio 2010\projects\classes intro\classes intro\classes intro.cpp 25 41 classes intro
5 IntelliSense: identifier "lastname" is undefined c:\documents and settings\allisa\my documents\visual studio 2010\projects\classes intro\classes intro\classes intro.cpp 25 31 classes intro
8 IntelliSense: identifier "position" is undefined c:\documents and settings\allisa\my documents\visual studio 2010\projects\classes intro\classes intro\classes intro.cpp 25 54 classes intro
1 IntelliSense: incomplete type is not allowed c:\documents and settings\allisa\my documents\visual studio 2010\projects\classes intro\classes intro\classes intro.cpp 17 6 classes intro
11 IntelliSense: no operator ">>" matches these operands c:\documents and settings\allisa\my documents\visual studio 2010\projects\classes intro\classes intro\classes intro.cpp 35 15 classes intro
12 IntelliSense: no operator ">>" matches these operands c:\documents and settings\allisa\my documents\visual studio 2010\projects\classes intro\classes intro\classes intro.cpp 37 20 classes intro
You need to include the function setInfo inside of your class definition and write the definition for it. If you are storing your class definitions in separate header files, you have to include the code for the class member functions in separate .cpp files as well.
Also, your member variables should be private to the class and the member functions (setinfo) should be public since you will be calling it outside of the class in main().
P.S. It is difficult to help without seeing your code.
the code is in the post before the errors and i have no idea how to set info.....im telling you im absolutly clueless on this its a combination of having to miss class to take care of a sick family and the instructor tells us the basics and then espects something far in excess of what he teachs....kinda like teaching someone to make the simpliest chilimac then throwing him expecting him to run the kitchen in a 5 star restaurant. i will repost the code for the headers and main here though
[code]
/*
christopher bruce
employee class header file
*/
#include <string>
using namespace std;
class employee
{
string firstname;
string lastname;
int idnum;
string dept;
string position;
};
/* christopher bruce
payroll class header file
*/
#include <string>
using namespace std;
class payroll
{
int hours;
double hourlyrate;
double grosspay;
int maxhours;
};
/*
christopher bruce
classes intro.cpp
the classes here are in the header files
this uses classes, header files and constructors
*/
#include <string>
#include <iostream>
#include <fstream>
#include "employee.h"
#include "payrollclass.h"
using namespace std;
void getpay ()
{
cout <<" how many hours did this person work?";
cin >> hours >> endl;
cout <<"how much do they get paid per hour?";
cin >> hourlyrate >> endl;
if (hourlyrate) > 60
cout <<"please reenter the hours worked, it must be less then 60"
else;
grosspay = hours * hourlyrate;
cout <<" their paycheck will be " << grosspay << "minus taxes" << endl;
}