I'm really confused. We are supposed to read in a students id, their 2 test scores and then their 7 homework scores. Then im supposed to be able to use those values to calculate their average test score and homework score and figure out their final grade. What I don't understand is how these arrays work. I don't get how I would just use student 1's test score 1 and 2 and not everyone else's. Plus my code isn't running correctly. This is what the file looks like:
123456789 77.2 88.3 22 28 35 45 33 35 40
234567890 97.5 90 25 30 38 48 34 35 50
345678901 82.4 77.5 22.5 27 35.5 44 35 33 48
456789012 65.5 67 20 25 28 40 27 25 35
567890123 79.5 82 25 30 32 47 30 33 46
678901234 90 86.5 25 30 40 46 34 35 50
789012345 77 82.2 25 30 36 46 33 32.5 47
890123456 67.7 72.5 23 28 35 44 30 30 44
901234567 76.5 83.4 25 29 38 49 35 35 49
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
|
#include <iostream>
#include <conio.h>
#include <fstream>
#include <string>
using namespace std;
struct SStudent
{
int id;
double test1, test2, hw [7];
};
int getInput(SStudent [], int);
void process(SStudent [], int);
void display(const SStudent[], int);
int main()
{
SStudent length[30];
int i;
getInput(length, 30);
_getch();
}
int getInput(SStudent students[], int size)
{
ifstream inFile;
inFile.open("scores.txt");
if(!inFile)
{
cout << "Can't open input file\n";
_getch();
exit(1);
}
for(int i = 0; i < size; ++i)
{
inFile >> students[i].id >> students[i].test1 >> students[i].test2
>> students[i].hw[1] >> students[i].hw[1] >> students[i].hw[1]
>> students[i].hw[1] >> students[i].hw[1] >> students[i].hw[1]
>> students[i].hw[1];
}
}
|