Using arrays and struct variables

Hello!
I am writing a program that should output to a file each student’s name followed by their test score and the relevant grade.

The problem i am having is outputting my data.
My program should output each student’s last name followed by a comma, followed by a space, followed by the first name. Next the fisrt name, output the score and grade on the same line. I need to use the left modifier, along with setw().
Here is what my input file is

Queen Louis 80
Jennifer Whatever 75
John Mark 65




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
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

struct studentType
{
	string s_first_Name; // First Name
	string s_last_Name;  // Last Name
	int score;           // test Score
	char grade;          // grade
};

studentType students[20];

void getData(studentType sList[], int listSize); //would i get rid of this line?
void getGrade(studentType sList[], int listSize);
void result(const studentType sList[], int listSize); //outstream here??

int StuRead(ifstream& indata, studentType students[])
{
	int x = 0;

	for (x = 0; !indata.eof() && x < 20; x++)
	{

		indata >> students[x].s_last_Name 
			>> students[x].s_first_Name
			>> students[x].score;
// SHOULD THIS BE LOCATED HERE OR IM THINKING IN MY MAIN?
		// output << left << setw(6) << "s_last_Name" << right 
		// << setw(6) << "s_first_Name" << setw(6)
		// << " Garde" << endl;
		// output << "\n";



	}
	return x;
}
char AssignGrade(char LetterGrade, studentType students[])
{
	char grade = 0;

	if (LetterGrade > 90)
		grade = 'A';
	else if (LetterGrade > 80)
		grade = 'B';
	else if (LetterGrade > 70)
		grade = 'C';
	else if (LetterGrade > 60)
		grade = 'D';
	else if (LetterGrade < 59)
		grade = 'F';

	return grade;
}



int main()
{
	ifstream inFile;
	inFile.open("Last_Lab.txt");
	
	ofstream outFile;
	outFile.open("studentResults.txt");
	
	system("PAUSE");
	return 0;
}
Last edited on
Consider this design:
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
int StuRead(ifstream& indata, studentType students[], int size)
{
	int x = 0;

	for (x = 0; !indata.eof() && x < size; x++)
	{

		indata >> students[x].s_last_Name 
			>> students[x].s_first_Name
			>> students[x].score;



	}
	return x;
}
void AssignGrade(studentType students[], int size)
{
	for (int x = 0; outdata && x < size; x++)
	{
		if (students[x].score > 90)
			students[x].grade = 'A';
		else ...

	}
}

void StuWrite(ostream& output, studentType students[], int size)
{
	for (int x = 0; outdata && x < size; x++)
	{

		output << left << setw(6) << students[x].s_last_Name << right 
		// << setw(6) << "s_first_Name" << setw(6)
		// << " Garde" << endl;
		// output << "\n";
	}
}

int main()
{
	ifstream inFile;
	inFile.open("Last_Lab.txt");
	
	ofstream outFile;
	outFile.open("studentResults.txt");

	int size = StuRead(inFile, students, 20)
	AssignGrade(students, size)
	StuWrite(outFile, students, size)
	
	system("PAUSE");
	return 0;
}
its not working either
Bummer!
Topic archived. No new replies allowed.