diff options
| author | Jordan HarrisToovy <[email protected]> | 2021-10-24 21:18:01 -0700 |
|---|---|---|
| committer | Jordan HarrisToovy <[email protected]> | 2021-10-24 21:18:01 -0700 |
| commit | 7ca10ff3f2123a5a56b92ff3667c70257dbe0218 (patch) | |
| tree | 55db02c97b61f738a35ec03a4810e4f00d2cd32a /CST116F2021-Lab4 | |
| parent | Add online IDE url (diff) | |
| download | cst116-lab4-jordanht-oit-master.tar.xz cst116-lab4-jordanht-oit-master.zip | |
Diffstat (limited to 'CST116F2021-Lab4')
| -rw-r--r-- | CST116F2021-Lab4/CST116 Lab4 Console Output Harris-Toovy.txt | 194 | ||||
| -rw-r--r-- | CST116F2021-Lab4/CST116 Lab4 Textual Work Harris-Toovy.txt | 35 | ||||
| -rw-r--r-- | CST116F2021-Lab4/CST116F2021-Lab4.cpp | 381 |
3 files changed, 598 insertions, 12 deletions
diff --git a/CST116F2021-Lab4/CST116 Lab4 Console Output Harris-Toovy.txt b/CST116F2021-Lab4/CST116 Lab4 Console Output Harris-Toovy.txt new file mode 100644 index 0000000..58d7034 --- /dev/null +++ b/CST116F2021-Lab4/CST116 Lab4 Console Output Harris-Toovy.txt @@ -0,0 +1,194 @@ +This file contains the console output for the various program runs. + +7a - 9.3 Learn By Doing Exercise #1: + +Enter value 1: 22.22 + +Enter value 2: 33.33 + +Enter value 3: 55.55 + +The average of the three values is: 37.0333 + +C:\Users\jorda\Source\Repos\cst116-lab4-JordanHT-OIT\Debug\CST116F2021-Lab4.exe (process 6596) exited with code 0. +To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. +Press any key to close this window . . . + + + +7b - 9.4 Learn By Doing Exercise #1: + +---[RUN 1]--- + +Enter the employee's salary: 25 + +Enter the employee's years of service: 15 + +For the employee's 15 years of service: +Their salary will be changed to 27.50 USD per hour +And they will receive a bonus of 4000 USD + +C:\Users\jorda\Source\Repos\cst116-lab4-JordanHT-OIT\Debug\CST116F2021-Lab4.exe (process 840) exited with code 0. +To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. +Press any key to close this window . . . + + +---[RUN 2]--- + +Enter the employee's salary: 17.50 + +Enter the employee's years of service: 7 + +For the employee's 7 years of service: +Their salary will be changed to 18.38 USD per hour +And they will receive a bonus of 2000 USD + +C:\Users\jorda\Source\Repos\cst116-lab4-JordanHT-OIT\Debug\CST116F2021-Lab4.exe (process 7788) exited with code 0. +To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. +Press any key to close this window . . . + + +---[RUN 3]--- + +Enter the employee's salary: 13.75 + +Enter the employee's years of service: 2 + +For the employee's 2 years of service: +Their salary will be changed to 14.02 USD per hour +And they will receive a bonus of 500 USD + +C:\Users\jorda\Source\Repos\cst116-lab4-JordanHT-OIT\Debug\CST116F2021-Lab4.exe (process 6540) exited with code 0. +To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. +Press any key to close this window . . . + + + +7c - 9.5 Learn By Doing Exercise #1: + +---[RUN 1]--- + +Please enter the current time: +Hours: 13 +Minutes: 42 +Seconds: 59 + +Please chose the time format to display: +1) - 24 Hour time +2) - Military time +3) - 12 Hour time (standard) +1 + +The time is 13:42:59 + +C:\Users\jorda\Source\Repos\cst116-lab4-JordanHT-OIT\Debug\CST116F2021-Lab4.exe (process 4876) exited with code 0. +To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. +Press any key to close this window . . . + +---[RUN 2]--- + +Please enter the current time: +Hours: 19 +Minutes: 73 +Seconds: 21 + +Invalid time +Please enter the current time: +Hours: 19 +Minutes: 37 +Seconds: 43 + +Please chose the time format to display: +1) - 24 Hour time +2) - Military time +3) - 12 Hour time (standard) +2 + +The time is 1937 + +C:\Users\jorda\Source\Repos\cst116-lab4-JordanHT-OIT\Debug\CST116F2021-Lab4.exe (process 12432) exited with code 0. +To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. +Press any key to close this window . . . + +---[RUN 3]--- + +Please enter the current time: +Hours: 17 +Minutes: 51 +Seconds: 39 + +Please chose the time format to display: +1) - 24 Hour time +2) - Military time +3) - 12 Hour time (standard) +5 +Invalid mode +Please chose the time format to display: +1) - 24 Hour time +2) - Military time +3) - 12 Hour time (standard) +3 + +The time is 5:51:39 PM + +C:\Users\jorda\Source\Repos\cst116-lab4-JordanHT-OIT\Debug\CST116F2021-Lab4.exe (process 3708) exited with code 0. +To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. +Press any key to close this window . . . + + + +8a - 9.13 Debugging Exercise #1: +NOTE: Since the base code is provided, and the modifications are minimal and documented in the Textual Work file, only one run should be nessary to prove the functionality of this simplpe code. + +Please enter your age: 24 +24! Boy are you old! +Did you know that you are at least 8760 days old? + + +C:\Users\jorda\Source\Repos\cst116-lab4-JordanHT-OIT\Debug\CST116F2021-Lab4.exe (process 13316) exited with code 0. +To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. +Press any key to close this window . . . + + + +8b - 9.14 Programming Exercise #1: +NOTE: Due to the tall aspect ratio of text, the rectangles appear taller then one might expect. The program is accurate in the number of characters tall/wide the output is. + +---[RUN 1]--- + +Enter width and height of the rectangle: +1 +1 + +Size too small +Enter width and height of the rectangle: +3 +3 + +┌─┐ +│ │ +│ │ +└─┘ + +C:\Users\jorda\Source\Repos\cst116-lab4-JordanHT-OIT\Debug\CST116F2021-Lab4.exe (process 4064) exited with code 0. +To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. +Press any key to close this window . . . + + +---[RUN 2]--- + +Enter width and height of the rectangle: +11 +6 + +┌─────────┐ +│ │ +│ │ +│ │ +│ │ +│ │ +└─────────┘ + +C:\Users\jorda\Source\Repos\cst116-lab4-JordanHT-OIT\Debug\CST116F2021-Lab4.exe (process 6872) exited with code 0. +To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. +Press any key to close this window . . . diff --git a/CST116F2021-Lab4/CST116 Lab4 Textual Work Harris-Toovy.txt b/CST116F2021-Lab4/CST116 Lab4 Textual Work Harris-Toovy.txt new file mode 100644 index 0000000..4ff5fb6 --- /dev/null +++ b/CST116F2021-Lab4/CST116 Lab4 Textual Work Harris-Toovy.txt @@ -0,0 +1,35 @@ +This file contains all non-code, non-code output work + +7a - 6.8 Exercises #1-9: +1) a = 3 (type float) +2) a = -nan(ind) (not-a-number) +3) a = 32 (type float) +4) a = 0.25 (type float) +5) a = 6 (type int) +6) a = 6 (type int) +7) a = 5 (type int) +8) a = 5 (type int) +9) a = 4 (type float) + + + +8a - 9.13 Debugging Exercises: + +Ex1) +D5: The address of age is 0x0133f96c +D9: The address changed because in this scope, "age" is a local variable, and not the variable we were referring to before. While I don't know the exact reason for this, the value of age (uninitialized to a set value) is -858993460, which is the pattern 11001100... in binary - which I assume is a pattern preloaded into memory by the debugger since it is always that value. +D11: Entered 24, and it is now in [age] +D14: Since the values were local, and the values is not (currently) passed back, the value of [age] in main is still 0 +D15: Changed GetAge(); to age = GetAge(); +D16: Verified intended behavior + +Ex2) +D5: Both the value of [age] and its address are greyed out. I would assume this is because it is not currently in scope (the variable we are currently working on is called [years]). + +Ex3) +D3: Yes, [age] is 20, and [days] is 7300 +D6: Probably because the values were fed in in the wrong order. This is likely due to a mismatch in the input naming of the function and its prototype. +D7: Swapped the inputs of the function definition + +Ex4) +D5: It seems that there is a separate entry on the call stack for the PrintResults function. This implies to me that the behavior of a function call within the primary .cpp file (integrated header) is the same as an external .cpp file with an associated header. diff --git a/CST116F2021-Lab4/CST116F2021-Lab4.cpp b/CST116F2021-Lab4/CST116F2021-Lab4.cpp index ff0073d..18af959 100644 --- a/CST116F2021-Lab4/CST116F2021-Lab4.cpp +++ b/CST116F2021-Lab4/CST116F2021-Lab4.cpp @@ -1,20 +1,377 @@ -// CST116F2021-Lab4.cpp : This file contains the 'main' function. Program execution begins and ends there. -// +//Code by Jordan Harris-Toovy for CST116-01P Lab 4, October 2021 #include <iostream> +#include <iomanip> +using namespace std; + +//7a - 9.3LBD#1 + +/* +float GetAvg(void); + +int main(void) +{ + float userAverage = 0.0F; + + userAverage = GetAvg(); + + cout << "The average of the three values is: " << userAverage << endl; + + return (0); +} + +float GetAvg(void) +{ + float userVal1, userVal2, userVal3, averageVal = 0.0F; + + cout << "Enter value 1: "; + cin >> userVal1; + cout << endl; + + cout << "Enter value 2: "; + cin >> userVal2; + cout << endl; + + cout << "Enter value 3: "; + cin >> userVal3; + cout << endl; + + averageVal = (userVal1 + userVal2 + userVal3) / 3.0F; + + return averageVal; +} +*/ + +//7b - 9.4LBD#1 + +/* +void GetInput(float&, int&); +void CalcRaise(float&, int&); +int CalcBonus(int); +void PrintCalculations(int, float, int); + int main() { - std::cout << "Hello World!\n"; + float sal = 0.0F; + int year_served = 0, bonus = 0; + + GetInput(sal, year_served); + + CalcRaise(sal, year_served); + + bonus = CalcBonus(year_served); + + PrintCalculations(year_served, sal, bonus); + + return (0); } -// Run program: Ctrl + F5 or Debug > Start Without Debugging menu -// Debug program: F5 or Debug > Start Debugging menu -// 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 +void GetInput(float& salary, int& years_service) +{ + std::cout << "Enter the employee's salary: "; + std::cin >> salary; + std::cout << "\nEnter the employee's years of service: "; + std::cin >> years_service; +} + +void CalcRaise(float& salary, int& years_service) +{ + if (years_service > 10) + { + salary *= 1.1; + } + else if (years_service > 5) + { + salary *= 1.05; + } + else + { + salary *= 1.02; + } +} + +int CalcBonus(int years_service) +{ + int bonus = 0; + bonus = (years_service / 2) * 500; + bonus += (years_service % 2) * 500; + return bonus; +} + +void PrintCalculations(int years_service, float salary, int bonus) +{ + cout << endl << "For the employee's " << years_service << " years of service: " << endl; + cout.setf(ios::fixed); + cout << setprecision(2) << "Their salary will be changed to " << salary << " USD per hour" << endl + << "And they will receive a bonus of " << bonus << " USD" << endl; +} +*/ + +//7c - 9.5LBD#1 + +/* + +void getTimeFromUser(int& hours, int& minutes, int& seconds); +void displayTime(int& hours, int& minutes, int& seconds, int MODE = 1); + +int main(void) +{ + int h, m, s, MODE = 0; + + getTimeFromUser(h, m, s); + + while ((MODE != 1) && (MODE != 2) && (MODE != 3)) + { + cout << "Please chose the time format to display:" << endl << "1) - 24 Hour time" << endl << "2) - Military time" << endl << "3) - 12 Hour time (standard)" << endl; + cin >> MODE; + if ((MODE != 1) && (MODE != 2) && (MODE != 3)) + { + cout << "Invalid mode" << endl; + } + } + + cout << endl << "The time is "; + + displayTime(h, m, s, MODE); + + return (0); +} + + +void getTimeFromUser(int& hours, int& minutes, int& seconds) +{ + int check = 0; + while (check == 0) + { + cout << "Please enter the current time:" << endl << "Hours: "; + cin >> hours; + cout << "Minutes: "; + cin >> minutes; + cout << "Seconds: "; + cin >> seconds; + cout << endl; + + if ((hours >= 24) || (minutes >= 60) || (seconds >= 60)) + { + check = 0; + cout << "Invalid time" << endl; + } + else + { + check = 1; + } + } +} + +void displayTime(int& hours, int& minutes, int& seconds, int MODE) +{ + switch (MODE) + { + case 1: + cout << setfill('0') << setw(2) << hours << ":" << setfill('0') << setw(2) << minutes << ":" << setfill('0') << setw(2) << seconds << endl; + break; + case 2: + cout << setfill('0') << setw(2) << hours << setfill('0') << setw(2) << minutes << endl; + //It is unclear if military time format uses seconds, but most sources claim that it does not. + break; + case 3: + if (hours >= 12) + { + hours %= 12; + cout << hours << ":" << setfill('0') << setw(2) << minutes << ":" << setfill('0') << setw(2) << seconds << " PM" << endl; + } + else + { + cout << hours << ":" << setfill('0') << setw(2) << minutes << ":" << setfill('0') << setw(2) << seconds << " AM" << endl; + } + break; + default: + cout << endl << "Error" << endl; + break; + } +} +*/ + +//8b - 9.14PE#1 + +/* +void DisplayRect(int width, int height); + +int main(void) +{ + int userW = 0, userH = 0; + + //Get user input + while ((userW <= 1) || (userH <= 1)) + { + cout << "Enter width and height of the rectangle: " << endl; + cin >> userW >> userH; + cout << endl; + + if ((userW <= 1) || (userH <= 1)) + { + cout << "Size too small" << endl; + } + } + + DisplayRect(userW, userH); + + return (0); +} + +void DisplayRect(int width, int height) +{ + for (int idxY = 0; idxY <= height; idxY++) + { + if (idxY == 0) //Top segment + { + cout << (char)218; + + for (int fillW = 0; fillW <= width - 3; fillW++) + { + cout << (char)196; + } + + cout << (char)191 << endl; + } + else if (idxY < height) //Middle segments + { + cout << (char)179 << setw(width - 1) << (char)179 << endl; + } + else //Bottom segment + { + cout << (char)192; + + for (int fillW = 0; fillW <= width - 3; fillW++) + { + cout << (char)196; + } + + cout << (char)217 << endl; + } + } +} +*/ + + +//8a - 9.13-Debug-Ex + +//Note: code from textbook, modified my Jordan Harris-Toovy. Answers to asked questions in the Textual Work file + +/* +* 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? +* 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? +* 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? +* 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? +* 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() +{ + int age = 0; + int days = 0; + + // Breakpoint 1 + // Put breakpoint on the following line + age = GetAge(); //Fixed issue where function was not passing back to a variable + 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) //Fixed an issue where input names were swapped +{ + cout << age << "! Boy are you old!\n"; + cout << "Did you know that you are at least " << days << " days old?\n\n"; +} + +*/
\ No newline at end of file |