diff options
| author | James Lawrance <[email protected]> | 2021-10-23 10:17:51 -0700 |
|---|---|---|
| committer | James Lawrance <[email protected]> | 2021-10-23 10:17:51 -0700 |
| commit | 6dab8c7a4bead7c0d6e295a1be544731361ac716 (patch) | |
| tree | 0849ce2d597b22b4a6a74de4b7057079dd5d3805 /CST116F2021-Lab4 | |
| parent | Text file up to 7c (diff) | |
| download | cst116-lab4-jemersonlawrance-master.tar.xz cst116-lab4-jemersonlawrance-master.zip | |
Diffstat (limited to 'CST116F2021-Lab4')
| -rw-r--r-- | CST116F2021-Lab4/CST116F2021-Lab4.cpp | 561 |
1 files changed, 374 insertions, 187 deletions
diff --git a/CST116F2021-Lab4/CST116F2021-Lab4.cpp b/CST116F2021-Lab4/CST116F2021-Lab4.cpp index d1e26c2..334c62c 100644 --- a/CST116F2021-Lab4/CST116F2021-Lab4.cpp +++ b/CST116F2021-Lab4/CST116F2021-Lab4.cpp @@ -90,196 +90,383 @@ using namespace std; //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); +//void getTime(int &hours, int &minutes, int &seconds); +//void displayTime(int hours, int minutes, int seconds, int style); -int main() -{ +//int main() +//{ //defining local variables - int hrs = 0; int mins = 0; int secs = 0; char styleChoice = 0; int style = 0; +// int hrs = 0; int mins = 0; int secs = 0; char styleChoice = 0; int style = 0; //get time - getTime(hrs, mins, secs); +// 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); +// 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); +// displayTime(hrs, mins, secs, style); //exit - return 0; -} - -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; - } - - 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 +// return 0; +//} + +//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; +// } + +// if (AmPm == 'A') +// { +// cout << "AM in standard format" << endl; +// } +// else if (AmPm == 'P') +// { +// cout << "PM in standard format" << endl; +// } +// } +//} + +//8a +//9.13 Debugging Exercises + +/******************************************************************** +* 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. 0x010ffa60 {0} +* 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(); +// 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"; +//} + +//8b +//9.14 Programming Exercises + +//void getDimensions(int&, int&); +//void createRectangle(int&, int&); + +//int main() +//{ + //defining variables +// int width = 0; int height = 0; + //greeting +// cout << "Welcome to the rectangle program!" << endl +// << "It is time to create a rectangle with dimensions that you specify." << endl; + //get width and height +// getDimensions(width, height); + //print rectangle +// createRectangle(width, height); + //results and farewell +// cout << endl << "Above is your rectangle, " << width << " units wide and " << height << " units tall." << endl +// << "Thank you for trying the rectangle program!" << endl; +// return 0; +//} + +//void getDimensions(int& width, int& height) +//{ +// cout << endl << "What is the width of the rectangle?" << endl; +// cin >> width; +// cout << "Ok, got it. And what about the height?" << endl; +// cin >> height; cout << endl; +//} + +//void createRectangle(int& width, int& height) +//{ +// int widthCount = width; int heightCount = height; +// char upperLeftCorner = 218, upperRightCorner = 191, lowerLeftCorner = 192, lowerRightCorner = 217, widthSides = 196, heightSides = 179; + +// for (heightCount; heightCount > 0; heightCount--) +// { +// if (heightCount == height) +// { +// cout << upperLeftCorner; +// for (widthCount-2; widthCount > 0; widthCount--) +// { +// cout << widthSides; +// } +// cout << upperRightCorner; +// } + +// if (heightCount < height && heightCount > 1) +// { +// cout << heightSides; +// for (widthCount-2; widthCount > 0; widthCount--) +// { +// cout << " "; +// } +// cout << heightSides; +// } + +// if (heightCount == 1) +// { +// cout << lowerLeftCorner; +// for (widthCount - 2; widthCount > 0; widthCount--) +// { +// cout << widthSides; +// } +// cout << lowerRightCorner; +// } + +// cout << endl; +// widthCount = width; +// } +//}
\ No newline at end of file |