![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Programmer
Join Date: Dec 2004
Posts: 34
Rep Power: 0
![]() |
Pointer return type,.. ???
I am writing a class employ with the following private data members
fName. // An object of type char array used to hold the Employee's first name lName. // An object of type char array used to hold the Employee's last name address. // An object of type char array used to hold the Employee's address ssn. // An object of type char array used to hold the Employee's social security number hours. // An object of type double used to hold the Employee's hours worked payRate. // An object of type static double used to hold the payRate empCount/ // an object of type static int that will count the number of Employee objects created Now the problem is how do i use the following accessors to acesses the private memebers: 1. char* getFName() for the fName member 2. char * getLName() 3. char* getSsn() 4. char* getAddress() 5. double getHours() 6. void display() : The regular one i understand ,. the porblem are the ones with the pionter return type,.. The is bascially an abstract class and couple of classes would be dervied from it. Thank u,.. |
|
|
|
|
|
#2 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 754
Rep Power: 3
![]() |
char* getFName()
{
return fName; // assuming fName was a character array/char*
} |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Apr 2006
Location: Calgary, Alberta
Posts: 67
Rep Power: 3
![]() |
char* getFName()
{
return &fName // or &fName[0] if that makes more sense, same thing
}
//Then, in your main function
{
. . . .
char* TheName = getfName();
. . . .
}TheName then becomes a pointer to the first element of fName, and you can use it as an array as well, by going TheName[i] in all the standard ways. |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Dec 2004
Posts: 34
Rep Power: 0
![]() |
return &fName |
|
|
|
|
|
#5 |
|
Programmer
Join Date: Dec 2004
Posts: 34
Rep Power: 0
![]() |
is it possible to send a character array via function with out telling the size of the array like this:
//Prototype
void setfName (char First[])
//Implementation
void setfName (char First[])
{
int size = 10;
//then use it like First[size]
strcpy(fName ,First );
} |
|
|
|
|
|
#6 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 754
Rep Power: 3
![]() |
You can pass the size as another parameter, and refer to the parameter. Hardcoding it like you have is a bad idea. Have you considered using std::string?
|
|
|
|
|
|
#7 |
|
Programmer
Join Date: Dec 2004
Posts: 34
Rep Power: 0
![]() |
The question specifialy asks for the C Strings,.. I would have perfered string too,.. lol
|
|
|
|
|
|
#8 | |
|
Programmer
Join Date: Apr 2006
Location: Calgary, Alberta
Posts: 67
Rep Power: 3
![]() |
Why exactly, would you need to have the size of the array for a copy operation? That said:
int size = 0;
int i = 0;
while( CharArray[i] = '\0')
{
size++;
i++;
}And Quote:
|
|
|
|
|
|
|
#9 |
|
Programmer
Join Date: Dec 2004
Posts: 34
Rep Power: 0
![]() |
This is the Entire Question
Begin with creating the Employee class.
In a separate header file called Employee.h, construct a class named Employee.
This class will have the following data-members:
fName. // An object of type char array used to hold the Employee's first name
lName. // An object of type char array used to hold the Employee's last name
address. // An object of type char array used to hold the Employee's address
ssn. // An object of type char array used to hold the Employee's social security number
hours. // An object of type double used to hold the Employee's hours worked
payRate. // An object of type static double used to hold the payRate
empCount/ // an object of type static int that will count the number of Employee objects created
This class will have the following member functions:
A no parameter constructor that will set all char arrays to blanks and all instance numeric variables to 0.
A four parameter constructor that will accept parameters in this order
1. A parameter for the first name
2. A parameter for the last name
3. A parameter for the address
4. A parameter for the social security number
· The following Non I/O modifiers:
1. void setFName(char n[]). This will modify the fName member
2. void setLName(char n[]). This will modify the lName member
3. void setAddress(char n[]). This will modify the address member
4. void setSsn(char n[]). This will modify the ssn member
5. void setHours(double n). This will modify the hours member
· The following I/O modifier
1. void read(). This will allow user input into all the instance data-members
· The following accessors:
1. char* getFName() for the fName member
2. char * getLName()
3. char* getSsn()
4. char* getAddress()
5. double getHours()
6. void display() : This will display the contents of one Employee object on one line. In the following example, the number 35 refers to his hours, 12.00 refers to the pay rate and 420 is his salary.
123-45-6789 Brown John 31 E.5th St. 35 12.00 420.00
· The following implementor:
1. double calcSalary(). This will calculate and return a salary based on hours and payRate. Hours in excess of 40 are paid at time and a half
· The following static functions:
1. static void setPayRate(double rate). This will modify the static member
2. static double getPayRate( ). This will return the payRate
3. static double getEmpCount( ). This will return the empCount member
Then using this class as a base class, implement the following classes
1. HourlyWorker class: This class would be exactly like the base class.
2. SalaryWorker class. This class would possess a new data-member called yearlySalary that would contain the yearly salary of the worker. The worker would be paid on a bi-weekly basis in an amount equal to 1/26th of the yearly salary. All Salaried workers start with a default salary of $36,000.00.
There must be the additional functions:
a. double getYearlySalary(); // This would return the yearly salary of the worker
b. void setYearlySalary(double sal); // This would set the yearly salary of the worker
3. Executive class. This class in addition to having a yearly salary has a bonus in a variable called bonus. The bi-weekly salary will be calculated at 1/26th of the yearly salary + 1/26th of the bonus. All executives start with a default bonus of $10,000.00 and a yearly salary of $50,000.00.
There must be additional functions:
a. double getYearlySalary(); // This would return the yearly salary of the worker
b. void setYearlySalary(double sal); // This would set the yearly salary of the worker
c. double getBonus(); // This would return the bonus of the worker
d. void setBonus(double bonl); // This would set the bonus of the worker.
Please note that all functions must be able to be accessed from a base class pointer. This would of course require some changes in the base class.
Hint: The base class would become an abstract class.
Write a main function that implements a simple menu that would:
• Add an employee
• List Employees
• Quit
When adding an employee, give the User the choice of which type of Employee to add (HourlyWorker, SalaryWorker or Executive). Create the object dynamically and attach it to a list of Employee pointers.Question: With the stated Functions and datatypes is it possible to create a list? Or do i have to use somthing else like Structs,....?? |
|
|
|
|
|
#10 |
|
Expert Programmer
Join Date: Dec 2004
Posts: 794
Rep Power: 4
![]() |
Sure.
std::list<Employee*> employees; Note: If you're supposed to write your own list class, have fun! (sucks for you!)
__________________
Few people deserve to be compared to (Rush) Limbaugh, most of them were convicted at the Nuremburg trials. --WilliamSChips on Slashdot |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|