From f3a36891cb7ee21c9cc1e601b7996a38624841a7 Mon Sep 17 00:00:00 2001 From: austinsworld15 <91639488+austinsworld15@users.noreply.github.com> Date: Tue, 26 Oct 2021 21:36:08 -0700 Subject: Update CST116F2021-Lab4.cpp --- CST116F2021-Lab4/CST116F2021-Lab4.cpp | 131 ++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) 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 +#include +#include +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 + +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; +} -- cgit v1.2.3