C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 12th, 2012, 05:43 AM
Haroca Haroca is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 2 Haroca User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 36 sec
Reputation Power: 0
Help in project

The program should be menu driven allowing the accountant to choose one of the following tasks:
1. Add a new employee.
2. Generate a payroll report for all employees
3. Generate a payroll report for salaried employees
4. Generate a payroll report for commissioned employees
5. Apply a 10% raise/bonus
6. Exit
1. Add a new employee
When the user chooses 1, the program should perform the following tasks:
a. Create/open an employees’ file (call it employees.txt) in append mode.
b. Allow the user to enter the employee ID, employee name, employee type (‘s’ if salaried or ‘c’ if commission).
- If the employee is a salaried, then the monthly salary is entered.
- If the employee is commissioned then the gross sales amount is entered.
c. Write to the employees file: the employee ID, the employee name, employee type; and the monthly salary OR the gross sales depending on the type.
d. Keep looping until the user enters (-1) sentinel to the employee ID to stop entering employees and go back to the main menu.
2. Generate a payroll report for all employees
When the user chooses 2, the program should perform the following tasks:
a. Read the employees file. [The program can load the data that is read from the data file into arrays].
b. Calculate the total monthly pay for all employees and the average monthly pay. (Note: the monthly pay of a commission employee is 15%*grossSales).
GENG106 Computer Programming Fall 2012
2/3 Prepared by: Rana Malhas
c. Generate a screen report that prints for each employee, his/her ID, name, type and monthly pay. The screen report should also print the total monthly pay and the average monthly pay.



Can any one help me to write this program

Reply With Quote
  #2  
Old December 12th, 2012, 11:13 PM
ediz ediz is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 102 ediz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 35 m 33 sec
Reputation Power: 3
Code:
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>

using namespace std;

struct Employee 
{
	int ID;
	string name;
	string type;
	double salary;
};

int Menu();
double CalcAverage(double, int);
void AddEmployee();
void WriteEmployees(vector<Employee> &);
vector<Employee> ReadEmployees();
void SaleryReport();
void SaleryReport(string);
void PrintReport(vector<Employee> &, double, double);
int stringToInt(string &);
double stringToDouble(string &);

int main()
{
	int choice = 0;
	bool quit = false;

	while(!quit)
	{
		choice = Menu();

		switch (choice)
		{
		case 1:
			AddEmployee();
			break;
		case 2:
			SaleryReport();
			break;
		case 3:
			SaleryReport("s");
			break;
		case 4:
			SaleryReport("c");
			break;
		case 5:
			//You Implement here
			break;
		case 6:
			quit = true;
			break;
		default:
			cout<<"Illegal Input."<<endl;
			break;
		}
	}
}

int Menu()
{
	int choice;
	bool stop = false; 

	cout<<"1. Add a new employee."<<endl;
	cout<<"2. Generate a payroll report for all employees"<<endl;
	cout<<"3. Generate a payroll report for salaried employees"<<endl;
	cout<<"4. Generate a payroll report for commissioned employees"<<endl;
	cout<<"5. Apply a 10% raise/bonus"<<endl;
	cout<<"6. Exit"<<endl<<endl;

	cin>>choice;

	return choice;
}

double CalcAverage( double amount, int total )
{
	return  amount / total;
}

void AddEmployee()
{
	string fName, sName, eType;

	bool quit = false;

	int choice = 0;
	int eID = 0;
	double amount = 0;
	vector<Employee> employees;


	while(!quit)
	{
		cout<<"Enter Employee ID: ";
		cin>>eID;

		if(eID == -1)
		{
			quit = true;
			WriteEmployees(employees);

			continue;
		}

		cout<<"Enter Employee name (firstname surname): ";
		cin>>fName;
		cin>>sName;


		bool end = false;
		do 
		{
			cout<<"Enter the type: ";
			cin>>eType;

			if(eType != "c" && eType != "s")
				cout<<"Invalid type. Valid types are s and c."<<endl;
			else
				end = true;


		} while (!end);

		if(eType == "s")
		{
			cout<<"Enter the salary: ";
			cin>>amount;
		}
		else
		{
			cout<<"Enter the gross sales: ";
			cin>>amount;
		}

		Employee empl;
		empl.ID = eID;
		empl.name = fName+" "+sName;
		empl.type = eType;
		empl.salary = amount;

		employees.push_back(empl);

	}

}

vector<Employee> ReadEmployees()
{
	vector<Employee> empl;
	ifstream read;

	read.open("employees.txt");

	if(!read.is_open())
	{
		cout<<"Error, file not found.";
		return empl;
	}

	while(!read.eof())
	{
		Employee newEmpl;
		char line[1024];
		char fName[512];
		char sName[512];
		char type[5];
		char salary[1024];
		int id;

		read.getline(line, sizeof(line));

		//prevents from scanning empty spaces
		if(strcmp(line, string("").c_str()) != 0)
		{
			sscanf(line,"%i %s %s %s %s", &id, &fName, &sName, &type, &salary);

			newEmpl.ID = id;
			newEmpl.name = string(fName)+ " " +string(sName);
			newEmpl.type = string(type);
			newEmpl.salary = stringToDouble(string(salary));

			empl.push_back(newEmpl);
		}
	}
	
	read.close();

	return empl;
}

void WriteEmployees( vector<Employee>& employees)
{
	ofstream write;
	write.open("employees.txt", ios::app);

	for(unsigned int i = 0; i < employees.size(); i++)
	{
		write<<employees[i].ID<<" "<<employees[i].name<<" "<<employees[i].type<<" "<<employees[i].salary<<endl;
	}

	write.close();
}

void SaleryReport()
{
	vector<Employee> employees;
	double amount = 0;
	double average;

	employees = ReadEmployees();

	if(employees.empty())
	{
		cout<<"No employees."<<endl;
		return;
	}

	for (unsigned int i = 0; i < employees.size(); i++)
	{
		if(employees[i].type == "s")
			amount += employees[i].salary;
		else
			amount += (0.15 * employees[i].salary);
	}

	average = CalcAverage(amount, employees.size());

	PrintReport(employees, average, amount);

}

void SaleryReport(string employeeType)
{
	vector<Employee> employees;
	vector<Employee> employeesToReport;
	double amount = 0;
	double average;

	employees = ReadEmployees();

	if(employees.empty())
	{
		cout<<"No employees."<<endl;
		return;
	}

	for (unsigned int i = 0; i < employees.size(); i++)
	{
		if(employees[i].type == employeeType)
		{
			if(employeeType == "s")
				amount += employees[i].salary;
			else
				amount += 0.15 * employees[i].salary;

			employeesToReport.push_back(employees[i]);
		}
			
	}

	average = CalcAverage(amount, employees.size());

	PrintReport(employeesToReport, average, amount);
}

void PrintReport(vector<Employee> &employees, double average, double total)
{
	for(unsigned int i = 0; i < employees.size(); i++)
	{
		cout<<"ID: "<<employees[i].ID<<endl;
		cout<<"Name: "<<employees[i].name<<endl;
		cout<<"Type: "<<employees[i].type<<endl;
		cout<<"Salary: "<<employees[i].salary<<endl;
	}

	cout<<"The average monthly pay is: "<<average<<endl;
	cout<<"The total monthly pay is: "<<total<<endl<<endl; 
}

double stringToDouble( string &str )
{
	double ret;
	stringstream ss;
	ss << str;
	ss >> ret;

	return ret;

}

Reply With Quote
  #3  
Old December 14th, 2012, 01:44 PM
Haroca Haroca is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 2 Haroca User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 36 sec
Reputation Power: 0
Thumbs up Thanks

Thanks a lot for help me , really I appreciate that.

Reply With Quote
  #4  
Old December 14th, 2012, 01:47 PM
ediz ediz is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 102 ediz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 35 m 33 sec
Reputation Power: 3
Quote:
Originally Posted by Haroca
Thanks a lot for help me , really I appreciate that.


I didn't implement option 5. Try to implement it.

Reply With Quote
  #5  
Old December 14th, 2012, 02:49 PM
ediz ediz is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 102 ediz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 35 m 33 sec
Reputation Power: 3
I forgot a few things:

* Forgot return in main.
* Forgot remove a function declaration I don't even use.

Code:
int Menu();
double CalcAverage(double, int);
void AddEmployee();
void WriteEmployees(vector<Employee> &);
vector<Employee> ReadEmployees();
void SaleryReport();
void SaleryReport(string);
void PrintReport(vector<Employee> &, double, double);
double stringToDouble(string &);

int main()
{
	int choice = 0;
	bool quit = false;

	while(!quit)
	{
		choice = Menu();

		switch (choice)
		{
		case 1:
			AddEmployee();
			break;
		case 2:
			SaleryReport();
			break;
		case 3:
			SaleryReport("s");
			break;
		case 4:
			SaleryReport("c");
			break;
		case 5:
			//You Implement here
			break;
		case 6:
			quit = true;
			break;
		default:
			cout<<"Illegal Input."<<endl;
			break;
		}
	}

	return 0;
}


Was very tired when i worked on this one.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Help in project


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap