Help converting inputs.txt to outputs.txt

Pages: 12345... 7
should i get rid of grade = "A+" and make my CourseGradePercentage a string and assign it to all the grades? will make the equation calculate?
closed account (48T7M4Gy)
No, I'd stay with that because it has no effect on the grade average
ok ya it didnt work lol... flippin A .. i know its probably something simple too i just cant see it. im not familiar enough with code yet. key word. yet.
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
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

const int NHOMEWORK = 7 ;

std::istream& read_hw_scores( std::istream& stm, double hw[NHOMEWORK] )
{
   for( int i = 0 ; i < NHOMEWORK ; ++i ) stm >> hw[i] ;
   return stm ;
}

std::string score_to_grade( double score )
{
    if( score > 100 ) return "F " ;

    else if( score > 96 ) return "A+" ;
    else if( score > 92 ) return "A " ;
    else if( score > 89 ) return "A-" ;

    else if( score > 86 ) return "B+" ;
    else if( score > 82 ) return "B " ;
    else if( score > 79 ) return "B-" ;

    else if( score > 76 ) return "C+" ;
    else if( score > 72 ) return "C " ;
    else if( score > 69 ) return "C-" ;

    else if( score > 59 ) return "D " ;

    else return "F " ;
}



int main()
{
    {
        // create a test input file
        std::ofstream( "sampleGrades3.txt" ) <<
R"(137
1 9 98 79 100 100 85 0 100 24 24 32
2 8 105 105 0 0 0 0 0 23 0 0
3 24 105 95 105 100 96 98 97 25 25 37
4 25 98.7 105 105 105 103.95 104 105 22 21 39
5 21 94.5 98 92 95 90 90 90.3 20 15 30
6 24 95.55 100 99 100 92 60 105 24 21 32
7 17 90 95 82 90.3 68 99 60 23 14 25
8 25 90 102.9 98.7 95.55 100 72 105 21 23 35
9 23 80 93 95 53 78 68 100 19 18 22
10 24 83 96 100 96 55 84 100 19 14 28)" ;
    }

    std::ifstream fin( "sampleGrades3.txt" );
    std::ofstream fout( "OutputGrades3.txt" );
    // TODO: verify that files have been opened

    {
        // throw the first liney
        std::string line ;
        std::getline( fin, line ) ;
    }

    int id ;
    double attendance, exam1, exam2, final_exam;
    double hw[NHOMEWORK] ;

    int num_A = 0, num_B = 0, num_C = 0, num_D = 0, num_F = 0 ;

    fout << std::fixed << std::setprecision(2) ;
    std::cout << std::fixed << std::setprecision(2) ;

    while( fin >> id >> attendance && read_hw_scores( fin, hw ) && fin >> exam1 >> exam2 >> final_exam )
    {
        double hw_total = 0 ;
        for( double s : hw ) hw_total += s ;

        const double grade_percent = attendance * 10.0/25 + hw_total * 35.0/700 + (exam1+exam2) * 15.0/25 + final_exam * 25.0/40 ;
        const std::string grade = score_to_grade(grade_percent) ;

        if( grade[0] == 'A' ) ++num_A ;
        else if( grade[0] == 'B' ) ++num_B ;
        else if( grade[0] == 'C' ) ++num_C ;
        else if( grade[0] == 'D' ) ++num_D ;
        else ++num_F ;

        // TODO: write record to output file
        fout << std::setw(3) << id << '.' << std::setw(6) << grade_percent << "% " << grade << '\n' ;
        std::cout << std::setw(3) << id << '.' << std::setw(6) << grade_percent << "% " << grade << '\n' ;
    }

    std::cout << "\nA - " <<  num_A << "\nB - " <<  num_B << "\nC - " <<  num_C
              << "\nD - " <<  num_D << "\nF - " <<  num_F << '\n' ;
}

http://coliru.stacked-crooked.com/a/d867fce0a1f8f32a
Last edited on
closed account (48T7M4Gy)
CourseGradePercentage =

10% of (Attendance marked out of 25) -> 10 marks maximum
35% of (hw1 + hw2 + hw3 + hw4 + hw5 + hw6 + hw7) marked out of 700 -> 35 max
15% of exam1 marked out of 25 -> 15 max
15% of exam2 marked out of 25 -> 15 max
25% finalExam marked out of 40 -> 25 max

This is why everybody gets an F. Why? because instead of %'s you are using .10, .15 etc

Last edited on
closed account (48T7M4Gy)
that's 100 not 100 factorial

actually I'm wrong it's deeper than that but on the right track

I was wrong, in fact it has turned out I was right.
Last edited on
i figured it out. i made coursegradepercentage a double. but it still is F for all
here is 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
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
#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
    ifstream sampleGrades4("sampleGrades4.txt");
    ofstream outputGrades("outputgrades.txt");
    
    string firstLine;
    int TotalStudents;
    
    double ID = 0.0, Attendance, hw1, hw2, hw3, hw4, hw5, hw6, hw7, exam1, exam2, finalExam,CourseGradePercentage;
    
    float LetterGrade;
    
    int NumA = 0;
    int NumB = 0;
    int NumC = 0;
    int NumD = 0;
    int NumF = 0;
    
    string Grade = "";
    
    if (sampleGrades4.is_open())
    {
        getline(sampleGrades4, firstLine);
        
        sampleGrades4 >> TotalStudents;
        cout << "No. of students: " << TotalStudents << endl;
        
        cout << firstLine << endl;
        cout << "ID" << setw(18) << "Course Grade" << setw(16) << "Letter Grade" << endl;
        outputGrades << "ID" << setw(18) << "  Course Grade" << setw(16) << "Letter Grade" << endl;
        
        while ( !sampleGrades4.eof() )
        {
            sampleGrades4 >> ID >> Attendance >> hw1 >> hw2 >> hw3 >> hw4 >> hw5 >> hw6 >> hw7 >> exam1 >> exam2 >> finalExam;
           
            CourseGradePercentage = Attendance*0.10 / 25 + (hw1 + hw2 + hw3 + hw4 + hw5 + hw6 + hw7)*0.35 / 700 + exam1*0.15 / 25 + exam2*0.15 / 25 + finalExam * 0.25 / 40;
CourseGradePercentage = CourseGradePercentage*100;
            
            
            cout << ID << setw(14) << CourseGradePercentage;
            outputGrades << ID << setw(14) << CourseGradePercentage;
            
            if (LetterGrade >= 97 && LetterGrade <= 100)
            {
                Grade = " A+ ";
                NumA++;
            }
            else if (LetterGrade >= 93 && LetterGrade < 97)
            {
                Grade = " A ";
                NumA++;
            }
            else if (LetterGrade >= 90 && LetterGrade < 93)
            {
                Grade = " A- ";
                NumA++;
            }
            else if (LetterGrade >= 87 && LetterGrade < 90)
            {
                Grade = " B+ ";
                NumB++;
            }
            else if (LetterGrade >= 83 && LetterGrade < 87)
            {
                Grade = " B ";
                NumB++;
            }
            else if (LetterGrade >= 80 && LetterGrade < 83)
            {
                Grade = " B- ";
                NumB++;
            }
            else if (LetterGrade >= 77 && LetterGrade < 80)
            {
                Grade = " C+ ";
                NumC++;
            }
            else if (LetterGrade >= 73 && LetterGrade < 77)
            {
                Grade = " C ";
                NumC++;
            }
            else if (LetterGrade >= 70 && LetterGrade < 73)
            {
                Grade = " C- ";
                NumC++;
            }
            else if (LetterGrade >= 60 && LetterGrade < 70)
            {
                Grade = " D ";
                NumD++;
            }
            else if (LetterGrade >= 0 && LetterGrade < 60)
            {
                Grade = " F ";
                NumF++;
            }
            cout << setw(15) << Grade << endl;
            outputGrades << setw(15) << Grade << endl;
        
            
        }
        
        
        outputGrades << setw(10) << ID << setw(14) << CourseGradePercentage << setw(14) << LetterGrade << endl;
        outputGrades << endl;
        outputGrades << "The # of A's: " << NumA << endl;
        outputGrades << "The # of B's: " << NumB << endl;
        outputGrades << "The # of C's: " << NumC << endl;
        outputGrades << "The # of D's: " << NumC << endl;
        outputGrades << "The # of F's: " << NumF << endl;
        
        sampleGrades4.close();
        outputGrades.close();
    }
    else
        cout << "Unable to open file";
    
    return 0;
}

Last edited on
when i add this to line i just want the percentage 2 decimal places but its doing it to the id too.. ill try and figure it out. I hate the letter F by the way..

1
2
3
cout << ID; 
cout << fixed << setprecision(2) << setw(14) << CourseGradePercentage;
outputGrades << ID << setw(14) << CourseGradePercentage;
Last edited on
closed account (48T7M4Gy)
what are the figures for each . are they percentages or the raw score?
o my god your right !! when i calculated student 1 i got a CourseGradePercentage of 73.8% WTH !
thanks JL. that code goes way over my head though. this code that i have is more of how i've learned in my class. My teacher is a stickler for that stuff. your the man though
closed account (48T7M4Gy)
So now the trick is to get that bit right. The obvious question is forgrtting about everyything else - What's the right formula?
dang man im trying to get 73.8% for the first one but my equation looks completely right... hmmm
i tried dividing C.G.P. by 137 as the total students.. that didnt work lol
i did notice that there were negative numbers in my text file that my teacher gave us... does that have something to do with it?
this formula looks so right to me though :/

CourseGradePercentage = Attendance*10.0 / 25 + (hw1 + hw2 + hw3 + hw4 + hw5 + hw6 + hw7)*35.0 / 700 + (exam1 + exam2)*30.0 / 50 + finalExam * 25.0 / 40;
Last edited on
closed account (48T7M4Gy)
I doubt it.
I'd just use the sample data we have so far. Maybe you just put a validation routine later on so that -ve values throw up an error message

Basically for that formula to make sense you have to know what each assessment item is out of.

Then it's just a weighted total for each student that then goes into the alphabetic grading filter. Without knowing the maximum score on each item we are doing it into the wind phil


so should i divide hw1-7 by 100 in my double and my 2 exams by 25 and my final by 40 ?

or like this
1
2
3
4
5
6
7
8
9
10
hw1 = hw1*35/100;
    hw2 = hw2*35/100;
    hw3 = hw3*35/100;
    hw4 = hw4*35/100;
    hw5 = hw5*35/100;
    hw6 = hw6*35/100;
    hw7 = hw7*35/100;
    exam1 = exam1*15/25;
    exam2 = exam2*15/25;
    finalExam = finalExam*25/40:
Last edited on
closed account (48T7M4Gy)
ID	  Course Grade	Letter Grade
1	80.5	 B- 
2	27.5	 F 
3	97.525	 A+ 
4	96.5075	 A 
5	80.64	 B- 
6	89.1775	 B+ 
7	73.84	 C 
8	91.4825	 A- 
9	73.5	 C 
10	77.6	 C+ 

The # of A's: 3
The # of B's: 3
The # of C's: 3
The # of D's: 3
The # of F's: 1



HA HA HA I know how it's done!!!!!!!!!!!!!!!!!!!!!!

nvm ugh that didnt change anything
Pages: 12345... 7