Hi, I am taking a C++ course and is stuck on one the questions on my homework assignment. How do I make the output look like this:
Employee Hourly Hours Tax Gross Net
Name Rate Worked Rate Amount Amount
Also, How would the codes look like to create an output like this:
Employee Hourly Hours Tax Gross Net
Name Rate Worked Rate Amount Amount
John Smith 10.45 40.00 15.00 418.00 355.30
Jane Doe 12.50 45.00 15.00 593.75 504.69
Harry Morgan 20.00 40.00 20.00 800.00 640.00
Carmen Martinez 25.00 35.00 25.00 875.00 656.25
Jacintha Washington 50.85 60.00 35.00 3559.50 2313.68
Totals 6246.25 4469.91
The spacing is turning out bad, but basically there are columns of hoursly rate, hours worked, tax rate, gross amount, and net amount. The setprecision is 2.
Quite simple really. For each field, create a variable( in a struct for simplicity ) and assign it the value of the associated field. Then, create n amount of instances for each employee. Finally, print the contents of each employee struct in a for loop using std::cout.
Where n is amount of employees. I'll let you do the driving :)
Basically, a struct( http://www.cplusplus.com/doc/tutorial/structures/ ) holds variables( or members ) with a given type. In your case, each member's type should correspond to each field in the example lines you gave. For example, John Smith( first field ) would have a dedicated member which is of type char * or string, and, 10.45( second field ) would also have a dedicated member which is of type float or double and so on.
As for printing the information to the screen you will need to use a method called cout( http://www.cplusplus.com/reference/iostream/cout/ ). An example use of cout would be:
cout << "Sample string n" << 4.5f << "n";
The output shall be:
Sample string
4.5
Where n( backslash-n ) is an escape character for new-line. And, where 4.5f is a floating-point numerical value.
Edit: --------8<-----------------------
It appears that the new-line escape character no longer works.