Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // assign_problem6.cpp : main project file.
- #include "stdafx.h"
- #include <iostream>
- #include <conio.h>
- #include <string>
- using namespace System;
- using namespace std;
- //Prototypes
- //Sets up the screen for entering data
- void setScreenData(void);
- //Sets up the screen for displaying payments
- void setScreenPay(void);
- //Calculates worker's payments
- void calcWorkerPay(double payRate, int hours, double & basicPay, double & overtimePay, double & grossPay,
- double & hourlyRate, double & timeAndAHalf, double & doubleTime, double totals[]);
- int main(array<System::String ^> ^args)
- {
- //Declare variables
- string name;
- int hours;
- double payRate = 5.8, basicPay = 0, overtimePay = 0, grossPay = 0, hourlyRate = 0, timeAndAHalf = 0,
- doubleTime = 0, totals[3] = {0};
- char again;
- //Allow to user to enter employee details as many times as they want
- do
- {
- //Set up the screen
- setScreenData();
- //Get the employee's name
- Console::SetCursorPosition(41, 4);
- getline(cin, name);
- //Get the employee's worked hours
- Console::SetCursorPosition(41, 5);
- cin >> hours;
- //Remove the last character (\n) from istream to avoid errors with getline
- cin.ignore();
- //Calculate the employee's pay
- calcWorkerPay(payRate, hours, basicPay, overtimePay, grossPay, hourlyRate, timeAndAHalf,
- doubleTime, totals);
- //Output the results
- Console::SetCursorPosition(41, 10); cout << basicPay;
- Console::SetCursorPosition(41, 12); cout << overtimePay;
- Console::SetCursorPosition(41, 14); cout << grossPay;
- //Ask the user if they would like to move on to the next employee
- Console::SetCursorPosition(20, 24);
- cout << "Next employee? (Y)es / (N)o [_]";
- //Get the user's reply
- Console::SetCursorPosition(49, 24);
- again = getche();
- //Convert again to lowercase
- again = tolower(again);
- //Show an error message and get another character from the user if they
- //enter an invalid option
- while(again != 'n' && again != 'y')
- {
- //Show the error message
- Console::SetCursorPosition(60, 24);
- cout << "Invalid option!";
- //Remove the character the user entered
- Console::SetCursorPosition(49, 24);
- cout << " ]";
- //Get another character from the user
- Console::SetCursorPosition(49, 24);
- again = getche();
- //Convert again to lowercase
- again = tolower(again);
- //Remove the error message
- Console::SetCursorPosition(60, 24);
- cout << " ";
- }
- }while(again != 'n');
- //Set up the screen
- setScreenPay();
- //Output the totals
- Console::SetCursorPosition(41, 6); cout << totals[0];
- Console::SetCursorPosition(41, 8); cout << totals[1];
- Console::SetCursorPosition(41, 10); cout << totals[2];
- //Wait for a key press before exiting
- getch();
- }
- void setScreenData(void)
- {
- //Clear the screen
- Console::Clear();
- //Display layout
- Console::SetCursorPosition(30, 2); cout << "Worker Payments";
- Console::SetCursorPosition(10, 4); cout << "Name:";
- Console::SetCursorPosition(10, 5); cout << "Hours worked:";
- Console::SetCursorPosition(10, 10); cout << "Basic pay:";
- Console::SetCursorPosition(10, 12); cout << "Overtime pay:";
- Console::SetCursorPosition(10, 14); cout << "Gross pay:";
- Console::SetCursorPosition(40, 4); cout << "[ ]";
- Console::SetCursorPosition(40, 5); cout << "[ ]";
- Console::SetCursorPosition(40, 10); cout << "[ ]";
- Console::SetCursorPosition(40, 12); cout << "[ ]";
- Console::SetCursorPosition(40, 14); cout << "[ ]";
- }
- void setScreenPay(void)
- {
- //Clear the screen
- Console::Clear();
- //Display layout
- Console::SetCursorPosition(30, 2); cout << "Total payments";
- Console::SetCursorPosition(10, 4); cout << "Rate of pay:";
- Console::SetCursorPosition(40, 4); cout << "Total:";
- Console::SetCursorPosition(10, 6); cout << "Hourly rate";
- Console::SetCursorPosition(10, 8); cout << "Time and a half";
- Console::SetCursorPosition(10, 10); cout << "Double time";
- Console::SetCursorPosition(40, 6); cout << "[ ]";
- Console::SetCursorPosition(40, 8); cout << "[ ]";
- Console::SetCursorPosition(40, 10); cout << "[ ]";
- Console::SetCursorPosition(30, 24);
- cout << "Press any key to exit...";
- }
- void calcWorkerPay(double payRate, int hours, double & basicPay, double & overtimePay, double & grossPay,
- double & hourlyRate, double & timeAndAHalf, double & doubleTime, double totals[])
- {
- //Calculate the amount of pay for each category of pay rates
- if(hours > 60)
- {
- //Normal pay
- hourlyRate = 35 * payRate;
- //Time and a half
- timeAndAHalf = 25 * (payRate * 1.5);
- //Double time
- doubleTime = (hours - 60) * (payRate * 2);
- }
- else
- {
- if(hours > 35)
- {
- //Normal pay
- hourlyRate = 35 * payRate;
- //Time and a half
- timeAndAHalf = (hours - 35) * (payRate * 1.5);
- }
- else
- //Normal pay
- hourlyRate = hours * payRate;
- }
- //Calcuate basic pay
- basicPay = hourlyRate;
- //Calculate overtime pay
- overtimePay = timeAndAHalf + doubleTime;
- //Calculate gross pay
- grossPay = basicPay + overtimePay;
- //Add worker payments to totals
- totals[0] += hourlyRate;
- totals[1] += timeAndAHalf;
- totals[2] += doubleTime;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement