diff options
| author | BensProgramma <[email protected]> | 2021-10-24 14:49:30 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-10-24 14:49:30 -0700 |
| commit | 4ce9a6df3c82ff6c5641a13ccec6ee5115d53e66 (patch) | |
| tree | c2177c9188a2b6fa27b77c297546a46f5664595e /CST116F2021-Lab4 | |
| parent | Update CST116F2021-Lab4.cpp (diff) | |
| download | cst116-lab4-bensprogramma-4ce9a6df3c82ff6c5641a13ccec6ee5115d53e66.tar.xz cst116-lab4-bensprogramma-4ce9a6df3c82ff6c5641a13ccec6ee5115d53e66.zip | |
Add files via upload
Diffstat (limited to 'CST116F2021-Lab4')
| -rw-r--r-- | CST116F2021-Lab4/RunFromLab4_Schroeder.txt | 236 |
1 files changed, 236 insertions, 0 deletions
diff --git a/CST116F2021-Lab4/RunFromLab4_Schroeder.txt b/CST116F2021-Lab4/RunFromLab4_Schroeder.txt new file mode 100644 index 0000000..c41e597 --- /dev/null +++ b/CST116F2021-Lab4/RunFromLab4_Schroeder.txt @@ -0,0 +1,236 @@ +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
+
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+Code from 9.3_1 p207
+
+#include <iostream>
+using namespace std;
+
+float average(float, float, float);
+
+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;
+ }
+ ////
+
+Run from 9.3_1 p207
+The average of these three #'s is : 5.93333.
+
+C:\Users\Lenovo\source\repos\Lab4_Schroeder\Debug\Lab4_Schroeder.exe (process 6992) 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 . . .
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+Code for 9.4_1 p214
+
+
+#include <iostream>
+using namespace std;
+
+void GetInput(float&, int&);
+void CalcRaise(float&, int);
+int CalcBonus(int); //Pass by value
+void PrintCalculations(int, float, int);
+
+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 << "*******************************************************************************************";
+
+}
+
+ ////
+Run from 9.4_1 p214
+
+Enter the employee's salary: 25000
+Enter the employee's years of service: 12
+Salary is : 25000.
+
+*******************************************************************************************
+
+ This employee's new salary is: $27500.
+ After 12 years of service, they have earned a bonus of: $3000.
+
+*******************************************************************************************
+C:\Users\Lenovo\source\repos\Lab4_Schroeder\Debug\Lab4_Schroeder.exe (process 13704) 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.5_2 Learn by Doing Exercises p 216
+# 2 Which of the following call statements would be valid?
+
+int records =0;
+void ReadData(int& records,int size = 11);
+
+a) Valid size = 11
+b) INVALID no records input
+c) INVALID no records input
+d) INVALID 3 inputs
+e) Valid
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+9.13_1 Debugging Exercises pp 226-229
+
+#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";
+}
+
+
+ /////
+Run from 9.13_1 Debugging Exercise
+
+Please enter your age: 33
+33! Boy are you old!
+Did you know that you are at least 12045 days old?
+
+
+C:\Users\Lenovo\source\repos\Chapter9_Debug\Debug\Chapter9_Debug.exe (process 21340) 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.14_1 Programming Exercises pp 229
+
+
+
+
|