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
|
#include <iostream>
#include <fstream>
#include <string>
#include<iomanip>
using namespace std;
int main()
{
double average;
double total;
string name, social, address, telephone, course1, course2, course3, header, studentID, comment1, comment2;
int n = 3;//, age, years; // n = number of students
const int NUMBER_OF_nonNumerical = 9;
const int NUMBER_OF_COURSES = 3;
const int NUMBER_OF_SCORES = 5;
const int THREE = 3;
const int TWO =2;
string student_nonNumeric1[n][NUMBER_OF_nonNumerical]; //store student string information
int student_numeric1 [THREE][TWO]; // store student age and years at Texas State
double courses_Numeric2 [n][NUMBER_OF_COURSES][NUMBER_OF_SCORES]; // store three students, three courses and five exams
char letterGrade [THREE][NUMBER_OF_COURSES]; // store letter grade of three students and three courses
//number of students
cout << "Enter how many students do you want to see:" << endl;
cin >> n;
// Validate the input while loop
while (n > 3 || n < 3 )
{
cout << "You should have exactly 3 students" << endl;
//get number of students again
cout << "Enter how many students do you want to see:";
cin >> n;
}
//Open Input and Output file
ifstream fin;
fin.open("Input.txt");
if (!fin) {
cout << "could not open file" << endl;
return -1;
}
//fin >> courses_Numeric2[i][j][k]; //scores
ofstream fout;
fout.open("Output.txt");
if (!fout) {
cout << "could not open file" << endl;
return -1;
}
for (int i = 0; i < n; i++)
{
getline(fin, student_nonNumeric1[i][0]); //headergetline(fin, student_nonNumeric1[i][3]);
getline(fin, student_nonNumeric1[i][1]); //name
getline(fin, student_nonNumeric1[i][2]); // Id number
getline(fin, student_nonNumeric1[i][3]); //address
// fin.ignore();
getline(fin, student_nonNumeric1[i][4]); //phone number
getline(fin, student_nonNumeric1[i][5]); //social security
fin >> student_numeric1[i][0]; // age
fin >> student_numeric1[i][1]; //years at texas state
fin.ignore();
for (int j = 0, z = 6; j < NUMBER_OF_COURSES; j++, z++)
{
getline(fin, student_nonNumeric1[i][z]);
total = 0;
for (int k = 0; k < NUMBER_OF_SCORES; k++)
{
fin >> courses_Numeric2[i][j][k]; //scores
total += courses_Numeric2[i][j][k];
// fout<<courses_Numeric2[i][j][k]; //scores
//average =+ courses_Numeric2[i][j][k] /5;
//average = (courses_Numeric2[0][0][0] + courses_Numeric2[0][0][1] + courses_Numeric2[0][0][2] + courses_Numeric2[0][0][3] + courses_Numeric2[0][0][4]) / 5;
}
average = total / 5;
courses_Numeric2[i][j][NUMBER_OF_SCORES] = average;
cout << average << endl;
fin.ignore();
}
//getline(fin, student_nonNumeric1[i][3]);
}
// fin >> courses_Numeric2[i][j][0]; //course 1
// fin >> courses_Numeric2[i][j][1]; //course 2
// fin >> courses_Numeric2[i][j][2]; //course 3
//for(i =0; i < NUMBER_OF_SCORES; i++)
fout << student_nonNumeric1[0][0] << endl;
fout << student_nonNumeric1[0][1] << endl;
fout << student_nonNumeric1[0][2] << endl;
fout << student_nonNumeric1[0][3] << endl;
fout << student_nonNumeric1[0][4] << endl;
fout << student_nonNumeric1[0][5] << endl;
fout << student_numeric1[0][0] << endl;
fout << student_numeric1[0][1] << endl;
fout << student_nonNumeric1[0][6] << endl;
for (int k = 0; k < NUMBER_OF_SCORES; k++)
{
fout << courses_Numeric2[0][0][k] << endl;
}
fout << student_nonNumeric1[0][7] << endl;
for (int k = 0; k < NUMBER_OF_SCORES; k++)
{
fout << courses_Numeric2[0][1][k]<< endl;
}
fout << student_nonNumeric1[0][8] << endl;
for (int k = 0; k < NUMBER_OF_SCORES; k++)
{
fout << courses_Numeric2[0][2][k]<< endl;
}
//fout << courses_Numeric2[0][0][NUMBER_OF_SCORES];//print average
fout << student_nonNumeric1[1][0] << endl;
fout << student_nonNumeric1[1][1] << endl;
fout << student_nonNumeric1[1][2] << endl;
fout << student_nonNumeric1[1][3] << endl;
fout << student_nonNumeric1[1][4] << endl;
fout << student_nonNumeric1[1][5] << endl;
fout << student_numeric1[1][0] << endl;
fout << student_numeric1[1][1] << endl;
fout << student_nonNumeric1[1][6] << endl;
for (int k = 0; k < NUMBER_OF_SCORES; k++)
{
fout << courses_Numeric2[1][1][k] << endl;
}
fout << student_nonNumeric1[1][7] << endl;
for (int k = 0; k < NUMBER_OF_SCORES; k++)
{
fout << courses_Numeric2[1][1][k]<< endl;
}
fout << student_nonNumeric1[1][8] << endl;
for (int k = 0; k < NUMBER_OF_SCORES; k++)
{
fout << courses_Numeric2[1][2][k]<< endl;
}
fout << student_nonNumeric1[2][0] << endl;
fout << student_nonNumeric1[2][1] << endl;
fout << student_nonNumeric1[2][2] << endl;
fout << student_nonNumeric1[2][3] << endl;
fout << student_nonNumeric1[2][4] << endl;
fout << student_nonNumeric1[2][5] << endl;
fout << student_numeric1[2][0] << endl;
fout << student_numeric1[2][1] << endl;
fout << student_nonNumeric1[2][6] << endl;
for (int k = 0; k < NUMBER_OF_SCORES; k++)
{
fout << courses_Numeric2[2][2][k] << endl;
}
fout << student_nonNumeric1[2][7] << endl;
for (int k = 0; k < NUMBER_OF_SCORES; k++)
{
fout << courses_Numeric2[02][1][k]<< endl;
}
fout << student_nonNumeric1[2][8] << endl;
for (int k = 0; k < NUMBER_OF_SCORES; k++)
{
fout << courses_Numeric2[2][2][k]<< endl;
}
return 0;
}
|