aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBensProgramma <[email protected]>2021-10-25 20:00:44 -0700
committerGitHub <[email protected]>2021-10-25 20:00:44 -0700
commit6ed44dd8d430a367beb729708f858fbd8be35f8b (patch)
tree9f890c8ff46474639d8ff123be1b9776b93c1b31
parentUpdate CST116F2021-Lab4.cpp (diff)
downloadcst116-lab4-bensprogramma-6ed44dd8d430a367beb729708f858fbd8be35f8b.tar.xz
cst116-lab4-bensprogramma-6ed44dd8d430a367beb729708f858fbd8be35f8b.zip
Update CST116F2021-Lab4.cpp
-rw-r--r--CST116F2021-Lab4/CST116F2021-Lab4.cpp426
1 files changed, 249 insertions, 177 deletions
diff --git a/CST116F2021-Lab4/CST116F2021-Lab4.cpp b/CST116F2021-Lab4/CST116F2021-Lab4.cpp
index 1c8eae7..5405309 100644
--- a/CST116F2021-Lab4/CST116F2021-Lab4.cpp
+++ b/CST116F2021-Lab4/CST116F2021-Lab4.cpp
@@ -5,7 +5,7 @@
-#include <iostream>
+#include <iostream> ////Some of the functions used in this lab are here at the top
using namespace std;
float average(float, float, float);
@@ -17,209 +17,281 @@ void PrintCalculations(int, float, int);
void mouse(char);
void elephant(double& );
-// p207
-//int main()
-//{
-/*
-7a
-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
-
-
- float a = 0;
- a = sqrt(pow(abs(-2),4));
- cout << a;
-*/
-/*
-9.3 Exercises
-p 207
-10 pts #1
-Submit: code & run
+// p207
+//
+//int main()
+//
+//{
-// int main()
-// {
+///*7a
+//6.8 Exercises
+//pp 132-133
+//5 pts #1-9
+//Submit: value of “a” after the expression is executed
+// 1) a = 3.0
+// 2) -nan(ind)
+// 3) 32
+// 4) 25
+// 5) 6
+// 6) 6
+// 7) 5
+// 8) 5
+// 9) 4
//
-// average(3.2, 6.0, 8.6);
-// return 0;
-// }
//
-// float average(float x, float y, float z)
-// {
+// float a = 0;
+// a = sqrt(pow(abs(-2),4));
+// cout << a;
+//*/
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///*
+//9.3 Exercises
+//p 207
+//10 pts #1
+//Submit: code & run
+//
//
-// cout << "The average of these three #'s is : " << (x + y + z) / 3 << ".\n";
-// return 0.0;
-// }
-//
+////int main()
+////{
+//// average(3.2, 6.0, 8.6);
+//// return 0;
+////}
+////
+//// float average(float x, float y, float z)
+//// {
+////
+//// cout << "The average of these three #'s is : " << (x + y + z) / 3 << ".\n";
+//// return 0.0;
+//// }
+////
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///*
+//9.4 Learn by Doing Exercises
+//p 214
+//10 pts #1
+//*/
+////int main()
+////{
+//// int years_service = 0;
+//// float salary = 0.0;
+////
+//// while (salary <= 0)
+//// {
+//// GetInput(salary, years_service);
+//// cout << "Salary is : " << salary << ".\n";
+//// }
+////
+//// CalcRaise(salary,years_service);
+//// int bonus = CalcBonus(years_service);
+////
+//// PrintCalculations(years_service, salary, bonus);
+////
+//// return 0;
+////}
+////
+////void GetInput(float& sal, int& years_serv) // salary, and years_service have been passed by reference (Global Changes)
+////{
+//// cout << "Enter the employee's salary: ";
+//// cin >> sal;
+//// if (sal > 0)
+//// {
+//// cout << "Enter the employee's years of service: ";
+//// cin >> years_serv;
+//// {
+////}
+////
+////void CalcRaise(float& salary, int years_service) //copy of years_service has been sent here
+////{
+//// if (years_service > 10)
+//// {
+//// salary = salary*1.1;
+//// }
+//// else if (years_service >= 5 && years_service <= 10)
+//// {
+//// salary = salary*1.05;
+//// }
+//// else
+//// {
+//// salary = salary*1.02;
+//// }
+////}
+////
+////int CalcBonus(int years_service) //copy of years_service has been sent here
+////{
+//// int bonus = 500 * (years_service / 2);
+////
+//// return bonus;
+////}
+////
+////void PrintCalculations(int years_service, float salary, int bonus) ////copy of years_service, salary, and bonus has been sent here
+////{
+//// cout << "\n*******************************************************************************************\n\n";
+//// cout << "\t\tThis employee's new salary is: $" << salary<<".\n";
+//// cout << "\t\tAfter " << years_service << " years of service, they have earned a bonus of: $" << bonus << ".\n\n";
+//// cout << "*******************************************************************************************";
+////}
+////
+////
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//// IN CLASS EXAMPLE of passing by reference and passing by value ////////////////////////////////////////////////////////////////
+////
+//// char c = 'A';
+//// double d = 3.5;
+//// mouse(c);
+//// elephant(d);
+//// cout << "The char VAlUE is: " << c << ".\n\n";
+//// cout << "The double VAlUE is: " << d << ".\n\n";
+////
+////}
+////void mouse(char littleChar)
+////{
+//// cout << "The char Value passed was: " << littleChar << ".\n\n";
+//// littleChar = 'B';
+////}
+////
+////void elephant(double& bigNum)
+////{
+//// cout << "The Reference VAlUE passed to: " << bigNum << ".\n\n";
+//// bigNum = 153.15;
+////}
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// 7c
+//9.5 Learn by Doing Exercises
+//p 216
+//10 pts #2
+// 9.5_1 Learn by Doing Exercises p 216
+// 1 Write a program to display times in different formats
/*
-9.4 Learn by Doing Exercises
-p 214
-10 pts #1
-*/
-// //FUNCTIONS ARE INTIALIZED AT THE TOP AND DEFINED BELOW main()
-// int main()
-// {
-// int years_service = 0;
-// float salary = 0.0;
-//
-// while (salary <= 0)
-// {
-// GetInput(salary, years_service);
-// cout << "Salary is : " << salary << ".\n";
-// }
-//
-// CalcRaise(salary,years_service);
-// int bonus = CalcBonus(years_service);
-//
-// PrintCalculations(years_service, salary, bonus);
+# 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;
+}
+
+void getTime(int& hour, int& min, int& sec) //Function to as 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;
+ }
+}
+
+void displayTime(int hour,int min,int sec,int F) //Function to display the time in 3 different format based on 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";
+ }
+}
+
+
+*/
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//8a
+//9.13 Debugging Exercises
+//pp 226 - 229
+//10 pts #1
//
//
-// return 0;
-// }
+//#include <iostream>
+//using std::cout;
+//using std::cin;
+//using std::endl;
//
+//const int DAYS_PER_YEAR = 365;
//
-//void GetInput(float& sal, int& years_serv) // salary, and years_service have been passed by reference (Global Changes)
-//{
-// cout << "Enter the employee's salary: ";
-// cin >> sal;
-// if (sal > 0)
-// {
-// cout << "Enter the employee's years of service: ";
-// cin >> years_serv;
-// }
-//}
+//int GetAge();
+//int CalcDays(int);
+//void PrintResults(int, int);
//
-//void CalcRaise(float& salary, int years_service) //copy of years_service has been sent here
+//int main()
//{
-// if (years_service > 10)
-// {
-// salary = salary*1.1;
-// }
-// else if (years_service >= 5 && years_service <= 10)
-// {
-// salary = salary*1.05;
-// }
-// else
-// {
-// salary = salary*1.02;
-// }
-//}
+// int age = 0;
+// int days = 0;
//
+// // Breakpoint 1
+// // Put breakpoint on the following line
+// age = GetAge();
+// days = CalcDays(age);
//
-//int CalcBonus(int years_service) //copy of years_service has been sent here
-//{
-// int bonus = 500 * (years_service / 2);
+// // Breakpoint 2
+// // Put breakpoint on the following line
+// PrintResults(days, age);
//
-// return bonus;
+// return 0;
//}
//
-//void PrintCalculations(int years_service, float salary, int bonus) ////copy of years_service, salary, and bonus has been sent here
+//// FUNCTIONS
+//int GetAge()
//{
-// cout << "\n*******************************************************************************************\n\n";
-// cout << "\t\tThis employee's new salary is: $" << salary<<".\n";
-// cout << "\t\tAfter " << years_service << " years of service, they have earned a bonus of: $" << bonus << ".\n\n";
-// cout << "*******************************************************************************************";
-//
+// int age;
//
+// cout << "Please enter your age: ";
+// cin >> age;
+//
+// return age;
//}
-//
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// In class example of passing by reference and passing by value ////////////////////////////////////////////////////////////////
-//int main()
-//{
-// char c = 'A';
-// double d = 3.5;
-// mouse(c);
-// elephant(d);
-// cout << "The char VAlUE is: " << c << ".\n\n";
-// cout << "The double VAlUE is: " << d << ".\n\n";
-//}
-//void mouse(char littleChar)
+//int CalcDays(int years)
//{
-// cout << "The char Value passed was: " << littleChar << ".\n\n";
-// littleChar = 'B';
+// int days;
+//
+// days = years * DAYS_PER_YEAR;
+//
+// return days;
//}
-//void elephant(double& bigNum)
+//void PrintResults(int days, int age)
//{
-// cout << "The Reference VAlUE passed to: " << bigNum << ".\n\n";
-// bigNum = 153.15;
+// cout << age << "! Boy are you old!\n";
+// cout << "Did you know that you are at least " << days << " days old?\n\n";
//}
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-
-/// pad with zeros p94
-//include<iomanip>
-//cout <<setw(2)<<setfill('0')<<hr;
-
-////////////////////////////////////////////////////////////////
-
-
-#include <iostream>
-using std::cout;
-using std::cin;
-using std::endl;
-
-const int DAYS_PER_YEAR = 365;
-
-int GetAge();
-int CalcDays(int);
-void PrintResults(int, int);
-
-//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(days, age);
-
- return 0;
-}
-
-// FUNCTIONS
-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 days, int age)
-{
- cout << age << "! Boy are you old!\n";
- cout << "Did you know that you are at least " << days << " days old?\n\n";
-}
+//
+//
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////