Gives Letter Grade

Ok so I have this code I made but now I have to add so it gives a final grade as an output depending on the "Test Average"

This is the rubric:
A 93-100
A- 90-92
B+ 75-89
B 83-86
B- 80-82
C+ 77-79
C 73-76
C- 70-72
D+ 67-69
D 60-66
F -60


And my code:
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
#include <iostream>
#include <ctime>
#include <fstream>
#include <string>
#include <vector>
using namespace std;

struct Grade
{
	std::string last,
		first,
		middle,
		absence;
	double test1,
		   test2,
		   test3;


	friend std::istream &operator>>(std::istream &in, Grade &s)
	{
		return in >> s.last >> s.first >> s.middle >> s.test1 >> s.test2 >> s.test3 >> s.absence;
	}
	friend std::ostream &operator<<(std::ostream &out, const Grade &s)
	{
		return out << "Name: "      << s.first << " "    << s.middle << " " << s.last      << std::endl
			<< "Test Average: "  << (s.test1+s.test2+s.test3)/3  << std::endl
			<< "Absences: "  << s.absence  << std::endl;
	}
};


void main ()
{
	std::vector<Grade> grades;

	{
		std::ifstream infile ("students.txt");
		Grade temp;
		while(infile >> temp)
		{
			grades.push_back(temp);
		}
	}

	for(size_t i = 0; i < grades.size(); ++i)
	{
		std::cout << grades[i] << std::endl;
	}
}



If any1 could get me started or show me an example that'd be awesome and much appreciated.
Start with int int main () and end with return 0;

Users like output, if they don't get output, they say your program is busted.

Of course I don't have a students.txt file but when I ran your code, I got 0 output.

so how about adding some output, if I don't have a file, and show a example of students.txt :) so I have something to look at when I do have a file.

closed account (18hRX9L8)
1
2
3
4
5
6
7
8
9
10
11
12
#include "genlib.h"
#include "simpio.h"
#include <stdio.h>

     if (Test Average>=93)
           printf ("A %.2f\n",Test Average);
     else if ((Test Average>89) && (Test Average <93))
           printf ("A- %.2f\n",Test Average);
     else if ((Test Average>84) && (Test Average <90))
           printf ("B+ %.2f\n",Test Average);

     //so on... 


Use if/else if/else statements.
Last edited on
Topic archived. No new replies allowed.