Parallel Arrays? Any help is appreciated

Create a program that will calculate the grade for a class full of students. There will be an input file called “Students.txt” that contains no more than 50 students,one per line. Each line contains the student ID(8 digits),4 test scores,and the final exam score.(All scores may have decimal numbers.)The grade is calculated as follows:grade=50%*test average+50%*final exam score The program should create an output file called “Grades.txt” which will contain summary information for each student,one per line.Each line should contain the student’s ID,4 test scores,final exam score,grade(with 2 decimal places),and letter grade based on a 10 point grading scale.

To be honest I'm not sure how to approach this problem.

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
#include <iostream>
#include <fstream>
#include <string>
using namespace std;


string studId[50];
double grade1[50], grade2[50], grade3[50], grade4[50];
double finalGrade;
char name[8];

int main ()
{
	int i = 0;
	double totalGrade;
	char dummy;
	ifstream infile;
	ofstream outfile;
	infile.open("Students.txt");
	outfile.open("Grades.txt");
	
	
	
	while(!infile.eof())
	{ 
	     for ( i = 0; i < 8; i++)
		{infile.get(name[i]);
		
		cout << name[i];}
		
		
	}
	return 0;
}

Am I even close?
Last edited on
Do you know anything about structures? It would prevent you from having to maintain parallel arrays, which is annoying for some.
I'm sorry but I do not. We were told to use arrays, but I wasn't sure if it would have to be a parallel array or not.
We were told to use arrays


WTF professors? Seriously limiting a student to arrays? Do they actually do this?! ARGH, that bugs me.
Sadly we were. Any ideas?
Have you written the "Students.txt" file?
Yes I have. Sorry, I meant to post it.

aaabbbcc 90 90 100 100 93
bbbbbbbb 80 90 70 100 90
ccccccccc 60 70 80 90 100


Anyone have any ideas?
Last edited on
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
 #include <iostream>
#include <fstream>
#include <string>
using namespace std;

string studId[50];
double grade1[50], grade2[50], grade3[50], grade4[50];
double finalExam[50];
char name[8];
char getGrade (double grade);
char letterGrade;

int main ()
{
	string name;
	int i = 0;
	 double grade[50];
	

	ifstream infile;
	ofstream outfile;
	infile.open("Students.txt");
	outfile.open("Grades.txt");
	
	
	
		
	// Find the id using no more than 8 characters.
	
	

	for (i = 0; i < 8; i++)
	{
		infile >> name[i];
		outfile << name[i];
	
	}
	outfile << " ";
	
	infile >> grade1[i] >> grade2[i] >> grade3[i] >> grade4[i] >> finalExam[i];
	
	// calculate the final grade using the given test scores
	
	grade[i] = (((grade1[i] + grade2[i] +grade3[i] + grade4[i]) / 4.00) * .50) + (.50 * finalExam[i]);
	
	outfile << grade1[i] << " " << grade2[i] << " "  << grade3[i] << " " << grade4[i] << " " <<finalExam[i] << " "
		<< grade[i] << " " <<  getGrade(grade[i]);
	
	
	
	
	
	
	
	
		
	
    return 0;
	}
// Calculate the letter grade using the calculations from above.
char getGrade(double grade)
{
if (grade >= 90)
	return 'A';
if (grade >= 80 && grade < 90)
	return 'B';
if (grade >= 70 && grade < 80)
	return 'C';
if (grade >= 60 && grade < 70)
	return 'D';
if (grade >= 50 && grade < 60)
    return 'F';
}


This is as close as I could get. I couldn't figure out how to make to work for more than one student.
Topic archived. No new replies allowed.