Convert to use functions where possible
#include<iostream>
#include<string>
using namespace std;
int main()
{
string first, last, job;
double hours, wages, net, gross, tax, taxrate =
.40;
double oPay, oHours;
int deductions;
// input section
cout << "Enter First Name: ";
cin >> first;
cout << "Enter Last Name: ";
cin >> last;
cin.ignore();
cout << "Enter Job Title: ";
getline(cin, job);
cout << "Enter Hours Worked: ";
cin >> hours;
cout << "Enter Hourly Wage: $";
cin >> wages;
cout << "Enter Number of Deductions Claimed:
";
cin >> deductions;
if (hours > 40)
{
oHours = hours - 40;
oPay = wages * 1.5 * oHours;
gross = oPay + 40 * wages;
}
else
{
gross = hours * wages;
}
tax = gross * taxrate;
net = gross - tax;
cout << "First Name: " << first <<
endl;
cout << "Last Name: " << last <<
endl;
cout << "Job Title: " << job <<
endl;
cout << "Hours Worked: " << hours <<
endl;
cout << "Hourly Wage: " << wages <<
endl;
cout << "Deductions Claimed: " <<
deductions << endl;
if (hours > 40)
{
cout << "Overtime Hours: "
<< oHours << endl;
}
cout << "Net Pay: " << net << endl << endl;
system("pause");
return 0;
}
#include<iostream>
#include<string>
using namespace std;
//function to calculate gross
double calculateGross(double hours, double wages)
{
double oHours, oPay, gross;
if (hours > 40)
{
oHours = hours - 40;
oPay = wages * 1.5 * oHours;
gross = oPay + 40 * wages;
}
else
{
gross = hours * wages;
}
return gross;
}
//function to calulate tax
double calculateTax(double gross, double taxrate)
{
return gross * taxrate;
}
//function to calculate net pay
double calculateNetPay(double gross, double tax)
{
return gross - tax;
}
int main()
{
string first, last, job;
double hours, wages, net, gross, tax, taxrate = .40;
double oPay, oHours;
int deductions;
// input section
cout << "Enter First Name: ";
cin >> first;
cout << "Enter Last Name: ";
cin >> last;
cin.ignore();
cout << "Enter Job Title: ";
getline(cin, job);
cout << "Enter Hours Worked: ";
cin >> hours;
cout << "Enter Hourly Wage: $";
cin >> wages;
cout << "Enter Number of Deductions Claimed: ";
cin >> deductions;
//function calling
gross = calculateGross(hours, wages);
//function calling
tax = calculateTax(gross, taxrate);
//function calling
net = calculateNetPay(gross, tax);
cout << "First Name: " << first << endl;
cout << "Last Name: " << last << endl;
cout << "Job Title: " << job << endl;
cout << "Hours Worked: " << hours << endl;
cout << "Hourly Wage: " << wages << endl;
cout << "Deductions Claimed: " << deductions <<
endl;
if (hours > 40)
{
cout << "Overtime Hours: " << oHours <<
endl;
}
cout << "Net Pay: " << net << endl << endl;
system("pause");
return 0;
}
OUTPUT:
Convert to use functions where possible #include<iostream> #include<string> using namespace std; int main() { string...
employee.h ---------- #include <stdio.h> #include <iostream> #include <fstream> class Employee { private: int employeeNum; std::string name; std::string address; std::string phoneNum; double hrWage, hrWorked; public: Employee(int en, std::string n, std::string a, std::string pn, double hw, double hwo); std::string getName(); void setName(std::string n); int getENum(); std::string getAdd(); void setAdd(std::string a); std::string getPhone(); void setPhone(std::string p); double getWage(); void setWage(double w); double getHours(); void setHours(double h); double calcPay(double a, double b); static Employee read(std::ifstream& in); void write(std::ofstream& out); }; employee.cpp ---------- //employee.cpp #include...
#include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int num1, num2, result; while(ch == 'Y'){ cout << "Enter first number: "; cin >> num1; while(1){//for handling invalid inputs if(cin.fail()){ cin.clear();//reseting the buffer cin.ignore(numeric_limits<streamsize>::max(),'\n');//empty the buffer cout<<"You have entered wrong input"<<endl; cout << "Enter first number: "; cin >> num1; } if(!cin.fail()) break; } cout << "Enter second number: "; cin >> num2; while(1){ if(cin.fail()){ cin.clear(); cin.ignore(numeric_limits<streamsize>::max(),'\n'); cout<<"You have entered wrong input"<<endl; cout <<...
please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName(); double getNumberExams(); double getScoresAndCalculateTotal(double E); double calculateAverage(double n, double t); char determineLetterGrade(); void displayAverageGrade(); int main() { string StudentName; double NumberExam, Average, ScoresAndCalculateTotal; char LetterGrade; StudentName = getStudentName(); NumberExam = getNumberExams(); ScoresAndCalculateTotal= getScoresAndCalculateTotal(NumberExam); Average = calculateAverage(NumberExam, ScoresAndCalculateTotal); return 0; } string getStudentName() { string StudentName; cout << "\n\nEnter Student Name:"; getline(cin, StudentName); return StudentName; } double getNumberExams() { double NumberExam; cout << "\n\n Enter...
#include <iostream> #include <string> using namespace std; int main() { int number; int sum = 0; while(true) { cout << "Please enter a number between 1 and 11: "; cin >> number; if (number >= 1 && number <= 11) { cout << number << endl; sum = sum + number; //only add the sum when number is in range: 1-11, so add wthin this if case } else { cout << number << endl; cout << "Out of range;...
#include <iostream> #include <cstdlib> #include <time.h> #include <string> using namespace std; int main() { srand(time (0)); int number, guess, response, reply; int score = 0 number = rand() % 100 + 1; do { do { cout << "Enter your guess "; cin >> guess; score++; if (guess < number) cout << guess << " is too low! Enter a higher number. "; else if (guess > number) cout << guess << " is too high! Enter a lower number....
CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer; cout << "MENU" << endl; cout << "a - Add item to cart" << endl; cout << "d - Remove item from cart" << endl; cout << "c - Change item quantity" << endl; cout << "i - Output items' descriptions" << endl; cout << "o - Output shopping cart" << endl; cout << "q - Quit" << endl << endl; while (true) {...
Use this code to create multiple functions. #include<iostream> #include<iomanip> #include<fstream> using namespace std; int main() { cout << fixed << showpoint << setprecision(2); ofstream outFile; outFile.open("Feras's.txt"); outFile << "..Skinny Feras's Restaurant ..\n\n" << endl; int choise=10, quantity; float paid, SubTotal=0, Tax = .10, Total, RM, more; while(choise!=0) { system("cls"); cout << "\t**Welcome To Skinny Alsaif Restaurant Lol**" << endl; cout << "\nWhat would you like to have?" << endl; cout << "1. Burger." << endl; cout << "2. Pizza." <<...
FILL IN THE BLANKS #include #include <> *BLANK* using namespace std; int main() { const double HOURLY_RATE = 15; string input_str; cout << "Enter days of attendance: " << endl; *BLANK* (cin, input_str); stringstream input_stream(); int total_hours = 0; while(!input_stream.())*BLANK* { int hours; string day; input_stream >> day; if(day == *BLANK*|| day == *BLANK*) { hours = 5; } *BLANK*(day == "Tuesday" || day == "Thursday") { hours = 4; } else if(day ==...
#include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car { private: string reportingMark; int carNumber; string kind; bool loaded; string choice; string destination; public: Car() { reportingMark = ""; carNumber = 0; kind = "Others"; loaded = 0; destination = "NONE"; } ~Car() { } void setUpCar(string &reportingMark, int &carNumber, string &kind, bool &loaded, string &destination); }; void input(string &reportingMark, int &carNumber, string &kind, bool &loaded,string choice, string &destination); void output(string &reportingMark, int &carNumber,...
#include <iostream> #include <chrono> using namespace std; double improvedPow(double x, int y) { // To be implemented by you } int main() { cout << "To calculate x^y ..." << endl; double x; int y; cout << "Please enter x: "; cin >> x; cout << "Please enter y: "; cin >> y; if(x == 0) { if (y > 0) cout << 0 << endl; else cout << "x^y is not defined" <<endl; } else { cout << improvedPow(x,y)...