From 79777adc3b54fe060d2d6f367fde6a3d35247918 Mon Sep 17 00:00:00 2001 From: austinsworld15 <91639488+austinsworld15@users.noreply.github.com> Date: Mon, 1 Nov 2021 19:45:43 -0700 Subject: Update CST116F2021-Lab5.cpp --- CST116F2021-Lab5/CST116F2021-Lab5.cpp | 150 ++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) diff --git a/CST116F2021-Lab5/CST116F2021-Lab5.cpp b/CST116F2021-Lab5/CST116F2021-Lab5.cpp index c228068..2c18946 100644 --- a/CST116F2021-Lab5/CST116F2021-Lab5.cpp +++ b/CST116F2021-Lab5/CST116F2021-Lab5.cpp @@ -122,16 +122,166 @@ int main() 2. +Voids.h +#ifndef VOIDS_H +#define VOIDS_H +void GetInput(float& salary, int& years_service); +void CalcRaise(float& salary, int& years_service); +int CalcBonus(int years_service); +void PrintCalculations(int years_service, float salary, int bonus); +#endif + +Functions.cpp + +#include "voids.h" + +#include + +using namespace::std; + +void GetInput(float& salary, int& years_service) +{ + cout << "Enter employee's salary: "; + std::cin >> salary; + if (salary > 0) + { + cout << "enter the employee's years of service: "; + std::cin >> years_service; + } +} +void CalcRaise(float& salary, int& years_service) +{ + if (years_service > 10) + { + cout << "10% will raise\n"; + } + else if (years_service > 5) + { + cout << "5% will raise\n"; + } + else + { + cout << "2% will raise\n"; + } +} +int CalcBonus(int years_service) +{ + int calculate_bonus = 500 * (int)(years_service / 2); + return calculate_bonus; +} +void PrintCalculations(int years_service, float salary, int bonus) +{ + cout << "Your total years of service is " << years_service << endl; + cout << "Your salary is " << salary << endl; + cout << "Your total bonus is " << bonus << endl; +} + +Main.cpp + +#include "voids.h" + +int main(void) +{ + float salary = 0; + int years_service = 0; + + GetInput(salary, years_service); + CalcRaise(salary, years_service); + PrintCalculations(years_service, salary, CalcBonus(years_service)); + return 0; +} 10b 9.5 pg 216 #7 7. +Voids.h + +#ifndef VOIDS_H +#define VOIDS_H +void GetInput(int& hours, int& minutes, int& seconds, char& style); +void PrintTime(int hours, int minutes, int seconds, char style); +#endif +Functions.cpp +#include "Voids.h" +#include + +using namespace::std; + +void GetInput(int& hours, int& minutes, int& seconds, char& style) +{ + cout << "Input the hour as of right now: "; + cin >> hours; + cout << "\nInput the minutes as of right now: "; + cin >> minutes; + cout << "\nInput the seconds as of right now: "; + cin >> seconds; + cout << "\nIs the time am or pm time? ('a' for am and 'p' for pm): "; + cin >> style; +} +void PrintTime(int hours, int minutes, int seconds, char style) +{ + if (style == 'a') + { + cout << "\n\nIf you want the time in standard notation, the time is " << hours << ":" << minutes << ":" << seconds << "\n" << endl; + cout << "\nAnd if you want the time in Military time, the time is " << hours << ":" << minutes << ":" << seconds << "\n" << endl; + } + else if (style == 'p') + { + cout << "\n\nIf you want the time in standard notation, the time is " << hours << ":" << minutes << ":" << seconds << "\n" << endl; + cout << "\nAnd if you want the time in Military time, the time is " << hours + 12 << ":" << minutes << ":" << seconds << "\n" << endl; + } +} + +Main 10b 9.5 pg 216 number 7 + +#include + +#include "Voids.h" + +int main(void) +{ + using namespace::std; + + int hours = 0; + int minutes = 0; + int seconds = 0; + char style; + + GetInput(hours, minutes, seconds, style); + + if (hours > 12 || hours < 0) + { + cout << "\n\nYou cannot have more than 24 hours in a day, run the program again\n\n"; + return 0; + } + if (minutes < 0 || minutes >= 60) + { + cout << "\n\nYou cannot have more than 60 minutes in an hour, run the program again\n\n"; + return 0; + } + if (seconds < 0 || seconds >= 60) + { + cout << "\n\nYou cannot have more than 60 seconds in a minute, run the program again\n\n"; + return 0; + } + if (style == 'a' || style == 'p') + { + cout << "\n\nCalculating the time\n\n"; + } + else + { + cout << "\n\nYou did not input the specified letters, run the program and try again.\n\n"; + return 0; + } + PrintTime(hours, minutes, seconds, style); + return 0; +} -- cgit v1.2.3