a simple HW question :

here is the question :
Write a program that generates an Employee Payroll Report. The input for the program consists of a collection of data containing the last name, hourly pay rate, and the number of hours worked, for a set of employees. The output of the program is a report conforming to the sample layout found in DOC:

Your program should perform the following tasks:

Repeatedly prompt the user to determine whether or not there is data pertaining to an employee to be input. (Program should work for 0 or more employees.) If the user responds in the affirmative, the program prompts for each of the input data items for a single employee; the user responds in the negative when there is no more employee data to be processed.

For each employee you are to compute the number of overtime hours worked by that employee, the salary, and the overtime pay. An employee earns straight time for the first forty hours of work, time-and-a-half for up to the first 10 hours in excess of 40 hours, and double-time for any additional hours.

One report detail line should be generated for each employee. The report should include heading lines, column headings, and "footer" line as shown in the layout document.


this is how the output should look:
http://cisnet.baruch.cuny.edu/friedman/cplusplus/hw/payrpt.doc

How would you start this problem ?

this is gotta be something simple. I need it for a first course in c++.
I can't use arrays because I don't know the number of employees.
I tried just inputting the data into variables (int, string etc)
even though it works I can't really make it look as a payroll sheet.

Also, say when I input the name, and I am trying to show the output w/o saved data, it goes to the next line even though I want it to stay on the same line for inputting the hours and the pay.

How would you suggest me build the algorithm ?

Here is what I've done so far, haven't really paid attention at it's efficiency or documentation (gotta get used to documentation :\ ) :

#include <iostream>
#include <iomanip>
#include <string>
#include <windows.h>
using namespace std;
void input_employee ();
void heading ();
void gotoxy ( short x, short y );
char temp='N';
string name;
int hour_rate, hours,over_hours;
int main ()
{
	cout << "any workers ? Y/N:  ";
	cin>> temp;	
	heading();
	while (temp=='Y' || temp=='y')
	{
		input_employee ();
		cout << "any workers ? Y/N:  ";
	    cin>> temp;	
	}
	system("pause");
	return 0;
}
void heading()
{
	cout<< setw(50) << "EMPLOYEE PAYROLL REPORT -  SPRING 2010" <<endl;
	for (int i=0; i<75;i++)
		cout << "-";
	cout << endl;
cout << "        HOURLY             OVERTIME     OVERTIME      TOTAL" << endl;
cout << " NAME   RATE     HOURS     HOURS        SALARY        SALARY" << endl;
	for (int i=0; i<75;i++)
		cout << "-";
	cout << endl;
}
void input_employee()
{
	cin>>name;
	gotoxy(9,7);
	cin>> hour_rate;
}
void gotoxy ( short x, short y )
{
COORD coord = {x, y};
SetConsoleCursorPosition ( GetStdHandle ( STD_OUTPUT_HANDLE ), coord );
}



I think there should be a better thing, maybe using classes and objects would do it ?
I think objects and classes would do it.

The thing is that I know some programming and I want to skip the first programming class. So, I am trying to solve some problems before I take the exam on Monday.
I am a little rusty, especially with Classes/Objects and Points and am trying to get better with them

Thanks very much,
Roni.
Last edited on
You can use any of the containers in the C++ STL to store the data. I'd use a std::vector.
You can use arrays if you ask the user the number of employees and then use that value to dynamically initialize it using the new command. (This new command is covered in the PowerPoint below)
Classes is covered pretty well on the tutorial for this website:
http://cplusplus.com/doc/tutorial/classes/
http://cplusplus.com/doc/tutorial/classes2/
http://cplusplus.com/doc/tutorial/pointers/

I would not really recommend classes myself for an object that will only contain data because that is what structures are for, but you can live without structure if you just learn classes.

You could also look at this PowerPoint for pointers and the second one is for classes:
http://users.csc.tntech.edu/~sghafoor/2110/Pointers.ppt
http://users.csc.tntech.edu/~sghafoor/2110/class.ppt
Topic archived. No new replies allowed.