The Best Reliable C++ Homework Help Service in AustraliaC++ is a general-purpose programming language mainly known for its object-oriented programming features but being low-level than its other popular counterpart Java. Apart from being object-oriented, C++ also supports imperative and generic prog...
Looping in C++
#include
#include
#include
#include
using namespace std;
void dispInputScrTitle()
{
cout << "SHOW ME THE MONEY INC." << endl << endl;
}
void getEmpName(string& str)
{
cout << "Employee Full Name:\t";
getline(cin, str);
cout << endl;
}
int getHoursWorked()
{
int hours;
while (true)
{
cout << "Total hours worked:\t";
cin >> hours;
if (cin.fail() || hours < 0 || hours > 100)
{
cout << "Please enter a valid number of hours." << endl;
}
else
break;
}
return hours;
}
double getPayRate()
{
double pay_rate;
while (true)
{
cout << "Employee's regular pay rate:\t";
cin >> pay_rate;
if (cin.fail() || pay_rate < 6.5 || pay_rate > 32.00)
{
cout << "Please enter a valid pay rate." << endl;
cin.get();
}
else
break;
}
cout << endl;
return pay_rate;
}
int calcRegHrs(int hours)
{
if (hours < 40)
return hours;
else
return 40;
}
int calcThHrs(int hours)
{
if (hours > 40 && hours <= 60)
return hours - 40;
else if (hours > 60)
return hours - 60;
else
return 0;
}
int calcDblHrs(int hours)
{
if (hours > 60)
return hours - 60;
return 0;
}
double calcGrossPay(int hours, double pay_rate)
{
// get regular hours
int reg_h = calcRegHrs(hours);
// get time and a half
int th_h = calcThHrs(hours);
// get double pay hours
int dbl_h = calcDblHrs(hours);
return pay_rate * ((double)reg_h + 1.5*(double)th_h + 2 * (double)dbl_h);
}
double calcFedTaxOwed(double gross_pay)
{
return 0.06*gross_pay;
}
double calcStTaxOwed(double gross_pay)
{
return 0.03*gross_pay;
}
double calcFICAOwed(double gross_pay)
{
return 0.02*gross_pay;
}
double calcMedicareOwed(double gross_pay)
{
return 0.02*gross_pay;
}
double calcNetPay(double gross_pay)
{
double fed_tax = calcFedTaxOwed(gross_pay);
double st_tax = calcStTaxOwed(gross_pay);
double FICA_tax = calcFICAOwed(gross_pay);
double medicare_tax = calcMedicareOwed(gross_pay);
return gross_pay - fed_tax - st_tax - FICA_tax - medicare_tax;
}
void dispOutputScrTitle(string employee_name)
{
transform(employee_name.begin(), employee_name.end(), employee_name.begin(), ::toupper);
cout << "SHOW ME THE MONEY INC" << endl;
cout << "PAYROLL REPORT FOR: " << employee_name << endl;
cout << endl;
}
void dispPayRep(int hours, double pay_rate)
{
// get regular hours
int reg_h = calcRegHrs(hours);
// get time and a half
int th_h = calcThHrs(hours);
// get double pay hours
int dbl_h = calcDblHrs(hours);
double gross_pay = calcGrossPay(hours, pay_rate);
double fed_tax = calcFedTaxOwed(gross_pay);
double st_tax = calcStTaxOwed(gross_pay);
double FICA_tax = calcFICAOwed(gross_pay);
double medicare_tax = calcMedicareOwed(gross_pay);
double net_pay = calcNetPay(gross_pay);
cout << "Total hours worked" <> input;
if (input == 'Y' || input == 'N')
{
valid_option = true;
if (input == 'N')
run_program = false;
}
else
cout << "Invalid option. Please enter Y/N." << endl;
}
cin.get();
}
bool valid_option = false;
char input;
while (!valid_option)
{
cout << "Display summary report? ";
cin >> input;
if (input == 'Y' || input == 'N')
{
valid_option = true;
if (input == 'Y')
{
dispSumScrTitle();
dispSumPayRep(total_employees, total_gross_pay, total_fed_tax, total_st_tax, total_FICA_tax, total_medicare_tax, total_net_pay);
}
}
else
cout << "Invalid option. Please enter Y/N." << endl;
}
}
Understanding subroutines in programming
#include
using namespace std;
int main()
{
while (1)
{
std::cout<< "Please enter a char: " <> c;
c = tolower(c);
int cd = c - '0';
int type = -1;
if (cd >= 0 && cd <= 9) // digit
type = 1;
else if (cd == 49 || cd == 53 || cd == 57 || cd == 63 || cd == 69) // vowel
type = 2;
else if (cd >= 50 && cd <= 74) // consonant
type = 3;
else // any other character
type = 4;
switch (type)
{
case 1: // is digit
cout<< "The character is a digit." <