Help converting inputs.txt to outputs.txt

Pages: 1234567
closed account (48T7M4Gy)
LetterGrade = 100*(Attendance*0.10/25 + (hw1 + hw2 + hw3 + hw4 + hw5 + hw6 + hw7)/700*0.35 + exam1/25*0.15 + exam2/25*0.15 + finalExam/40 * 0.25);
closed account (48T7M4Gy)
I think that's broken the back of this problem. The rest is just tidy up now.
lol i thought you were rubbing it in before i saw that formula !! :p
ill try it hold on
Last edited on
the only problem kemort is if you get a calculator and calculate the first student. you get 73.8% not 80.5 so ive been thinking it was wrong... is 80.5 right ??
thank you kemort !!! your so smart lmao. ok so now i have my output.txt file yay ! but that is also what is in my ouput on xcode.. i need xcode's output to show this.. so i should have an output.txt of what i just did ! perfect. but that is also showing in xcode. i need whats below in xcode :) any ideas kemort ?

Letter      count        average attendance 
A               2                   24.00 
B               0                       0
C               4                   21.50 
D               0                      0
F               0                       0
Last edited on
closed account (48T7M4Gy)
80.5 is correct weight - too easy
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
#include<fstream>
#include<string>
#include<iostream>

using namespace std;

int main()
{
	ifstream sampleGrades("sampleGrades.txt");
	ofstream outputGrades("outputGrades.txt");

	string firstLine;
	int TotalStudents;

	double ID = 0.0, Attendance, hw1, hw2, hw3, hw4, hw5, hw6, hw7, exam1, exam2, finalExam;

	double LetterGrade;

	int NumA = 0;
	int NumB = 0;
	int NumC = 0;
	int NumD = 0;
	int NumF = 0;

	string Grade = "";

	if (sampleGrades.is_open())
	{
		getline(sampleGrades, firstLine);

		sampleGrades >> TotalStudents;
		cout << "No. of students: " << TotalStudents << endl;

		cout << firstLine << endl;
		cout <<         "ID     Course  Letter"<< endl;
		cout <<         "       Grade   Grade" << endl;

		outputGrades << "ID     Course  Letter" << endl;
		outputGrades << "       Grade   Grade" << endl;

		while (!sampleGrades.eof())
		{
			sampleGrades >> ID >> Attendance >> hw1 >> hw2 >> hw3 >> hw4 >> hw5 >> hw6 >> hw7 >> exam1 >> exam2 >> finalExam;

			Grade = "Error: if this appears you're #$%@*^~ wrong!!";

			LetterGrade = 100*(Attendance*0.10/25 + (hw1 + hw2 + hw3 + hw4 + hw5 + hw6 + hw7)/700*0.35 + exam1/25*0.15 + exam2/25*0.15 + finalExam/40 * 0.25);

			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 <<         ID << '\t' << LetterGrade << '\t' << Grade << endl;
			outputGrades << ID << '\t' << LetterGrade << '\t' << Grade << 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;

		sampleGrades.close();
		outputGrades.close();
	}
	else
		cout << "Unable to open file";

	return 0;
}


ID     Course  Letter
       Grade   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
Last edited on
^ that didnt work for me at allll.. here is what i have
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
#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
    cout.setf(ios::fixed);
    cout.precision(2);
    
    ifstream sampleGrades4("sampleGrades4.txt");
    ofstream outputGrades("outputgrades.txt");
    
    string firstLine;
    int TotalStudents;
    
    double ID = 0.0, Attendance, CourseGradePercentage;
    double hw1, hw2, hw3, hw4, hw5, hw6, hw7, exam1, exam2, finalExam;

    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 = 100*(Attendance*0.10/25 + (hw1 + hw2 + hw3 + hw4 + hw5 + hw6 + hw7)/700*0.35 + exam1/25*0.15 + exam2/25*0.15 + finalExam/40*0.25);
           
            LetterGrade = 100*(Attendance*0.10/25 + (hw1 + hw2 + hw3 + hw4 + hw5 + hw6 + hw7)/700*0.35 + exam1/25*0.15 + exam2/25*0.15 + finalExam/40*0.25);
            
            
            
            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 << 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;
}
closed account (48T7M4Gy)
You'll need to compare closely what I have against yours. There has to be a difference - somewhere if you're not getting exactly the same result.
but i got the right answer for mine. is what you posted above^ the answer to my post about: ?
Letter      count        average attendance 
A               2                   24.00 
B               0                       0
C               4                   21.50 
D               0                      0
F               0                       0
o i see what was different in yours. for that one value over 100 you had an error.. i see. ok that worked for me. thanks ! you teach better than my teacher lmao...

how do i get this to be in my xcodes output:
Letter      count        average attendance 
A               2                   24.00 
B               0                       0
C               4                   21.50 
D               0                      0
F               0                       0



but still have everything in my output.txt file as it is ? calculating the avg attendance with resspect to the solid Letter grade no '-'s' or '+'s' is beyond me.. he never taught us this
closed account (48T7M4Gy)
but i got the right answer for mine. is what you posted above^ the answer to my post about: ?


Don't get me wrong it's your assignment. The point I would make though is if we are working off the same dataset (ie the same small sample) then the last table of output I showed above is correct.

The question of average attendance against the letterGrade hasn't been addressed in 'my' program. All it would mean though is two extra lines in each if block - one for the number of students with that grade and another for the actual attendance score.

The other aspect you need to look at is the dreaded CourseGradePercentage . All it does is duplicate LetterGrade and can be deleted wherever it appears. Up to you.
Last edited on
closed account (48T7M4Gy)
To see what happens to get rid of the +'s and -'s take a close look at the numX++ lines in each category and how they (don't) vary.
ya i deleted the CGP. the only reason i had that in is because that is how my teacher labeled it. i may go back and change all the Letter Grade's to the CGP. Well ill study on what you suggested above.
I'm not supposed to have 'The number of A's is:" etc. im suposed to have it how it is counted in my block above. i just wanted to test to see if i can do it.
To calculate the avg. attendance from the data in my inputGrades.txt do i take: AvgAttendance= Attendance/137. Then for the grades i'm going to have to write more if statements correct? that is my last question
Thank you for all your help kemort. seriously, i learned a lot today. I'm sure you feel like takin it easy so i'll try and work the rest out myself tonight and see if i can do it with the tools i've acquired.
ok ill play around with the numX++ . im supposed to have the A+, A-, A, B+ ... etc for my ouput.txt.. but for my output on xcode in the box above it is only the solid letters.

"Finally, your program must count the number of grades in each letter category, and print the average attendance value for each letter grade category to the **screen**. Example output printed to screen:"

Ill play around with it
Last edited on
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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++;
            }


Hint: Underline and bold should assist focus ...
Cheers,
Let's know if you have any questions
awesome thank you man.. last thing lol sorry . I need my 'LetterGrade' to have 2 decimal places only. and my ID should just be the number no decimal but when i try to specify a fixed setprecision just for LetterGrades it also does it to ID. Is there a way to keep ID with no decimal and LetterGrades with setprecision(2) only applied to it ?then i will leave this site i promise lol
closed account (48T7M4Gy)
Well, ID could be an integer, or just change setprecision as you go along a line or before or after a block to whatever value you want. But integer for ID makes sense.

http://www.cplusplus.com/reference/iomanip/setprecision/?kw=setprecision
perfect . i got that to work. For NumX++ you recommended i focus on the num part of it. if i change that will that affect my ouput.txt numbers? also the grade counter that i have at the cottom of the txt file is way off. it says theres like 20 D's and thers not even 10. :/
closed account (48T7M4Gy)
Don't change num part because it works.
The totals were OK with the sample dataset. You can check that automatically by comparing the total of the categories with the total number of students processed which is not necessarily 137.
Last edited on
Pages: 1234567