diff options
| author | austinsworld15 <[email protected]> | 2021-10-26 21:36:08 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-10-26 21:36:08 -0700 |
| commit | f3a36891cb7ee21c9cc1e601b7996a38624841a7 (patch) | |
| tree | 420c4e91a8d2e2cda6604800e67c5996cb5d177c | |
| parent | Update CST116F2021-Lab4.cpp (diff) | |
| download | cst116-lab4-austinsworld15-f3a36891cb7ee21c9cc1e601b7996a38624841a7.tar.xz cst116-lab4-austinsworld15-f3a36891cb7ee21c9cc1e601b7996a38624841a7.zip | |
Update CST116F2021-Lab4.cpp
| -rw-r--r-- | CST116F2021-Lab4/CST116F2021-Lab4.cpp | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/CST116F2021-Lab4/CST116F2021-Lab4.cpp b/CST116F2021-Lab4/CST116F2021-Lab4.cpp index 312f3c3..f8c4b7d 100644 --- a/CST116F2021-Lab4/CST116F2021-Lab4.cpp +++ b/CST116F2021-Lab4/CST116F2021-Lab4.cpp @@ -98,15 +98,146 @@ int main() 1. +#include <iostream> +#include <iomanip> +#include <stdlib.h> +using namespace::std; + +void GetInput(int& hours, int& minutes, int& seconds, char& style); +void PrintTime(int hours, int minutes, int seconds, char style); + +int main() +{ + 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; +} + +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; + } +} + 8a 9.13 pg 226-229 #1 1. +5) address of age is 0 +9) because we have inserted our own number to override age to be that number +14)I don't know +19)ok + +5) I'm not sure, but it still functions as an integer +6)ok + +3)ok +6)It probably assigned both days and age to be equal to age that the user inputted +7)ok + +5)ok + 8b 9.14 pg 229 #1 1. +#include <iostream> + +using namespace::std; + +void draw_rect(int width, int height) +{ + using std::cout; + cout << "+"; + for (int i = 0; i < width - 2; i++) + { + cout << "-"; + } + cout << "+\n"; + + for (int i = 0; i < height - 2; i++) + { + cout << "|"; + for (int j = 0; j < width - 2; j++) + { + cout << " "; + } + cout << "|\n"; + } + + cout << "+"; + for (int i = 0; i < width - 2; i++) + { + cout << "-"; + } + cout << "+\n"; +} + +int main() +{ + int width = 0; + int height = 0; + + cout << "Input the width of the rectangle: "; + cin >> width; + + cout << "Input the height of the rectangle: "; + cin >> height; + + draw_rect(width, height); + return 0; +} |