Hey, thanks for the help so far but it does not seem to have fixed the program. Below is an updated version of my program. I tried to change everything that was suggested.
Also, in regards to the logic behind my if statement, I have to check for variables between 1 and 10 so it has to not only b less than 10 but also greater than one to fit into that category. The teacher wants a list of how many numbers are between 1 and 10, 11 and 20, and so forth.
Also if it helps, the LabData.txt file I am accessing is in the project folder and looks like this
14 4 78 45 23 99 56 54 7 19 37 71 20 82 33 59 53 77 55 1
71 72 25 54 61 78 53 45 60 56 54 70 76 60 69 32 45 48 68 36
16 37 58 44 37 42 53 65 13 54 16 30 43 63 62 37 75 59 23 67
41 42 55 34 60 62 21 72 42 36 53 66 47 46 56 44 73 86 49 63
64 70 68 24 45 49 60 57 55 70 45 35 41 37 44 74 45 60 67 85
12 48 69 53 11 44 59 29 22 52 93 42 58 74 66 84 61 35 42 41
41 63 79 53 54 69 33 36 54 44 64 52 44 33 7 51 59 61 54 27
62 70 56 52 34 61 94 33 28 61 34 41 10 58 53 43 51 56 69 68
51 80 62 68 71 42 46 52 50 33 59 59 66 45 69 22 57 68 58 74
60 69 36 57 74 36 82 60 43 70 32 68 51 45 73 69 23 49 51 48
51 26 49 52 65 41 34 58 43 5 92 56 83 52 40 58 88 47 60 60
43 30 57 54 61 79 65 57 78 46 73 59 56 56 34 44 31 41 87 38
54 61 80 52 41 67 39 52 55 51 21 24 32 45 40 64 39 59 68 67
52 48 6 38 53 42 60 40 39 15 65 57 63 50 66 32 47 75 43 75
2 66 83 29 50 64 62 51 77 43 33 72 19 56 88 67 60 26 67 66
49 62 53 54 27 56 57 40 54 58 45 64 43 39 47 66 76 31 65 80
91 38 71 53 47 47 35 52 71 46 56 57 68 42 31 92 58 77 41 37
50 39 53 55 72 39 94 76 62 32 64 46 51 78 80 25 63 75 79 70
50 60 58 84 40 59 51 82 14 63 52 61 53 45 91 42 81 44 76 78
6 45 63 38 85 31 61 93 58 46 49 64 83 79 28 86 77 69 87 37
P.s. just found out how to make the code appear as code, sorry for the double post
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 224 225 226 227 228 229 230 231 232 233 234 235 236
|
//This program will read a file and provide output and information based on the data
# include <iostream>
# include <cmath>
# include <fstream>
# include <iomanip>
using namespace std;
//Opens the file under variable name Write and Identifies the file that is being read from
ofstream Write("temp.txt",ios::out);
ifstream Read("LabData.txt", ios::in);
void Header(); //Prototype for header function
int Maximum (int info[], int); //Prototype for Maximum function
int Minimum (int num[],int); //Prototype for Minimum function
void Distribution(int val[],int); //Prototype for Distribution function
int Mean(int table[],int); //Prototype for Mean function
double Deviation(int set[], int); //Prototype for Standard Deviation function
void sort(int[], int); //Prototype for Sort function
const int Max = 400; //Size of the array
int main()
{
Header();
int data[Max];
int number;
int lines = 1;
cout << "This program will read from a file, which is titled \"LabData.txt\"\n\n";
cout << "Then store the information to \"temp.txt\" along with\n\n";
cout << "The mean, minimum, maximum, distribution of dat and standard deviation\n\n";
for(int scale = 0; scale < Max; scale++)
Read >> data[scale];
for(number =0; number < Max; number++)
{
if(lines <= 20)
{
Write << data[number] << setw(4);
++lines;
}
else
{
lines = 1;
Write << "\n";
}
}
Write << "The Mean is " << Mean(data, Max);
Write << "\n\nThe Minimum value is " << Minimum(data, Max);
Write << "\n\nThe Maximum Value is " << Maximum(data, Max);
Distribution(data, Max);
Write << "\n\nThe Standard Deviation is " << Deviation(data, Max);
sort(data, Max);
for(number =0; number < Max; number++)
{
if(lines <= 20)
{
Write << data[number] << setw(4);
++lines;
}
else
{
lines = 1;
Write << "\n";
}
}
return 0;
}
void Header() //Header Function
{
//Heading at top of output and sets precision to 2 decimal places
Write << "**************************************************************\n\n"
<< setw(5) <<"Luke Shaw and Cody Dickerman" << setw(36) << "Array\n\n"
<< setw(5) <<"Fall Semester" << setw(52) << "2012 \n\n"
<< setw(5) <<"Due Date" << setw(57) << "December 4,2012 \n\n"
<< setw(5) <<"Date Executed" << setw(52) << "November 27,2012 \n\n"
<< "**************************************************************\n\n";
} //End Header Function
int Maximum (int info[], int Max)
{
int Number;
Number = info[0];
for (int counter = 1; counter < Max; counter++)
if (info[counter] > Number)
Number = info[counter];
return Number;
}
int Minimum (int num[], int Max)
{
int Value;
int count;
Value = num[399];
for(count = (Max - 1); count >= 0; count--);
if (num[count] < Value)
Value = num[count];
return Value;
}
void Distribution(int val[], int Max)
{
int val1 = 0;
int val2 = 0;
int val3 = 0;
int val4 = 0;
int val5 = 0;
int val6 = 0;
int val7 = 0;
int val8 = 0;
int val9 = 0;
int val10 = 0;
for( int var = 0; var < Max; var++)
{
if (1 <= val[var] && val[var] <= 10)
++ val1;
else if (11 <= val[var] && val[var] <= 20)
++ val2;
else if (21 <= val[var] && val[var] <= 30)
++ val3;
else if (31 <= val[var] && val[var] <= 40)
++ val4;
else if (41 <= val[var] && val[var] <= 50)
++ val5;
else if (51 <= val[var] && val[var] <= 60)
++ val6;
else if (61 <= val[var] && val[var] <= 70)
++ val7;
else if (71 <= val[var] && val[var] <= 80)
++ val8;
else if (81 <= val[var] && val[var] <= 90)
++ val9;
else if (91 <= val[var] && val[var] <= 100)
++ val10;
}
Write << "\n\n1 <= " << val1 << " <= 10\n\n";
Write << "11 <= " << val2 << " <= 20\n\n";
Write << "21 <= " << val3 << " <= 30\n\n";
Write << "31 <= " << val4 << " <= 40\n\n";
Write << "41 <= " << val5 << " <= 50\n\n";
Write << "51 <= " << val6 << " <= 60\n\n";
Write << "61 <= " << val7 << " <= 70\n\n";
Write << "71 <= " << val8 << " <= 80\n\n";
Write << "81 <= " << val9 << " <= 90\n\n";
Write << "91 <= " << val10 << " <= 100\n\n";
}
int Mean(int table[], int Max)
{
int average;
double total = 0;
int sum = 0;
for (average = 0; average < Max; average++)
sum += table[average];
return (sum / Max);
}
double Deviation(int set[], int Max)
{
double value = 0.;
for (int dev = 0; dev < Max; dev++)
{
value = set[dev] - Mean(set, Max);
value = pow(value,2.);
value = +value;
return sqrt((value / Max));
}
}
void sort(int data[], int Max)
{
int position;
int smallest;
for(int variable = 0; variable < Max; variable++)
{
position = variable;
smallest = data[position];
for(int variable1 = variable + 1; variable1 < (Max + 1) ; ++variable)
{
if (data[variable1] < smallest)
{
position = variable1;
smallest = data[position];
}
data[position] = data[variable];
data[variable] = smallest;
}
}
}
|