-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHernandez_reference.cpp
More file actions
166 lines (143 loc) · 4.05 KB
/
Hernandez_reference.cpp
File metadata and controls
166 lines (143 loc) · 4.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
// Bianca Hernandez
// Created: October 15, 2015
// Summary:
//
//**********************************************
#include<iostream> //cin/cout
#include<string> // string manipulation
#include<cmath> // pow
#include<cstdlib>
#include<cassert> // assert testing
using namespace std;
//************************************************************
void sort(int& numA, int&numB, int& numC);
//Pre-Condition: accept values from (0-100)
//Post Condition: numbers are sorted in increasing order and then returned
//
//************************************************************
//************************************************************
void numDigits(int valA, int& n);
//Pre-Condition: accept values from (-10000 - 10000)
//Post Condition: counts how many digits are in the integers
//
//************************************************************
//************************************************************
void computeSphere(double& a, double& v, double r);
//Pre-Condition: accepts in values of double type numbers between (0-10000)
//Post Condition: returns the value of the area and volume of a sphere
//
//************************************************************
//************************************************************
void swap(int& A, int&B);
//Pre-Condition: accepts in only positive integers
//Post Condition:values have been swapped and then returned
//
//************************************************************
int main()
{
int numA = 52;
int numB = 96;
int numC = 13;
int valA = -5002;
int n = -6352;
double a = 1526;
double v = 9999;
double r = 5;
int A = 6;
int B = 42;
//sort
cout<< "Before:\tnumA: " << numA << "\t numB: " << numB << "\t numC: " << numC << endl; // Test case 1
sort(numA, numB, numC);
cout<< "After: \tnumA: " << numA << "\t numB: " << numB << "\t numC: " << numC << endl;
cout<< "Before:\tnumA: " << numA << "\t numB: " << numB << "\t numC: " << numC << endl; // Test case 2
sort(numA, numB, numC);
cout<< "After: \tnumA: " << numA << "\t numB: " << numB << "\t numC: " << numC << endl << endl;
// numDigits
cout << "Before:\tvalA: " << valA << "\t n: " << n << endl; // Test Case1
numDigits(valA, n);
cout << "After: \tvalA: " << valA << "\t n: " << n << endl;
cout << "Before:\tvalA: " << numC<< "\t n: " << n << endl; // Test case2
numDigits(numC, n);
cout << "After: \tvalA: " << numC << "\t n: " << n << endl << endl;
// computeSphere
cout << "Before:\ta: " << a << "\t v: " << v << endl; // Test Case1
computeSphere(a, v, r);
cout << "After: \ta: " << a << "\t v: " << v << endl;
cout << "Before:\ta: " << a << "\t v: " << v << endl; // Test Case2
computeSphere(a, v, numA);
cout << "After: \ta: " << a << "\t v: " << v << endl << endl;
// swap
cout << "Before;\tA: " << A << "\t B: " << B << endl;// Test case 1
swap(A,B);
cout << "After: \tA: " << A << "\t B: " << B << endl;
cout << "Before:\tA: " << numC << "\t B: " << B << endl;// Test case 1
swap(numC,B);
cout << "After: \tA: " << numC << "\t B: " << B << endl << endl;
return 0;
}
void sort(int& numA, int& numB, int& numC)
{
assert(numA >= 0 && numA <= 100 );
assert(numB >= 0 && numB <= 100 );
assert(numC >= 0 && numC <= 100 );
int temp;
if(numC < numB && numC < numA)
{
temp = numA;
numA = numC;
if(temp < numB )
{
numC = numB;
numB = temp;
}
}
else if (numB < numC && numB < numA)
{
temp = numC;
numC = numB;
if( temp < numA)
{
numB = numA;
numA = temp;
}
}
else if( numC < numB)
{
temp = numC;
numC = numB;
numB = temp;
}
return;
}
void numDigits(int valA, int& n)
{
assert(valA >= -10000 && valA <= 10000);
assert(n >= -10000 && n <= 10000);
string digits = to_string(valA);
if(valA < 0)
{
n = digits.length() - 1;
}
else
{
n = digits.length();
}
return;
}
void computeSphere(double& a, double& v, double r)
{
assert(a >= 0 && a <= 10000 );
assert(v >= 0 && v <= 10000 );
assert(r >= 0 && r <= 10000 );
const double PI = 3.14;
a = 4 * PI * pow(r,2);
v = (4.0/3.0) * PI * pow(r,3);
return;
}
void swap(int& A, int& B)
{
int temp = A;
A = B;
B = temp;
return;
}