aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CST116F2021-Lab4/RunFromLab4_Schroeder.txt238
1 files changed, 206 insertions, 32 deletions
diff --git a/CST116F2021-Lab4/RunFromLab4_Schroeder.txt b/CST116F2021-Lab4/RunFromLab4_Schroeder.txt
index c41e597..f9f10c0 100644
--- a/CST116F2021-Lab4/RunFromLab4_Schroeder.txt
+++ b/CST116F2021-Lab4/RunFromLab4_Schroeder.txt
@@ -1,23 +1,36 @@
Lab4 Code and Runs txt Benjamin Schroeder
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-6.8 Exercises pp 132-133 #1-9
-Submit: value of �a� after the expression is executed
- 1) a = 3.0
- 2) -nan(ind)
- 3) a = 32
- 4) a = 25
- 5) a = 6
- 6) a = 6
- 7) a = 5
- 8) a = 5
- 9) a = 4
-
-
-
+6.8 Exercises
+pp 132-133
+5 pts #1-9
+Submit: value of “a” after the expression is executed
+
+ 1) a= sqrt(9.0); ... a = 3.0
+ 2) a= sqrt(-9.0); ... -nan(ind)
+ 3) a = pow(2.0,5); ... a= 32
+ 4) a = pow(2.0,-2); ... a= .25
+ 5) a = ceil(5.1); ... a= 6
+ 6) a = ceil(5.9); ... a =6
+ 7) a = floor(5.1); ... a = 5
+ 8) a = floor(5.9); ... a = 5
+ 9) a = sqrt(pow(abs(-2),4)); a=4
+
+//int main() // example code
+//{
+// float a = 0;
+// a = sqrt(pow(abs(-2),4));
+// cout << a;
+//}
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-Code from 9.3_1 p207
+9.3_1 Exercises
+p 207
+10 pts #1
+Submit: code & run
+ ///// CODE /////
#include <iostream>
using namespace std;
@@ -37,7 +50,11 @@ float average(float x, float y, float z)
cout << "The average of these three #'s is : " << (x + y + z) / 3 << ".\n";
return 0.0;
}
- ////
+
+
+
+
+ //// RUN ////
Run from 9.3_1 p207
The average of these three #'s is : 5.93333.
@@ -46,10 +63,14 @@ C:\Users\Lenovo\source\repos\Lab4_Schroeder\Debug\Lab4_Schroeder.exe (process 69
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 . . .
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-Code for 9.4_1 p214
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+9.4_1 Learn by Doing Exercises
+//p 214
+//10 pts #1
+ //// CODE ////
#include <iostream>
using namespace std;
@@ -124,7 +145,7 @@ void PrintCalculations(int years_service, float salary, int bonus) ////copy of y
}
- ////
+ //// RUN ////
Run from 9.4_1 p214
Enter the employee's salary: 25000
@@ -142,24 +163,101 @@ To automatically close the console when debugging stops, enable Tools->Options->
Press any key to close this window . . .
+
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-9.5_2 Learn by Doing Exercises p 216
-# 2 Which of the following call statements would be valid?
+9.5_1 Learn by Doing Exercises p 216
+# 1 Write a program to display the time in 3 different formats
+
+
+ //// CODE ////
+# include<iomanip>
+void getTime(int& hour, int& min, int& sec);
+void displayTime(int,int,int,int F=3);
+
+int main()
+{
+ int hour = 0, min=0, sec=0;
+ int F;
+
+ getTime(hour, min, sec);
+ cout << "\n\n";
+ displayTime(hour, min, sec);
+ displayTime(hour, min, sec, 1);
+ displayTime(hour, min, sec, 2);
+ return 0;
+}
-int records =0;
-void ReadData(int& records,int size = 11);
+void getTime(int& hour, int& min, int& sec) // function to ask for the time
+{
+ hour = -1;
+ min = -1;
+ sec = -1;
+ cout << "Please enter the Time:\n";
+ while (hour > 24 || hour < 0)
+ {
+ cout << "\tHour (0 to 24): ";
+ cin >> hour;
+ }
+ while (min > 59 || min < 0)
+ {
+ cout << "\tMinute (0 to 59):";
+ cin >> min;
+ }
+ while (sec > 59 || sec < 0)
+ {
+ cout << "\tSecond(0 to 59): ";
+ cin >> sec;
+ }
+}
-a) Valid size = 11
-b) INVALID no records input
-c) INVALID no records input
-d) INVALID 3 inputs
-e) Valid
+void displayTime(int hour,int min,int sec,int F) //function to display the time , format depending upon F
+{
+ string ampm = "am";
+
+ if (F == 1)
+ cout << "\t24 hr notation: " << setw(2) << setfill('0') << hour << ":" << setw(2) << setfill('0') << min << ":" << setw(2) << setfill('0') << sec << "\n";
+ else if (F == 2)
+ cout << "\tMilitary time: " << setw(2) << setfill('0') << hour << setw(2) << setfill('0') << min << ":" << setw(2) << setfill('0') << sec << "\n";
+ else if (F == 3)
+ {
+ if (hour > 12)
+ {
+ hour = hour - 12;
+ ampm = "pm";
+ }
+ cout << "\tStandard format: " << hour << ":" << setw(2) << setfill('0') << min << ":" << setw(2) << setfill('0') << sec << ampm<<"\n";
+ }
+
+}
+Run from 9.5_1 //// RUN ////
+
+Please enter the Time:
+ Hour (0 to 24): 16
+ Minute (0 to 59):1
+ Second(0 to 59): 8
+
+
+ Standard format: 4:01:08pm
+ 24 hr notation: 16:01:08
+ Military time: 1601:08
+
+C:\Users\Lenovo\Source\Repos\cst116-lab4-BensProgramma\x64\Debug\CST116F2021-Lab4.exe (process 9696) 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 . . .
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-9.13_1 Debugging Exercises pp 226-229
+
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//9.13_1 Debugging Exercises
+//pp 226 - 229
+//10 pts
+ //// CODE ////
#include <iostream>
using std::cout;
using std::cin;
@@ -213,7 +311,7 @@ void PrintResults(int days, int age)
}
- /////
+ ///// RUN /////
Run from 9.13_1 Debugging Exercise
Please enter your age: 33
@@ -228,8 +326,84 @@ Press any key to close this window . . .
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-9.14_1 Programming Exercises pp 229
+9.14_1 Programming exercises
+p229
+// Draw A rectangle
+ //// CODE ////
+
+#include <iostream>
+#include<string>
+using namespace std;
+
+void DrawRect(int,int);
+
+int main() // Program to draw a rectangle on the screen of user defined dimensions
+{
+ int height = 0;
+ int width = 0;
+ cout << "Enter the dimensions of the rectangle I'm going to print on the screen\n";
+ cout << "Height: ";
+ cin >> height;
+ cout << "Width: ";
+ cin >> width;
+
+ DrawRect(height, width);
+
+ return 0;
+}
+
+void DrawRect(int height,int width) //Function that draws the rectangle
+{
+ //Top
+ string line(width,char(196));
+ line[0] = char(218);
+ line[width-1] = char(191);
+ cout << line<<"\n";
+
+ //Sides
+ string sides(width, char(32));
+ for (int i=1; i<height-2;i++)
+ {
+ sides[0] = char(179);
+ sides[width-1] =char(179);
+ cout << sides<<"\n";
+ }
+
+ //Bottom
+ string bottom(width, char(196));
+ bottom[0] = char(192);
+ bottom[width-1] = char(217);
+ cout << bottom;
+}
+
+
+ ///// RUN //////
+Run from 9.14_1
+
+Enter the dimensions of the rectangle I'm going to print on the screen
+Height: 10
+Width: 25
+┌───────────────────────┐
+│ │
+│ │
+│ │
+│ │
+│ │
+│ │
+│ │
+└───────────────────────┘
+C:\Users\Lenovo\Source\Repos\cst116-lab4-BensProgramma\x64\Debug\CST116F2021-Lab4.exe (process 23708) 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 . . .
+
+
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+