diff options
| author | James Lawrance <[email protected]> | 2021-10-22 12:07:19 -0700 |
|---|---|---|
| committer | James Lawrance <[email protected]> | 2021-10-22 12:07:19 -0700 |
| commit | 12a4fdd113e1d10c1389e3e54aeed2575c97c4be (patch) | |
| tree | 6f8d034a2712083dcbb37a3cad553d4579de01ba | |
| parent | Add online IDE url (diff) | |
| download | cst116-lab4-jemersonlawrance-12a4fdd113e1d10c1389e3e54aeed2575c97c4be.tar.xz cst116-lab4-jemersonlawrance-12a4fdd113e1d10c1389e3e54aeed2575c97c4be.zip | |
Text file up to 7c
| -rw-r--r-- | CST116F2021-Lab4/CST116F2021-Lab4.cpp | 289 | ||||
| -rw-r--r-- | Output-Debug.txt | 15 | ||||
| -rw-r--r-- | TextFile1.txt | 144 |
3 files changed, 436 insertions, 12 deletions
diff --git a/CST116F2021-Lab4/CST116F2021-Lab4.cpp b/CST116F2021-Lab4/CST116F2021-Lab4.cpp index ff0073d..d1e26c2 100644 --- a/CST116F2021-Lab4/CST116F2021-Lab4.cpp +++ b/CST116F2021-Lab4/CST116F2021-Lab4.cpp @@ -1,20 +1,285 @@ -// CST116F2021-Lab4.cpp : This file contains the 'main' function. Program execution begins and ends there. +#include <iostream> +using namespace std; + +//7a +//9.3 Learn by Doing Exercises + +//float avgFunction(float first, float second, float third); + +//int main() +//{ +// float one = 0; float two = 0; float three = 0; float average = 0; +// cout << "This program will find the average of 3 user values\n"; +// +// average = avgFunction(one, two, three); +// cout << "\nThe average is: " << average; // +// return 0; +//} -#include <iostream> +//float avgFunction(float first, float second, float third) +//{ +// cout << "Enter the first number: "; +// cin >> first; +// cout << "Enter the second number: "; +// cin >> second; +// cout << "Enter the third number: "; +// cin >> third; +// +// return ((first + second + third) / 3); +//} + +//7b +//9.4 Learn by Doing Exercises + +//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); + +//int main() +//{ + //defining variables +// float sal = 0; int years = 0; + + //running functions +// GetInput(sal, years); +// CalcRaise(sal, years); +// int bonus = CalcBonus(years); +// PrintCalculations(years, sal, bonus); + +// return 0; + +//} + +//void GetInput(float& salary, int& years_service) +//{ +// cout << "Enter the employee's salary\n"; +// cin >> salary; +// cout << "Enter the employee's years of service\n"; +// cin >> years_service; +//} + +//void CalcRaise(float& salary, int years_service) +//{ +// if (years_service > 10) +// { +// salary *= 1.10; +// } +// else if (years_service < 10 && years_service > 5) +// { +// salary *= 1.05; +// } +// else +// { +// salary *= 1.02; +// } +//} + +//int CalcBonus(int years_service) +//{ +// int bonusCounter = (years_service / 2); +// return (bonusCounter * 500); +//} + +//void PrintCalculations(int years_service, float salary, int bonus) +//{ +// cout << endl << "The employee's new salary will be " << salary << ", and they will receive a bonus of " << bonus; +//} + +//7c +//9.5 Learn by Doing Exercises + +void getTime(int &hours, int &minutes, int &seconds); +void displayTime(int hours, int minutes, int seconds, int style); int main() { - std::cout << "Hello World!\n"; + //defining local variables + int hrs = 0; int mins = 0; int secs = 0; char styleChoice = 0; int style = 0; + //get time + getTime(hrs, mins, secs); + //style + cout << endl << "Press 'd' for default, press 'm' for style menu." << endl; + cin >> styleChoice; + + do + { + if (styleChoice == 'm') + { + cout << "Press 1 for 24 hour notation, 2 for military time, or 3 for standard format." << endl; + cin >> style; + cout << endl; + if (style > 3 || style < 1) + { + cout << "Error: number other than 1, 2, or 3 entered." << endl; + } + } + else if (styleChoice == 'd') + { + cout << endl; + style = 3; + } + } while (style > 3 || style < 1); + //time display function + displayTime(hrs, mins, secs, style); + //exit + return 0; } -// Run program: Ctrl + F5 or Debug > Start Without Debugging menu -// Debug program: F5 or Debug > Start Debugging menu +void getTime(int& hours, int& minutes, int& seconds) +{ + do + { + cout << "Input the current hours (0-23)\n"; + cin >> hours; + cout << endl; + if (hours < 0 || hours > 23) + { + cout << "Error: value outside of the range 0-23 entered." << endl; + } + } while (hours < 0 || hours > 23); + + do + { + cout << "Input the current minutes (0-59)\n"; + cin >> minutes; + cout << endl; + if (minutes < 0 || minutes > 59) + { + cout << "Error: value outside of the range 0-59 entered." << endl; + } + } while (minutes < 0 || minutes > 59); + + do + { + cout << "Input the current seconds (0-59)\n"; + cin >> seconds; + cout << endl; + if (seconds < 0 || seconds > 59) + { + cout << "Error: value outside of the range 0-59 entered." << endl; + } + } while (seconds < 0 || seconds > 59); +} + +void displayTime(int hours, int minutes, int seconds, int displayStyle) +{ + cout << "The current time: "; + + if (displayStyle == 1) + { + if (hours < 10) + { + cout << "0" << hours << ":"; + } + else + { + cout << hours << ":"; + } + + if (minutes < 10) + { + cout << "0" << minutes << ":"; + } + else + { + cout << minutes << ":"; + } + + if (seconds < 10) + { + cout << "0" << seconds; + } + else + { + cout << seconds; + } + + cout << " in 24 hour notation" << endl; + } + + else if (displayStyle == 2) + { + if (hours < 10) + { + cout << "0" << hours; + } + else + { + cout << hours; + } + + if (minutes < 10) + { + cout << "0" << minutes; + } + else + { + cout << minutes; + } + + if (seconds < 10) + { + cout << "0" << seconds; + } + else + { + cout << seconds; + } + + cout << " in military time" << endl; + } + + else if (displayStyle == 3) + { + char AmPm = 'N'; + + if (hours > 12) + { + hours -= 12; + cout << hours << ":"; + + AmPm = 'P'; + } + else if (hours == 12) + { + cout << hours << ":"; + + AmPm = 'P'; + } + else + { + cout << hours << ":"; + + AmPm = 'A'; + } + + if (minutes < 10) + { + cout << "0" << minutes << ":"; + } + else + { + cout << minutes << ":"; + } + + if (seconds < 10) + { + cout << "0" << seconds; + } + else + { + cout << seconds; + } -// Tips for Getting Started: -// 1. Use the Solution Explorer window to add/manage files -// 2. Use the Team Explorer window to connect to source control -// 3. Use the Output window to see build output and other messages -// 4. Use the Error List window to view errors -// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project -// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file + if (AmPm == 'A') + { + cout << "AM in standard format" << endl; + } + else if (AmPm == 'P') + { + cout << "PM in standard format" << endl; + } + } +}
\ No newline at end of file diff --git a/Output-Debug.txt b/Output-Debug.txt new file mode 100644 index 0000000..ba1b38c --- /dev/null +++ b/Output-Debug.txt @@ -0,0 +1,15 @@ +'CST116F2021-Lab4.exe' (Win32): Loaded 'C:\Users\there\source\repos\cst116-lab4-JEmersonLawrance\x64\Debug\CST116F2021-Lab4.exe'. Symbols loaded. +'CST116F2021-Lab4.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. +'CST116F2021-Lab4.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. +'CST116F2021-Lab4.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. +'CST116F2021-Lab4.exe' (Win32): Loaded 'C:\Windows\System32\msvcp140d.dll'. +'CST116F2021-Lab4.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140_1d.dll'. +'CST116F2021-Lab4.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140d.dll'. +'CST116F2021-Lab4.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbased.dll'. +The thread 0x4f1c has exited with code 0 (0x0). +'CST116F2021-Lab4.exe' (Win32): Loaded 'C:\Windows\System32\kernel.appcore.dll'. +'CST116F2021-Lab4.exe' (Win32): Loaded 'C:\Windows\System32\msvcrt.dll'. +'CST116F2021-Lab4.exe' (Win32): Loaded 'C:\Windows\System32\rpcrt4.dll'. +The thread 0x5288 has exited with code 0 (0x0). +The thread 0x94 has exited with code 0 (0x0). +The program '[17124] CST116F2021-Lab4.exe' has exited with code 0 (0x0). diff --git a/TextFile1.txt b/TextFile1.txt new file mode 100644 index 0000000..819b3f2 --- /dev/null +++ b/TextFile1.txt @@ -0,0 +1,144 @@ +James Lawrance Lab 4 Work + Output +---------------------------------- + +7a - +6.8 Exercises 1-9 - + +1. 3 +2. -nan(ind) +3. 32 +4. .25 +5. 6 +6. 6 +7. 5 +8. 5 +9. 4 + +9.3 Learn by Doing Exercises output - + +This program will find the average of 3 user values +Enter the first number: 76.8 +Enter the second number: 55.3 +Enter the third number: 100 + +The average is: 77.3667 + +7b - +9.4 Learn by Doing Exercises output - + +Enter the employee's salary +10000 +Enter the employee's years of service +9 + +The employee's new salary will be 10500, and they will receive a bonus of 2000 + +7c - +9.5 Learn by Doing Exercises output - + +output 1 - + +Input the current hours (0-23) +12 + +Input the current minutes (0-59) +0 + +Input the current seconds (0-59) +0 + + +Press 'd' for default, press 'm' for style menu. +d + +The current time: 12:00:00PM in standard format + +output 2 - + +Input the current hours (0-23) +18 + +Input the current minutes (0-59) +50 + +Input the current seconds (0-59) +2 + + +Press 'd' for default, press 'm' for style menu. +d + +The current time: 6:50:02PM in standard format + +output 3 - + +Input the current hours (0-23) +9 + +Input the current minutes (0-59) +30 + +Input the current seconds (0-59) +00 + + +Press 'd' for default, press 'm' for style menu. +m +Press 1 for 24 hour notation, 2 for military time, or 3 for standard format. +1 + +The current time: 09:30:00 in 24 hour notation + +output 4 - + +Input the current hours (0-23) +23 + +Input the current minutes (0-59) +59 + +Input the current seconds (0-59) +59 + + +Press 'd' for default, press 'm' for style menu. +m +Press 1 for 24 hour notation, 2 for military time, or 3 for standard format. +2 + +The current time: 235959 in military time + +output 5 - + +Input the current hours (0-23) +25 + +Error: value outside of the range 0-23 entered. +Input the current hours (0-23) +21 + +Input the current minutes (0-59) +-15 + +Error: value outside of the range 0-59 entered. +Input the current minutes (0-59) +15 + +Input the current seconds (0-59) +60000000 + +Error: value outside of the range 0-59 entered. +Input the current seconds (0-59) +60 + +Error: value outside of the range 0-59 entered. +Input the current seconds (0-59) +20 + + +Press 'd' for default, press 'm' for style menu. +m +Press 1 for 24 hour notation, 2 for military time, or 3 for standard format. +3 + +The current time: 9:15:20PM in standard format |