Initialize from a File

hello everyone, Probably a really basic question, but I am still begging here and can't seem to figure it out..

My teacher is asking me to create a program that takes students marks, converts them into percent and outputs a letter grade.. That part is all fine and dandy but the part I don't understand is that she says, "Initialize letter grades and weightings from a file" Now I know how to I/O from files, but correct me if I am wrong, you can't really input a range? like if the file said an A was from 80 to 90 percent.. Any help would be greatly appreciated. thanks
for example in the file we have:
1
2
3
4
5
6
A++ 110 110
A+ 100 109
A 90 99
B 80 89
C 70 79
D 60 69

using 'ifstream' just do :
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
#include <iostream>
#include <cstdlib>
#include <vector>
#include <cstring>
#include <fstream>

using namespace std;

struct Grade{     //a struct to store grades with min-max value for range
    string desc;
    int min;
    int max;
};

vector<Grade> grades;

int main(){
    ifstream input("ListGrades.txt",ios::in);
    Grade temp_grade;
    while(input.good())
        input >> temp_grade.desc >> temp_grade.min >> temp_grade.max;
        grades.insert(temp_grade);
    }
   //------- other code --------
}

//if the number of grades is known and the file contains all of them, you can use this variant

Grade grades[NUM_GRADES]

int main(){
    ifstream input("ListGrades.txt",ios::in);
    for(int i=0;i<NUM_GRADES;i++) input>>grades[i].desc>>grades[i].min>>grades[i].max;
    //-------- other code --------
}
Last edited on
Topic archived. No new replies allowed.