Reading in Names and grades

I am trying to read in a file and read out its contents to another.
I have 3 categories to fit the grades in English, History, and Math
some problems I have is displaying the actual letter grade after the name, aligning the the names, and putting the names in the correct category.
my output file becomes out of order and the names and information only shows on one category
Main.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
#include <fstream>
#include <iomanip>
#include <iostream>
#include <cstring>
#include <string>
#include <cctype>
#include "student.h"
using namespace std;

int main()
{
	ifstream in;
	ofstream out;
	char instream[40];
	char outstream[40];
	do
	{	
		cout << "Please enter the name of the file that you want open ending with (.txt)"<< endl;
		cin.getline(instream,40);
		in.open(instream);
		
		if (!in)
			cout << "Invalid name, Please re-enter."<< endl;
	}while (!in);
	
	do 
	{
	
		cout << "Please enter the name of the outputfile ending with (.txt))"<<endl;
		cin.getline(outstream,40);
		out.open(outstream);
		
		if (!out)
			cout << "Invalid name, Please re-enter."<< endl;
	}while(!out);

	int size;
	string l;
	string f;
	string c;
	double t1;
	double t2;
	double proj;
	double fe;
	double m;
	double a;
	double term;
	double qu[4];
	char finalM;
	char finalH;
	char finalE;
	int aa = 0;
	int bb = 0;
	int cc = 0;
	int dd = 0;
	int ff = 0;
	
	in >> size;
	
		
	Student **gradeList = new Student *[size];
	for (int i = 0; i < size; i++)
    	{
 		getline(in, l, ',');
                getline(in,f);
                in >> c;		    
        	if (c == "English")			
        	{
         		
            		in >> term;
            		in >> m;
            		in >> fe;
            		gradeList[i] = new English(l, f, c, term, m, fe);
			
           	}
        	
		if (c == "History")			
        	{
			in >> a;
			in >> proj;
			in >> m;
			in >> fe;
            		gradeList[i] = new History(f, l, c, a, proj, m, fe);
            
        	}
        	if (c == "Math")		
        	{
            		
		
			for (int p= 0; p < 5; p++)
				in >> qu[i];
			in >> t1;
			in >> t2;
			in >> fe;
            		gradeList[i] = new Math(f, l, c, qu, t1, t2, fe);
        	}
    	}
    
       
    	in.close();	
   
	for (int i = 0; i < size; i++)		
    	{
        if (gradeList[i]->Average() >= 90 && gradeList[i]->Average() <= 100)
        {
            	finalE = 'A';
		finalH = 'A';
		finalM = 'A';
		aa++;	
        }
        if (gradeList[i]->Average() >= 80 && gradeList[i]->Average() <= 89 )
        {
            	finalE = 'B';
               	finalH = 'B';
              	finalM = 'B';
		bb++;	
        }
        if (gradeList[i]->Average() >= 70 && gradeList[i]->Average() <= 79 )
        {
            	finalE = 'C';
                finalH = 'C';
                finalM = 'C';
		cc++;	
        }
        if (gradeList[i]->Average() >= 60 && gradeList[i]->Average() <= 69 )
        {
            	finalE = 'D';
                finalH = 'D';
                finalM = 'D';
		dd++;	
        }
        if (gradeList[i]->Average() >= 0 && gradeList[i]->Average() <= 59 )
        {
            	finalE = 'F';
                finalH = 'F';
                finalM = 'F';
		ff++;	
        }
	
    }
    
    	cout << "Processing Complete......" << endl;
	out << "Grade Summary" << endl;
	out << "English Class\n\n";
	out << "Student Name"<<"                              ";
	out << "Final Exam    ";
	out << "Final Avg    ";
	out << "Letter Grade\n";
	out << "-------------------------------------------------------------------------------------"<<endl << endl;
	for (int i = 0; i < size; i++)
    	{
		if(c == "English")
        	out <<gradeList[i]->GetFname() << " " << gradeList[i]->GetLname()<<"                                                 "<< gradeList[i]->Final() << "         "<<setprecision(2)<< gradeList[i]->Average() <<"    "<< finalE << endl;
    	}
	out << "Grade Summary" << endl;
        out << "History Class\n\n";
        out << "Student Name"<<"                              ";
        out << "Final Exam    ";
        out << "Final Avg    ";
        out << "Letter Grade\n";
        out << "-------------------------------------------------------------------------------------"<<endl << endl;
	for (int i = 0; i < size; i++)
        {
                if (c == "History")
                {
                        out <<gradeList[i]->GetFname() << " " << gradeList[i]->GetLname()<<"                                         "<< gradeList[i]->Final() << "         "<< setprecision(2)<<gradeList[i]->Average() <<"    "<< finalH <<endl;
		}
	}
	out << "Grade Summary" << endl;
        out << "Math Class\n\n";
        out << "Student Name"<<"                              ";
        out << "Final Exam    ";
        out << "Final Avg    ";
        out << "Letter Grade\n";
        out << "------------------------------------------------------------------------------------"<<endl<< endl;
	for (int i = 0; i < size; i++)
        {
                if (c == "Math")
                {
                        out <<gradeList[i]->GetFname() << " " << gradeList[i]->GetLname()<<"                                         "<< gradeList[i]->Final() << "        "<<setprecision(2)<< gradeList[i]->Average() <<"    "<<finalM <<endl;
		}
	}

	out << "\n\nOVERALL GRADE DISTRIBUTION:" << endl;
    	out << "A:  " << aa << endl;
    	out << "B:  " << bb << endl;
    	out << "C:  " << cc << endl;
    	out << "D:  " << dd << endl;
    	out << "F:  " << ff << endl;
		
	out.close();
	
	return 0;
}
Last edited on
input file
6
Bunny, Bugs
Math 90 86 80 95 100 99 96 93
Schmuckatelli, Joe
English 88 75 90
Dipwart, Marvin
History 95 76 72 88
Crack Corn, Jimmy
Math 44 58 23 76 50 59 77 68
Kirk, James T.
History 40 100 68 88
Lewinsky, Monica
English 60 72 78

output file
Grade Summary
English Class

Student Name Final Exam Final Avg Letter Grade
-------------------------------------------------------------------------------------

Bugs
Bunny 93 87 C

Schmuckatelli Joe 90 84 C
Marvin
Dipwart 88 80 C
Jimmy
Crack Corn 68 64 C
James T.
Kirk 88 81 C

Lewinsky Monica 78 71 C
Grade Summary
History Class

Student Name Final Exam Final Avg Letter Grade
-------------------------------------------------------------------------------------

Grade Summary
Math Class

Student Name Final Exam Final Avg Letter Grade
------------------------------------------------------------------------------------



OVERALL GRADE DISTRIBUTION:
A: 0
B: 4
C: 1
D: 1
F: 0
Topic archived. No new replies allowed.