-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFenton_reference.cpp
More file actions
196 lines (164 loc) · 5.05 KB
/
Fenton_reference.cpp
File metadata and controls
196 lines (164 loc) · 5.05 KB
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// Name: Ali Fenton
// Date: October 16,2015
// Programming Practice - Functions D
#include <iostream>
#include <cmath>
#include <cassert>
using namespace std;
//**********************************Problem 1*********************************************
void sort(int& numA, int& numB, int& numC);
// Summary: Sorts the 3 numbers by increasing order
// Precondition: The 3 numbers will be between 0-100 if it not it will leave the code
// Postcondition: It will put them in order from smallest to biggest
//**********************************Problem 2*********************************************
void numDigits(int valA, int& n);
// Summary: Find put what range they are in from 1-5 and tells you where they go
// Precondition: If it sees that its not in range the program will not work
// Postcondition: It will see if its in range it will print return from 1-5
//**********************************Problem 3*********************************************
void computeSphere(double& a, double& v, double r);
// Summary: find the volume and area of a sphere
// Precondition: Make sure that it in range of 0-10000 if not leaves codes
// Postcondition: After running the code it should tell you the volume and area
//**********************************Problem 4*********************************************
void swap(int& A, int& B);
// Summary: Move the numbers to the other variable
// Precondition: Makes sure that the numbers will swap if not it will leave the code
// Postcondition: If the code works it will swap the numbers to the other variable
int main(){
// Problem 1
int valA = 1, valB = 10, valC = 5;
sort(valA,valB,valC);
assert(valA == 1);
assert(valB == 5);
assert(valC == 10);
int valA1 = 90, valB1 = 5, valC1 = 0;
sort(valA1,valB1,valC1);
assert(valA1 == 0);
assert(valB1 == 5);
assert(valC1 == 90);
int valA2 = 8, valB2 = 1, valC2 = 15;
sort(valA2,valB2,valC2);
assert(valA2 == 1);
assert(valB2 == 8);
assert(valC2 == 15);
//Problem 2
int val;
numDigits(34, val);
assert(val == 2);
int valBB;
numDigits(9879, valBB);
assert(valBB == 4);
int val2B;
numDigits(1, val2B);
assert(val2B == 1);
//Problem 3
double area, volume, e = .0001;
computeSphere(area, volume, 4);
assert((area - 201.062) < e);
assert((volume - 67.020643276) < e);
double area1, volume1;
computeSphere(area1, volume1, 7.1);
assert(( area1 - 633.47074265) < e);
assert(( volume1 - 374.80352275) < e);
double area2, volume2;
computeSphere(area2, volume2, 0);
assert(( area2 - 0) < e);
assert(( volume2 - 0) < e);
// Problem 4
int swapA = 7, swapB = 9;
swap(swapA, swapB);
assert(swapA == 9);
assert(swapB == 7);
int swapA1 = 2, swapB1 = 2;
swap(swapA1, swapB1);
assert(swapA1 == 2);
assert(swapB1 == 2);
int swapA2 = 3, swapB2 = 100;
swap(swapA2, swapB2);
assert(swapA2 == 100);
assert(swapB2 == 3);
return 0;
}
//******************Problem 1**********************
void sort(int& numA, int& numB, int& numC){
assert(numA <= 100);
assert(numA>=0);
assert(numB <= 100);
assert(numB>=0);
assert(numC <= 100);
assert(numC >= 0);
int tempA,tempB,temp;
if ((numA > numB) && (numA > numC)){
tempA = numA;
if (numB > numC){
numA = numC;
numC = tempA;
}else if (numC > numB){
numA = numB;
numB = numC;
numC = tempA;
}
}else if ((numB > numC) && (numB > numA)){
tempB = numB;
if (numA > numC){
numB = numA;
numA = numC;
numC = tempB;
}else if (numC > numA){
numB = numC;
numC = tempB;
}
}else if ((numC > numA) && (numC > numB)){
if (numA > numB){
temp = numA;
numA = numB;
numB = temp;
}else if (numB > numA){
numA;
numB;
numC;
}
}
return;
}
//******************Problem 2**********************
void numDigits(int valA, int& n){
assert(valA >= -10000);
assert(valA <= 10000);
int valB;
valB = abs(valA);
if(valB >= 10000){
n = 5;
}
if(valB >= 1000 && valB < 10000){
n = 4;
}
if(valB >= 100 && valB < 1000){
n = 3;
}
if(valB >= 10 && valB < 100){
n = 2;
}
if(valB >= 0 && valB < 10){
n = 1;
}
return;
}
//******************Problem 3**********************
void computeSphere(double& a, double& v, double r){
assert(r >= 0);
assert(r <= 10000);
const double PI = 3.14159265359;
a = 4 * PI * r * r;
v = ((1/3) * PI * r * r * r);
return;
}
//******************Problem 4**********************
void swap(int& a, int& b){
int result;
result = a;
a = b;
b = result;
return;
}