aboutsummaryrefslogtreecommitdiff
path: root/CST116F2021-Lab4/Lab4_Taormina
blob: 787f66ac8569b8d484e9ea7e48b55f2b4a0388d0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
Tyler Taormina Lab 4 Text File
CST CST116
October 20, 2021

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
2. a = sqrt (-9.0);    a = nan
3. a = pow( 2.0, 5 );   a = 32
4. a = pow ( 2.0, -2 );  a = 0.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


________________________________________________________________________________________________________________________
9.3 Exercises
p 207
10 pts #1
Submit: code & run
Total: 15 pts


#include <iostream>
#include <cmath> // needed for square roots
using namespace std;

int avg_score (float& num1, float& num2, float& num3)
{
    int avg = 0;
    avg = ( num1 + num2 + num3 ) / 3;
    return avg;
}

int main() {

    float value1, value2, value3, average = 0.0;

    cout << "Enter 3 values that you want averaged." << endl;
    cout << "Enter value 1: " << endl;
    cin >> value1;
    cout << "Enter value 2: " << endl;
    cin >> value2;
    cout << "Enter value 3: " << endl;
    cin >> value3;

    average = avg_score(value1, value2, value3);
    cout << "Your average score is: " << average << endl;

    return 0;
}

RUN:
C:\Users\Till\CLionProjects\gitDemo\cmake-build-debug\gitDemo.exe
Enter 3 values that you want averaged.
Enter value 1:
20
Enter value 2:
19
Enter value 3:
21
Your average score is: 20

Process finished with exit code 0

________________________________________________________________________________________________________________________
7b
9.4 Learn by Doing Exercises
p 214
10 pts #1
Submit: code & runs
CODE:

#include <iostream>
using namespace std;

void GetInput (float& salary, int& years_service)
{
    cout << "Enter salary: ";
    cin >> salary;
    cout << "Enter years_service: ";
    cin >> years_service;
}

void CalcRaise (float& salary, int years_service)
{
    if (years_service > 10)
        salary += (salary * .10);
    else if (years_service >= 5)
        salary += (salary * .05);
    else
        salary += (salary * .02);
}


int CalcBonus (int years_service)
{
    int bonus = 0;
    int bonus_years = 0;
    bonus_years = years_service / 2;
    bonus = bonus_years * 500;
    return bonus;
}

void PrintCalc (int years_service, float salary, int bonus)
{
    cout << "Employee years of service is " << years_service << endl;
    cout << "Your current salary is $" << salary << endl;
    cout << "The bonus you will receive is $" << bonus << endl;
}

int main()
{
    int years_service = 0, bonus = 0;
    float salary = 0.0;

    GetInput(salary, years_service);
    CalcRaise(salary, years_service);
    bonus = CalcBonus(years_service);
    PrintCalc(years_service, salary, bonus);

    return 0;
}


RUN:
C:\Users\Till\CLionProjects\gitDemo\cmake-build-debug\gitDemo.exe
Enter salary:20000
 Enter years_service:10
 Employee years of service is 10
Your current salary is $21000
The bonus you will receive is $2500

Process finished with exit code 0
________________________________________________________________________________________________________________________

7c
9.5 Learn by Doing Exercises
p 216
10 pts #2
Submit: code & run





________________________________________________________________________________________________________________________
8a
9.13 Debugging Exercises
pp 226-229
10 pts #1
Submit: code & runs

8b
9.14 Programming Exercises
pp 229
10 pts #1
Submit: code & run

Total: 55 pts