-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathgroup.cpp
232 lines (193 loc) · 5 KB
/
group.cpp
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// Name: Daniel Calderon
// Name: Angel Gonzalez
// Name: Sandra Flores
// Name: Miguel Fletes
// Nov 1 ,2015
// structural strength code
/* Question answered: Going by the data, neither of the items will be able to hold the amount of force required. If you go to three standard deviations the value will be below 16000 and as a result the bridge will succumb to the weight.*/
#include <vector>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cmath>
using namespace std;
double mean(ifstream& fin);
void maxMin(int ary[], int n,ofstream& fout);
double stdDev(ifstream& fin);
double var(ifstream& fin);
int main()
{
ifstream fin,finB;
ofstream fout;
fin.open("data1.txt");
finB.open("data2.txt");
fout.open("results.txt");
double val =0,valDeviation = 0,valDeviationB = 0,valVariance = 0,valVarianceB = 0;
const int SIZE = 10;
string string1;
int value, value1;
int numbers[SIZE] = {0};
int numbers1[SIZE] = {0};
string word;
fout << "Daniel Calderon, Angel Gonzalez, Miguel Fletes, Sandra Flores" << endl;
val = mean(fin);
fout << "The mean is: " << val << endl;
fout << " " << endl;
//********************************************************************************
fin.clear();
finB.clear();
fin.seekg(0);
finB.seekg(0);
valDeviation = stdDev(fin);
valDeviationB = stdDev(finB);
fout << "The standard devaition for steel is: " << valDeviation << endl;
fout << " " << endl;
fout << "The standard deviation for graphite is: " << valDeviationB << endl;
fout << " " << endl;
//********************************************************************************
for(int ix = 0; ix < 1; ix++)
{
fin >> string1;
}
for(int ix = 0; ix < SIZE; ix++)
{
fin >> value;
numbers[ix] = value;
}
fin.clear();
finB.clear();
fin.seekg(0);
finB.seekg(0);
for(int ix = 0; ix < 1; ix++)
{
finB >> string1;
}
for(int ix = 0; ix < SIZE; ix++)
{
finB >> value1;
numbers1[ix] = value1;
}
fout << "The max and min for steel are: " << endl;
maxMin(numbers, SIZE,fout);
fout << "The max and min for graphite are: "<< endl;
maxMin(numbers1, SIZE,fout);
//********************************************************************************
fin.clear();
finB.clear();
fin.seekg(0);
finB.seekg(0);
valVariance = var(fin);
valVarianceB = var(finB);
fout << "The variance for steel is: " << valVariance << endl;
fout << " " << endl;
fout << "The variance for graphite is: " << valVarianceB << endl;
//********************************************************************************
fin.close();
finB.close();
fout.close();
return 0;
}
//********************************************************************************
double mean(ifstream& fin)
{
int ary[20];
string word;
int val,size = 0;
int ix=0;
int sum = 0;
int i = 0;
for(i; i < 1; i++)
{
fin >> word;
}
while(fin >> val)
{
ary[ix] = val;
ix++;
size++;
}
for(i =0; i < size;i++)
{
sum += ary[i];
}
return sum/size ;
}
//********************************************************************************
void maxMin(int ary[], int n,ofstream& fout)
{
int min = ary[0];
for(int ix = 0; ix < n; ix++)
{
if(ary[ix] < min)
{
min = ary[ix];
}
}
fout << "min: " << min << endl;
fout << endl;
int max = ary[0];
for(int ix = 0; ix < n; ix++)
{
if(ary[ix] > max)
{
max = ary[ix];
}
}
fout << "max: " << max << endl;
fout << endl;
}
//********************************************************************************
double var(ifstream& fin)
{
double ary[5000];
int sizeAry = 0;
double temp, sum = 0, average, variance;
double squareSum = 0; //holds the square root sum of average - actual number in the array
int ix = 0;
string word;
for(int i =0; i < 1; i++)
{
fin >> word;
}
while (fin >> temp)
{
sizeAry++;
ary[ix] = temp;
ix++;
}
for(int i = 0; i < sizeAry ; i++)
{
sum += ary[i];
}
average = sum/sizeAry;
for(int i = 0; i < sizeAry ; i++)
{
squareSum += (ary[i] - average) * (ary[i] - average);
}
variance = squareSum/sizeAry;
fin.clear();
fin.seekg(0);
return variance;
}
//********************************************************************************
double stdDev(ifstream& fin)
{
double ary[5000];
int sizeAry = 0, ix = 0;; //need the size of the array :~
double variance = var(fin);//need the variance
double temp;
string word;
for(int i = 0; i < 1; i++)
{
fin >> word;
}
while (fin >> temp)//eats values to find out the # of things
{
sizeAry++;
ary[ix] = temp;
ix++;
}
fin.clear();
fin.seekg(0);
return sqrt(variance/sizeAry); //all stdDev does is return the square root of the variance divided by the number of values
}