aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBensProgramma <[email protected]>2021-10-24 14:48:38 -0700
committerGitHub <[email protected]>2021-10-24 14:48:38 -0700
commit9aa40ed9d692693499b44661a33d4dcf85e8c6dc (patch)
tree5549682d091a35b28861c220e82a8a92e0b28892
parentAdd online IDE url (diff)
downloadcst116-lab4-bensprogramma-9aa40ed9d692693499b44661a33d4dcf85e8c6dc.tar.xz
cst116-lab4-bensprogramma-9aa40ed9d692693499b44661a33d4dcf85e8c6dc.zip
Update CST116F2021-Lab4.cpp
-rw-r--r--CST116F2021-Lab4/CST116F2021-Lab4.cpp237
1 files changed, 226 insertions, 11 deletions
diff --git a/CST116F2021-Lab4/CST116F2021-Lab4.cpp b/CST116F2021-Lab4/CST116F2021-Lab4.cpp
index ff0073d..9b5b8f9 100644
--- a/CST116F2021-Lab4/CST116F2021-Lab4.cpp
+++ b/CST116F2021-Lab4/CST116F2021-Lab4.cpp
@@ -1,20 +1,235 @@
-// CST116F2021-Lab4.cpp : This file contains the 'main' function. Program execution begins and ends there.
+// Lab4_Schroeder.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
+
+
+
+
+#include <iostream>
+using namespace std;
+
+float average(float, float, float);
+
+void GetInput(float&, int&);
+void CalcRaise(float&, int);
+int CalcBonus(int); //Pass by value
+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 = 3.0
+ 2) -nan(ind)
+ 3) 32
+ 4) 25
+ 5) 6
+ 6) 6
+ 7) 5
+ 8) 5
+ 9) 4
+
+
+ float a = 0;
+ a = sqrt(pow(abs(-2),4));
+ cout << a;
+*/
+
+/*
+9.3 Exercises
+p 207
+10 pts #1
+Submit: code & run
+
+//
+//
+// 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 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;
+//
+//}
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+/// 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()
{
- std::cout << "Hello World!\n";
+ 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";
+}
+
+
+
+
+
-// 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