Final project help

Pages: 12
Line 61/62 was displays that i forgot to take out. Out now. Sorry here you go. This is the format it should be in. And yea.. bad naming. you mean like the .txt file I used to read from in my program, that?
666 Dunn, Bob
A C D C A C D B C A
88 Hall, Bill
A C D A B C D B C A
333 Land, Chris
C D B C A B D B A A
998 Miles, Sue
A C D B B B D B C A
55 Hill, Nathan
A C B A B D D B C A
66 Rowe, Steve
A C D C A A D B C A
44 Ball, Lee
A B D C A C D B C A
22 Smith, Mary
A C D B A C D B C A
111 Jones, Paul
A C D C A C D B C A
878 Adams, Jerry
A C D C A B D B C A
closed account (48T7M4Gy)
OK I'll give it a go. I'll get back shortly.

you mean like the .txt file I used to read from in my program, that?

No i'm talking about the two arrays in your struct. They are nearly the same :(
closed account (48T7M4Gy)
Please enter the answer key.
Answer 1: A
Answer 2: C
Answer 3: D
Answer 4: C
Answer 5: A
Answer 6: C
Answer 7: D
Answer 8: B
Answer 9: C
Answer 10: A
Student ID   Student Name   Answers Total Pts   Average   Letter Grade
All Students
       666      Dunn,, Bob       A C D C A C D B C A        50       100         A
        88      Hall,, Bill      A C D A B C D B C A        40        80         B
       333      Land,, Chris     C D B C A B D B A A        25        50         F
       998      Miles,, Sue      A C D B B B D B C A        35        70         C
        55      Hill,, Nathan    A C B A B D D B C A        30        60         D
        66      Rowe,, Steve     A C D C A A D B C A        45        90         A
        44      Ball,, Lee       A B D C A C D B C A        45        90         A
        22      Smith,, Mary     A C D B A C D B C A        45        90         A
       111      Jones,, Paul     A C D C A C D B C A        50       100         A
       878      Adams,, Jerry    A C D C A B D B C A        45        90         A


Students Admitted to the Graduate Program
       666      Dunn,, Bob       A C D C A C D B C A        50       100         A
        88      Hall,, Bill      A C D A B C D B C A        40        80         B
        66      Rowe,, Steve     A C D C A A D B C A        45        90         A
        44      Ball,, Lee       A B D C A C D B C A        45        90         A
        22      Smith,, Mary     A C D B A C D B C A        45        90         A
       111      Jones,, Paul     A C D C A C D B C A        50       100         A
       878      Adams,, Jerry    A C D C A B D B C A        45        90         A


Students with conditional admission
       998      Miles,, Sue      A C D B B B D B C A        35        70         C


Students Not Allowed Admission:
       333      Land,, Chris     C D B C A B D B A A        25        50         F
        55      Hill,, Nathan    A C B A B D D B C A        30        60         D
Press any key to continue . . .
Last edited on
closed account (48T7M4Gy)
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
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>

using namespace std;

struct StudentRecord
{
	string first;
	string last;
	int ID;
	char Answer[10];
	int score;
	double average;
	char letter_grade;
	string name;
};

int getInfo(StudentRecord[], int);
void enterKey(char key[], int);

void calculateScore(char[], int[], int, StudentRecord[], int);
void sortName(StudentRecord[], int);
void displayResults(StudentRecord[], int);
void displayStudentRecord(StudentRecord);

int main()
{
	const int sLimit = 10;
	const int kLimit = 10;

	char key[kLimit];
	enterKey(key, kLimit);

	int marks[kLimit] = { 5,5,5,5,5,5,5,5,5,5 };

	StudentRecord stu[sLimit];
	int No_studs = getInfo(stu, sLimit);
	calculateScore(key, marks, kLimit, stu, No_studs);

	displayResults(stu, No_studs);
	sortName(stu, No_studs);

	return 0;
}

int getInfo(StudentRecord stu[], int aLimit)
{
	int count = 0;

	ifstream inFile;
	inFile.open("students.txt");

	if (!inFile)
		cout << "\n\n**** ERROR OPENING FILE. ******\n" << endl;
	else
	{
		count = 0;
		while (inFile >> stu[count].ID && count < aLimit)
		{
			inFile >> stu[count].last;
			inFile >> stu[count].first;

			for (int index = 0; index < 10; index++)
				inFile >> stu[count].Answer[index];
			count++;
		}
	}
	return count;
}

void enterKey(char key[], int aLimit)
{
	cout << "Please enter the answer key." << endl;
	for (int index = 0; index < aLimit; index++)
	{
		cout << "Answer " << index + 1 << ": ";
		cin >> key[index];
	}

}

void calculateScore(char key[], int points[], int noPoints, StudentRecord  stu[], int aLimit)
{
	for (int index = 0; index < aLimit; index++)
	{
		stu[index].score = 0;
		for (int p = 0; p < noPoints; p++)
		{
			if (stu[index].Answer[p] == key[p])
				stu[index].score += points[p];
		}

		stu[index].average = stu[index].score * 2;

		if (stu[index].average >= 90)
			stu[index].letter_grade = 'A';
		else if (stu[index].average >= 80)
			stu[index].letter_grade = 'B';
		else if (stu[index].average >= 70)
			stu[index].letter_grade = 'C';
		else if (stu[index].average >= 60)
			stu[index].letter_grade = 'D';
		else
			stu[index].letter_grade = 'F';
	}
}

void sortName(StudentRecord stu[], int No_studs)
{
	bool swap = true;
	int j = 0;

	StudentRecord temp;

	while (swap)
	{
		swap = false;
		j++;
		for (int i = 0; i < No_studs - j; i++)
		{

			if (stu[i].name.compare(stu[i + 1].name.c_str()) > 0)
			{
				temp.name = stu[i].name;
				stu[i].name = stu[i + 1].name;
				stu[i + 1].name = temp.name;
				swap = true;
			}
		}
	}
}

void displayHeading()
{
	cout << setw(10) << "Student ID";
	cout << setw(15) << "Student Name";
	cout << setw(10) << "Answers";
	cout << setw(10) << "Total Pts";
	cout << setw(10) << "Average";
	cout << setw(15) << "Letter Grade";
	cout << endl;
}

void displayResults(StudentRecord stu[], int aLimit)
{
	displayHeading();

	cout << "All Students" << endl;
	for (int index = 0; index < aLimit; index++)
		displayStudentRecord(stu[index]);

	cout << "\n\nStudents Admitted to the Graduate Program" << endl;
	for (int i = 0; i < aLimit; i++)
	{
		if (stu[i].letter_grade == 'A' || stu[i].letter_grade == 'B')
			displayStudentRecord(stu[i]);
	}
	
	cout << "\n\nStudents with conditional admission" << endl;
	for (int i = 0; i < aLimit; i++)
	{
		if (stu[i].letter_grade == 'C')
			displayStudentRecord(stu[i]);
	}
	
	cout << "\n\nStudents Not Allowed Admission: " << endl;
	for (int i = 0; i < aLimit; i++)
	{
		if (stu[i].letter_grade == 'D' || stu[i].letter_grade == 'F')
			displayStudentRecord(stu[i]);
	}
}

void displayStudentRecord(StudentRecord aStudent)
{
	cout << setw(10) << aStudent.ID;
	cout << '\t' << aStudent.last << ", "<< aStudent.first << '\t';
	for (int y = 0; y < 10; y++)
		cout << setw(2) << aStudent.Answer[y] << "";

	cout << setw(10) << aStudent.score;
	cout << setw(10) << aStudent.average;
	cout << setw(10) << aStudent.letter_grade;
	cout << endl;
}
Last edited on
Topic archived. No new replies allowed.
Pages: 12