diff options
| author | LTB-Pravda <[email protected]> | 2021-11-02 14:20:01 -0700 |
|---|---|---|
| committer | LTB-Pravda <[email protected]> | 2021-11-02 14:20:01 -0700 |
| commit | 5db56d1977ab0aeeb4337e21261a21e5db4a9ad4 (patch) | |
| tree | 9c88477d01b9c31d2f6cffe676774b456b806f4f | |
| parent | Add online IDE url (diff) | |
| download | cst116-lab4-ltb-pravda-5db56d1977ab0aeeb4337e21261a21e5db4a9ad4.tar.xz cst116-lab4-ltb-pravda-5db56d1977ab0aeeb4337e21261a21e5db4a9ad4.zip | |
Updating GitHub with current work
| -rw-r--r-- | CST116F2021-Lab4/CST116F2021-Lab4.cpp | 411 | ||||
| -rw-r--r-- | CST116F2021-Lab4/CST116F2021-Lab4.vcxproj | 1 |
2 files changed, 400 insertions, 12 deletions
diff --git a/CST116F2021-Lab4/CST116F2021-Lab4.cpp b/CST116F2021-Lab4/CST116F2021-Lab4.cpp index ff0073d..50c8e11 100644 --- a/CST116F2021-Lab4/CST116F2021-Lab4.cpp +++ b/CST116F2021-Lab4/CST116F2021-Lab4.cpp @@ -1,20 +1,407 @@ -// CST116F2021-Lab4.cpp : This file contains the 'main' function. Program execution begins and ends there. -// +// File: CST116-Lab_4-Billingsley +// Summary: A compilation of all coding exercises in lab 4 +// Author: Logan Billingsley +// Date: 10/20/2021 +/* +#include <iostream> +#include <iomanip> +using namespace std; + +void set_time(int&, int&, int&, int&, int&); // Get Variables +void dis_time(int, int, int, int, int); // Display Varibles + +int main() +{ + // 9.7 Page 217 -- I spent way to long on this, and it's badly over engineered, but I'm proud. + // Set Variables + int hrs; // Hours + int mnt; // Minutes + int sec; // Seconds + int apm; // AM or PM + int mlt; // Military or Standard + int loop;// Does the loop + + // Functions + set_time(hrs, mnt, sec, apm, mlt); + dis_time(hrs, mnt, sec, apm, mlt); + + // Loop Functions + do + { + cout << "\t\tMenu:\n\n" + << "1. Select New Time\n" + << "2. Change Display\n" + << "3. Quit\n\n" + << "Please input menu option: "; + cin >> loop; + cout << "\n\n"; + switch (loop) + { + case 1: + set_time(hrs, mnt, sec, apm, mlt); + dis_time(hrs, mnt, sec, apm, mlt); + break; + case 2: + dis_time(hrs, mnt, sec, apm, mlt); + break; + default: + cout << "Exiting Program\n\n"; + loop = 0; + break; + } + } while (loop != 0); + return 0; +} +void set_time(int& hrs, int& mnt, int& sec, int& apm, int& mlt) // 9.7 Page 217 -- Time for a lot of "do.. while" and "if.. else" statements! +{ + int c1 = 0, // Variables used to keep track of checks 1-5 + c2 = 0, + c3 = 0, + c4 = 0, + c5 = 0; + cout << "\t\tSet the time in either Military or Standard Time:\n\n"; + do // Loop until hrs is validated + { + cout << "Please input the current hour: "; // Get Hours + cin >> hrs; + if (hrs >= 0 && hrs < 24) // Make sure hrs is in a valid range for either Military or Standard Time + { + c1 = 1; // Mark that check 1 passed + do + { + cout << "Please input the current minute: "; // Get Minute + cin >> mnt; + if (mnt >= 0 && mnt < 60) // Make sure mnt is in a valid range + { + c2 = 1; + do + { + cout << "Please input the current second: "; // Get Second + cin >> sec; + if (sec >= 0 && sec < 60) // Make sure mnt is in a valid range + { + c3 = 1; + do + { + if (hrs == 0 || hrs > 12) // Check to see if time has to be in the form of Military Time + { + cout << "Automatically set to Military Time\n"; + mlt = 1; + } + else // If not, ask which format + { + cout << "Please input if time is Standard (0) or Military/24H-Standard (1) Time: "; + cin >> mlt; + } + if (mlt == 0 || mlt == 1) + { + c4 = 1; + do + { + if (mlt == 1) // If Military Time + { + if (hrs / 12 == 1) + apm = 1; + else + apm = 0; + } + else // If Standard Time + { + cout << "Please input if time is AM (0) or PM (1): "; + cin >> apm; + } + if (apm == 0 || apm == 1) + c5 = 1; + } while (c5 == 0); // Check 5 + } + else + cout << "Invalid format\n\n"; + } while (c4 == 0); // Check 4 + } + else + cout << "Invalid second\n\n"; + } while (c3 == 0); // Check 3 + } + else + cout << "Invalid minute\n\n"; + } while (c2 == 0); // Check 2 + } + else + cout << "Invalid hour\n\n"; + } while (c1 == 0); // Check 1 + cout << "Thank you for inputting the time.\n\n"; + return; +} +void dis_time(int hrs, int mnt, int sec, int apm, int mlt) // 9.7 Page 216 -- Time to display the time! +{ + int dis; + int thr = hrs; // Used to convert Military to Standard time and back + int c1 = 0; // Used for check 1 + do + { + cout << "Do you want to display the time in Standard (0), Military (1), or 24H-Standard (2) Time: "; + cin >> dis; + switch (dis) + { + case 0: + c1 = 1; + if (mlt == 0) // If both Input and Display are Standard Time + { + cout << "The time is: " << hrs << ':' << setfill('0') << setw(2) << mnt << ':' << setfill('0') << setw(2) << sec << ' '; + if (apm == 0) + cout << "AM"; + else + cout << "PM"; + } + else // If Input is't Standard Time but Display is + { + thr %= 12; + if (thr == 0) + thr = 12; + cout << "The time is: " << thr << ':' << setfill('0') << setw(2) << mnt << ':' << setfill('0') << setw(2) << sec << ' '; + if (apm == 0) + cout << "AM"; + else + cout << "PM"; + } + break; + case 1: + c1 = 1; + if (mlt == 1) // If input is 24 Hour Standard and Display is Military + cout << "The time is: " << setfill('0') << setw(2) << hrs << setfill('0') << setw(2) << mnt << setfill('0') << setw(2) << sec; + else // If Input is Standard Time and Display is Military + { + if (apm == 0) // If Input is AM + cout << "The time is: " << setfill('0') << setw(2) << thr << setfill('0') << setw(2) << mnt << setfill('0') << setw(2) << sec; + else // If Input is PM + { + thr += 12; // Shift time to night + if (thr == 24) // Roll over midnight to 0 + thr = 0; + cout << "The time is: " << setfill('0') << setw(2) << thr << setfill('0') << setw(2) << mnt << setfill('0') << setw(2) << sec; + } + } + break; + case 2: + c1 = 1; + if (mlt == 1) // If both Input and Display are 24 Hour Standard + cout << "The time is: " << hrs << ':' << setfill('0') << setw(2) << mnt << ':' << setfill('0') << setw(2) << sec; + else // If Input is Standard Time and Display is 24 Hour Standard + { + if (apm == 0) // If Input is AM + cout << "The time is: " << thr << ':' << setfill('0') << setw(2) << mnt << ':' << setfill('0') << setw(2) << sec; + else // If Input is PM + { + thr += 12; // Shift time to night + if (thr == 24) // Roll over midnight to 0 + thr = 0; + cout << "The time is: " << thr << ':' << setfill('0') << setw(2) << mnt << ':' << setfill('0') << setw(2) << sec; + } + } + break; + default: + c1 = 0; // If input is not valid + cout << "Invalid Display Type.\n\n"; + break; + } + cout << "\n\n"; + } while (c1 == 0); // Check 1 +} +*/ +/******************************************************************** +* File: Chapter 9 Debug.cpp +* +* General Instructions: Complete each step before proceeding to the +* next. +* +* Debugging Exercise 1 +* +* 1) Insert a breakpoint on the lines indicated in the code. +* 2) Run to Breakpoint 1. +* 3) Place a watch on age and days. +* 4) Add another watch using &age for the name. This will display +* the address of age. +* 5) Write down the address of age. +* 6) Step Into the code for the function GetAge. +* 7) The execution continues to the function header for GetAge. +* 8) Step into one more time. +* 9) Why did the address of age and value change? - Becuase it's moved into a function without using pass by reference. +* 10) Step over the cout and cin statements. +* 11) Verify the value entered is stored properly in age. +* 12) Step into until the flow returns to main. +* 13) Step over one more time. +* 14) Why didn't the value entered get transferred back to main? - Becuase it's not passed the value by reference, or called by "age = GetAge();" the value doesn't pass on. +* 15) Stop debugging and fix the error. +* 16) Run to Breakpoint 1. +* 17) Step over the function call to GetAge. +* 18) Verify that the value entered was returned and stored +* correctly from GetAge. +* 19) Stop debugging. +* +* Debugging Exercise 2 +* +* 1) Run to Breakpoint 1. +* 2) Step over the call to GetAge. +* 3) Step into CalcDays. +* 4) Step into one more time so that the current line is the +* calculation. +* 5) Why is age greyed out in your watch window? - Becauase CalcDays doesn't have access to age. +* 6) Stop debugging. +* +* Debugging Exercise 3 +* +* 1) Run to Breakpoint 2. +* 2) When asked, enter the value of 20 for your age. +* 3) Verify that the variable age is 20 and the variable days +* is 7300. +* 4) Step into the PrintResults function. +* 5) Age is 7300? Not even Ralph is that old. +* 6) Why did the values for both variables change? - Becuase the function had it reversed from the call. The function needed to be "(int age, int days)" instead of "(int days, int age)" +* 7) Stop debugging and fix the error. +* +* Debugging Exercise 4 +* +* 1) Run to Breakpoint 2. +* 2) Display your Call Stack window. +* 3) View the contents of the window and notice that the top +* function on the stack is main. +* 4) Step into the PrintResults function. +* 5) Notice that the call stack now shows PrintResults on top of +* the stack. +********************************************************************/ +/* #include <iostream> +using std::cout; +using std::cin; +using std::endl; + +const int DAYS_PER_YEAR = 365; + +int GetAge(); +int CalcDays(int age); +void PrintResults(int age, int days); int main() { - std::cout << "Hello World!\n"; + int age = 0; + int days = 0; + + // Breakpoint 1 + // Put breakpoint on the following line + age = GetAge(); + days = CalcDays(age); + + // Breakpoint 2 + // Put breakpoint on the following line + PrintResults(age, days); + + return 0; } +int GetAge() +{ + int age; + + cout << "Please enter your age: "; + cin >> age; + + return age; +} +int CalcDays(int years) +{ + int days; + + days = years * DAYS_PER_YEAR; + + return days; +} +void PrintResults(int age, int days) +{ + cout << age << "! Boy are you old!\n"; + cout << "Did you know that you are at least " << days << " days old?\n\n"; +} +*//* +#include <iostream> +using namespace std; + +int main() +{ + char UL = 218, // Upper-Left + LL = 192, // Lower-Left + UR = 191, // Upper-Right + LR = 217, // Lower-Right + TB = 196, // Top and Bottom + SD = 179; // Left and Right + + int width = 0, + length = 0; + do + { + cout << "Please input the width of the rectangle in characters: "; + cin >> width; -// Run program: Ctrl + F5 or Debug > Start Without Debugging menu -// Debug program: F5 or Debug > Start Debugging menu + if (width < 2) + { + cout << "\nWidth cannot be less than 2 characters."; + width = 0; + } + else if (width > 50) + { + cout << "\nWidth cannot be greater than 50 characters."; + width = 0; + } + cout << endl << endl; + } while (width == 0); + width *= 2; + width--; + do + { + cout << "Please input the length of the rectangle in characters: "; + cin >> length; -// 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 (length < 2) + { + cout << "\nLength cannot be less than 2 characters."; + length = 0; + } + else if (length > 50) + { + cout << "\nLength cannont be greater than 50 characters."; + length = 0; + } + cout << endl << endl; + } while (length == 0); + + for (int y = length; y > 0; y--) + { + if (y == length) //Top Line + { + cout << UL; + for (int x = width - 2; x > 0; x--) + { + cout << TB; + } + cout << UR; + } + else if (y == 1) + { + cout << LL; + for (int x = width - 2; x > 0; x--) + { + cout << TB; + } + cout << LR; + } + else + { + cout << SD; + for (int x = width - 2; x > 0; x--) + { + cout << ' '; + } + cout << SD; + } + cout << endl; + } + return 0; +}*/
\ No newline at end of file diff --git a/CST116F2021-Lab4/CST116F2021-Lab4.vcxproj b/CST116F2021-Lab4/CST116F2021-Lab4.vcxproj index 8b8d493..fdcd22e 100644 --- a/CST116F2021-Lab4/CST116F2021-Lab4.vcxproj +++ b/CST116F2021-Lab4/CST116F2021-Lab4.vcxproj @@ -24,6 +24,7 @@ <ProjectGuid>{77997f04-8dfb-49a5-9984-28279194cb71}</ProjectGuid> <RootNamespace>CST116F2021Lab4</RootNamespace> <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> + <ProjectName>CST116-Lab_4-Billingsley</ProjectName> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> |