Reading and Displaying from output file

Write your question here.

Sooooo, i'm outputting and calculating to a text file...
But now I need to display what has been written to the text file... Any help?

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
  //Computer Science 40
//Term Project: GPA Calculator
// Eric Haro


#include<iostream>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<cctype>
#include<fstream>

using namespace std;
// ====== Function Protype =======
int get_courseload();
string get_coursename(string *, int x);
void get_grade(char *, int x);
void get_units(int *, int x);
bool repeat(bool &);
int sum_units(int *, int x);
int sum_gradepts(int *, int *, char *, int);

int main()
{
	// ======== Main Functions ==========
	cout << "This program will calculate your semester's Grade Point Average:\n\n";
	string *course;
	char *grade;
	int *units, *gradepoints, courseload, unitSum = 0, gpSum = 0;
	bool again;
	const int SIZE = 20;
	int grdpts[SIZE];
	double gpa, gp, u;
	ofstream ofile("GPA.txt");
	ifstream ifile;

	//do while loop to prompt user until user is done
	//wanting to determine her or his grade point average
	do
	{
		// Prompts user for number of classes
		courseload = get_courseload();

		cout << endl << endl;

		// Function Calls
		course = new string[courseload];
		grade = new char[courseload];
		units = new int[courseload];
		gradepoints = new int[courseload];

		//for loop to repeat course names, grades and numbers of units
		for (int t = 0; t < courseload; t++)
		{
			cin.ignore(20, '\n');
			cout << t + 1 << ". ";
			// Function calls
			course[t] = get_coursename(course, t);
			get_grade(grade, t);
			cin.ignore(20, '\n');
			grade[t] = toupper(grade[t]);
			get_units(units, t);
			unitSum += sum_units(units, t);
			gpSum += sum_gradepts(gradepoints, units, grade, t);
			grdpts[t] = sum_gradepts(gradepoints, units, grade, t);
			cout << endl << endl;
		}
		// Calculates the GPA
		u = unitSum;
		gp = gpSum;
		gpa = gp / u;

		// Displays output to text file
		ofile << endl << endl;
		ofile << "Course               Grade          Units\n";
		ofile << "-----------------------------------------\n";
		for (int v = 0; v < courseload; v++)
		{

			ofile << left << setw(23) << course[v];
			ofile << setw(15) << grade[v];
			ofile << setw(10) << units[v] << endl;
		}
		ofile << endl << endl;
		ofile << "The total points are " << gp << endl;
		ofile << "The total units are " << u << endl;
		ofile << "Your GPA for the semester is " << setprecision(2) << setw(3) << gpa << endl << endl;
		
		// Run program again?
		repeat(again);

		// End of Loop
	} while (again);
	delete[] course;
	delete[] grade;
	delete[] units;
	delete[] gradepoints;
	
	system("pause");
	return 0;
}

int get_courseload()
{
	int x;
	cout << "How many classes are you enrolled to this semester? ";
	cin >> x;
	return x;
}
// ========= Function Definitions ==========
string get_coursename(string *h, int x)
{
	cout << "What is the name of the class? ";
	getline(cin, h[x]);
	return h[x];
}

void get_grade(char *x, int y)
{
	cout << "What is your grade for this class? ";
	x[y] = cin.get();
}

void get_units(int *x, int y)
{
	cout << "How many units is this class worth? ";
	cin >> x[y];
}

int sum_units(int *y, int x)
{
	int g = y[x];
	return g;
}

int sum_gradepts(int *w, int *x, char *y, int z)
{
	int c;
	if (y[z] == 'A')
	{
		w[z] = 4;
	}
	else if (y[z] == 'B')
	{
		w[z] = 3;
	}
	else if (y[z] == 'C')
	{
		w[z] = 2;
	}
	else if (y[z] == 'D')
	{
		w[z] = 1;
	}
	else
	{
		w[z] = 0;
	}

	c = (w[z]) * (x[z]);
	return c;
}
bool repeat(bool &yes)
{
	char x;
	cout << "Do you wish to calculate your grade point average for another semester?\n";
	cout << "(Y/N) ";
	cin >> x;
	cin.ignore();
	if (x == 'y' || x == 'Y')
		yes = true;
	else
		yes = false;
	return yes;
}

Topic archived. No new replies allowed.