aboutsummaryrefslogtreecommitdiff
path: root/CST116F2021-Lab4/CST116F2021-Lab4.cpp
diff options
context:
space:
mode:
authorJames Lawrance <[email protected]>2021-10-22 12:07:19 -0700
committerJames Lawrance <[email protected]>2021-10-22 12:07:19 -0700
commit12a4fdd113e1d10c1389e3e54aeed2575c97c4be (patch)
tree6f8d034a2712083dcbb37a3cad553d4579de01ba /CST116F2021-Lab4/CST116F2021-Lab4.cpp
parentAdd online IDE url (diff)
downloadcst116-lab4-jemersonlawrance-12a4fdd113e1d10c1389e3e54aeed2575c97c4be.tar.xz
cst116-lab4-jemersonlawrance-12a4fdd113e1d10c1389e3e54aeed2575c97c4be.zip
Text file up to 7c
Diffstat (limited to 'CST116F2021-Lab4/CST116F2021-Lab4.cpp')
-rw-r--r--CST116F2021-Lab4/CST116F2021-Lab4.cpp289
1 files changed, 277 insertions, 12 deletions
diff --git a/CST116F2021-Lab4/CST116F2021-Lab4.cpp b/CST116F2021-Lab4/CST116F2021-Lab4.cpp
index ff0073d..d1e26c2 100644
--- a/CST116F2021-Lab4/CST116F2021-Lab4.cpp
+++ b/CST116F2021-Lab4/CST116F2021-Lab4.cpp
@@ -1,20 +1,285 @@
-// CST116F2021-Lab4.cpp : This file contains the 'main' function. Program execution begins and ends there.
+#include <iostream>
+using namespace std;
+
+//7a
+//9.3 Learn by Doing Exercises
+
+//float avgFunction(float first, float second, float third);
+
+//int main()
+//{
+// float one = 0; float two = 0; float three = 0; float average = 0;
+// cout << "This program will find the average of 3 user values\n";
+//
+// average = avgFunction(one, two, three);
+// cout << "\nThe average is: " << average;
//
+// return 0;
+//}
-#include <iostream>
+//float avgFunction(float first, float second, float third)
+//{
+// cout << "Enter the first number: ";
+// cin >> first;
+// cout << "Enter the second number: ";
+// cin >> second;
+// cout << "Enter the third number: ";
+// cin >> third;
+//
+// return ((first + second + third) / 3);
+//}
+
+//7b
+//9.4 Learn by Doing Exercises
+
+//void GetInput(float& salary, int& years_service);
+//void CalcRaise(float& salary, int years_service);
+//int CalcBonus(int years_service);
+//void PrintCalculations(int years_service, float salary, int bonus);
+
+//int main()
+//{
+ //defining variables
+// float sal = 0; int years = 0;
+
+ //running functions
+// GetInput(sal, years);
+// CalcRaise(sal, years);
+// int bonus = CalcBonus(years);
+// PrintCalculations(years, sal, bonus);
+
+// return 0;
+
+//}
+
+//void GetInput(float& salary, int& years_service)
+//{
+// cout << "Enter the employee's salary\n";
+// cin >> salary;
+// cout << "Enter the employee's years of service\n";
+// cin >> years_service;
+//}
+
+//void CalcRaise(float& salary, int years_service)
+//{
+// if (years_service > 10)
+// {
+// salary *= 1.10;
+// }
+// else if (years_service < 10 && years_service > 5)
+// {
+// salary *= 1.05;
+// }
+// else
+// {
+// salary *= 1.02;
+// }
+//}
+
+//int CalcBonus(int years_service)
+//{
+// int bonusCounter = (years_service / 2);
+// return (bonusCounter * 500);
+//}
+
+//void PrintCalculations(int years_service, float salary, int bonus)
+//{
+// cout << endl << "The employee's new salary will be " << salary << ", and they will receive a bonus of " << bonus;
+//}
+
+//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);
int main()
{
- std::cout << "Hello World!\n";
+ //defining local variables
+ int hrs = 0; int mins = 0; int secs = 0; char styleChoice = 0; int style = 0;
+ //get time
+ 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);
+ //time display function
+ displayTime(hrs, mins, secs, style);
+ //exit
+ return 0;
}
-// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
-// Debug program: F5 or Debug > Start Debugging menu
+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;
+ }
-// 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 (AmPm == 'A')
+ {
+ cout << "AM in standard format" << endl;
+ }
+ else if (AmPm == 'P')
+ {
+ cout << "PM in standard format" << endl;
+ }
+ }
+} \ No newline at end of file