Help converting inputs.txt to outputs.txt

Pages: 1... 34567
right exactly theres like 170 . why is that ? is my input.txt being read wrong by my program?
closed account (48T7M4Gy)
No I don't think so. The number 137 appears at the start of the data file and that is not necessarily the number of students on the list. You can prove that easily by changing that number to 7 million 402 thousand.
hmmmm. thats wierd then. i tried an equation to calcualte the avg attendance for Letter A but it didnt work. I get my colum titles under every row.

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
#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
    
    
    ifstream sampleGrades4("sampleGrades4.txt");
    ofstream outputGrades("outputgrades.txt");
    
    string firstRow;
    int TotalStudents;
    
    double Attendance;
    double hw1, hw2, hw3, hw4, hw5, hw6, hw7, exam1, exam2, finalExam;
    double LetterGrade, AvgAttendance;
    
    int ID = 0;
    int NumA = 0;
    int NumB = 0;
    int NumC = 0;
    int NumD = 0;
    int NumF = 0;
    int Count = 0;
    
    string Grade = "";
    
    
    if (sampleGrades4.is_open())
    {
        getline(sampleGrades4, firstRow);
        
        sampleGrades4 >> TotalStudents;
        cout << "Number of Students: " << TotalStudents << endl;
        
        cout << firstRow << endl;
        
        outputGrades << "ID" << setw(14) << "Course Letter" << setw(17) << "Letter Grade" << endl;
       
        
        while ( !sampleGrades4.eof() )
        {
            sampleGrades4 >> ID >> Attendance >> hw1 >> hw2 >> hw3 >> hw4 >> hw5 >> hw6 >> hw7 >> exam1 >> exam2 >> finalExam;
            
            Grade = "Error: This is 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);
            
            AvgAttendance = Attendance/25*NumA;
            cout << "Letter" << '\t' << "Count" << '\t' << "AvgAttendance" << endl;
            
        
            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++;
            }
          

            outputGrades << ID << '\t' << setprecision(2) << fixed << LetterGrade << '\t' << '\t' << Grade << endl;
            
            cout << Grade << '\t' << Count << '\t' << AvgAttendance << 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;
}
im stumped on how to make just one variable for Num for my avg attendance equation when i have 11 variable Num's to calculate for my ouputgrades.txt ya know
closed account (48T7M4Gy)
you need another set of variables countA and totalA to get the average attendance in each category. That could be another 20 variables. If you're not happy with that then use arrays.
Last edited on
o no its ok. i enjoy programming like this. i will learn arrays in my class in 2 weeks so i cant use those now. Ill make those variables now. So i should make new if else if statements right ? or should i just add like CountA++ under the NumA++ etc
Last edited on
so i have this now. Do i need to have an avgAttendance equation for each totalX? i added CountX++ in each if else if statement. But for my equation i have
AvgAttendance = Attendance/25 *CountA; Im gonna need that for each correct ?

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
#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
    
    
    ifstream sampleGrades4("sampleGrades4.txt");
    ofstream outputGrades("outputgrades.txt");
    
    string firstRow;
    int TotalStudents;
    
    double Attendance;
    double hw1, hw2, hw3, hw4, hw5, hw6, hw7, exam1, exam2, finalExam;
    double LetterGrade, AvgAttendance;
    double TotalA, TotalB, TotalC, TotalD, TotalF;
    
    int ID = 0;
    int NumA = 0;
    int NumB = 0;
    int NumC = 0;
    int NumD = 0;
    int NumF = 0;
    int CountA = 0, CountB = 0, CountC = 0, CountD = 0, CountF = 0;
    
    string Grade = "";
    
    
    if (sampleGrades4.is_open())
    {
        getline(sampleGrades4, firstRow);
        
        sampleGrades4 >> TotalStudents;
        cout << "Number of Students: " << TotalStudents << endl;
        
        cout << firstRow << endl;
        
        outputGrades << "ID" << setw(14) << "Course Letter" << setw(17) << "Letter Grade" << endl;
       
        
        while ( !sampleGrades4.eof() )
        {
            sampleGrades4 >> ID >> Attendance >> hw1 >> hw2 >> hw3 >> hw4 >> hw5 >> hw6 >> hw7 >> exam1 >> exam2 >> finalExam;
            
            Grade = "Error: This is 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);
            
            AvgAttendance = Attendance/25*CountA;
            cout << "Letter" << '\t' << "Count" << '\t' << "AvgAttendance" << endl;
            
        
            if (LetterGrade >= 97 && LetterGrade <= 100)
            {
                Grade = " A+ ";
                NumA++;
                CountA++;
            }
            else if (LetterGrade >= 93 && LetterGrade < 97)
            {
                Grade = " A ";
                NumA++;
                CountA++;
            }
            else if (LetterGrade >= 90 && LetterGrade < 93)
            {
                Grade = " A- ";
                NumA++;
                CountA++;
            }
            else if (LetterGrade >= 87 && LetterGrade < 90)
            {
                Grade = " B+ ";
                NumB++;
                CountB++;
            }
            else if (LetterGrade >= 83 && LetterGrade < 87)
            {
                Grade = " B ";
                NumB++;
                CountB++;
            }
            else if (LetterGrade >= 80 && LetterGrade < 83)
            {
                Grade = " B- ";
                NumB++;
                CountB++;
            }
            else if (LetterGrade >= 77 && LetterGrade < 80)
            {
                Grade = " C+ ";
                NumC++;
                CountC++;
            }
            else if (LetterGrade >= 73 && LetterGrade < 77)
            {
                Grade = " C ";
                NumC++;
                CountC++;
            }
            else if (LetterGrade >= 70 && LetterGrade < 73)
            {
                Grade = " C- ";
                NumC++;
                CountC++;
            }
            else if (LetterGrade >= 60 && LetterGrade < 70)
            {
                Grade = " D ";
                NumD++;
                CountD++;
            }
            else if (LetterGrade >= 0 && LetterGrade < 60)
            {
                Grade = " F ";
                NumF++;
                CountF++;
            }
          

            outputGrades << ID << '\t' << setprecision(2) << fixed << LetterGrade << '\t' << '\t' << Grade << endl;
            
            cout << Grade << '\t' << Count << '\t' << AvgAttendance << 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;
}
i made a small mistake i got the column titles fixed. But the numbers are still with the + and -
Letter	Count	AvgAttendance
0
 B- 	0	0
0
 F 	0	0
0
 A+ 	1	0
0
 A 	2	1
0
 B- 	2	1.68
0
 B+ 	2	1.92
0
 C 	2	1.36
0
 A- 	3	2
1
 C 	3	2.76
1
 C+ 	3	2.88
1
 C+ 	3	2.64
Last edited on
i made a seperate if else if table with Letter instead of Grades so it doesnt mess up my output.txt. I gotta figure out though the avg attendace equation and how to have it read for every letter instead of the TotalA,B,C,D,F unless i have to do it that way then i can as long as the xcodeoutput table is right

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
   if (LetterGrade >= 100 && LetterGrade <= 90)
            {
                Letter = " A ";
                CountA++;
            }
            else if (LetterGrade >= 80 && LetterGrade < 90 )
            {
                Letter = " B ";
                CountB++;
            }
            else if (LetterGrade >= 70 && LetterGrade < 80)
            {
                Letter = " C ";
                CountC++;
            }
            else if (LetterGrade >= 60 && LetterGrade < 70)
            {
                Letter = " D ";
                CountD++;
            }
            else if (LetterGrade >= 0 && LetterGrade < 60)
            {
                Letter = " F ";
                CountF++;
            }
i feel like the only way to successfully do this is with arrays; thats what i keep reading even though its not specifically my issue
closed account (48T7M4Gy)
Arrays condense and simplify the end result but if you change now you are in for a lot of work.

All you do is add to each category a (progressive) total score via a new variable along with a new progressive count of the students in that category. They have no effect on output unless you program it. This is simple!
LOL. it probably is simple .. i just dont see it. Soo i should have something like this

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
double TotalA, TotalB, TotalC, TotalD, TotalF;

int CountA = 0, CountB = 0, CountC = 0, CountD = 0, CountF = 0;

 if (LetterGrade >= 97 && LetterGrade <= 100)
            {
                Grade = " A+ ";
                NumA++;
                CountA++;
                TotalA++;
            }
            else if (LetterGrade >= 93 && LetterGrade < 97)
            {
                Grade = " A ";
                NumA++;
                CountA++;
                TotalA++;
            }
            else if (LetterGrade >= 90 && LetterGrade < 93)
            {
                Grade = " A- ";
                NumA++;
                CountA++;
                TotalA++;
            }
i just dont see how i can write just 1 equation that can calculate the specific avg attendance just for people who have a specific grade. So as an example there are 40 people with A's. My 1 equation can calculate just that groups avg attendance. Plus it can do it for all the other grrades? I may not see it because this is my first program with an input file so i cant picture how i can have my program selectively pick out the students in groups. :/ ive been trying all day though i have
closed account (48T7M4Gy)
A typical category would be:

1
2
3
4
5
6
7
else if (LetterGrade >= 90 && LetterGrade < 93)
			{
				Grade = " A- "; 
				NumA++;
				attendAm++; //<--- new
				countAm++;   // <--- new
			}


Then at the end attendAm/countAm is the average.

( Note attendAm means attendA-, attendA means attendA and attendAp means attendA+, i.e each category has its own variable not the general variable as for NumA )
ooo so i need to make INT's of:
TotalAm, TotalBm, TotalCm, TotalDm, TotalFm (
CountAm CountBm CountCm CountDm CountFm
&
TotalA TotalB TotalC TotalD TotalF
CountA CountB CountC CountD CountF
&
TotalAp TotalBpTotalCpTotalDp TotalFp
CountAp CountBp CountCp CountDp CountFp

- Thats 30 variables. Is that what you mean ? Also, it doesnt have to be attend right thats just what you put
- Then i will have 15 equations like TotalAm/CountAm
Last edited on
attendAm/countAm is the average of the a minus' though right ? I need the avg
students attendance of --> TotalAm + TotalA + TotalAp/CountAm +CountA + CountAp
-^ my program needs to pick only the students with the A's (in this example) and take their avg attendance. not the avg attendance of the whole list of students. do you know what i mean ? Thank you for the 'p' and 'm' though. i didnt know that. now thats another tool in my arsonal
so you mean something like:
AvgAttendanceA = TotalAm/CountAm + TotalA/CountA + TotalAp/CountAp
then for my Count column. I will be like:
CountA = CountAm +CountA + Countp
-then do that for all the other letters. So i will have 4 AvgAttendance doubles.
then i can line up the couts so my program will output it cleanly. Is that it ? :D
Last edited on
closed account (48T7M4Gy)
It all depends on what you are averaging. I am assuming that the average is the average attendance mark for students who got A- for example.

If that assumption of mine is correct, and only you know, then average for A- is attendAm/countAm, nothing more, nothing less. :)

You are right, there are all those extra variables and equations. No question of that. Arrays are the only way to get around it and that has always been on right from the getgo. However that is simply a design and workload choice you have to make.

AvgAttendanceA = TotalAm/CountAm + TotalA/CountA + TotalAp/CountAp
should be AvgAttendanceA =( TotalAm + TotalA + TotalAp)/(CountAp + CountA + CountAm)

But that last means you don't need as many variables - you can save a heap of trouble if you just want the A's general rather than A's specific aggregates. Have a think about it.
i only need the A+ A and A- for the output.txt ; for the XCODE output, it is the solid letter. not a- or a+ its the A+'s A's and A-'s added together. That is what im averaging
Last edited on
my output.txt has 3 columns.

--> ID Grade% LetterGrade(+,solid,-)
-i have that correct as of now.

my xcode output has 3 columns:
--> Letter(all -'s, solid's and +'s combined)
Count(students who got said lettergrade)
Avg Attendance (Avg attendace for students who got said grade)
Pages: 1... 34567