Struggling Bad!

closed account (LE8p216C)
I have wrote the code for this problem in 2 different ways but they are huge programs with too many variables I feel it could be simplified. If anyone has time and could show me the simplest most compact form of this problem I would greatly appreciate it!

I need help calculating the final grades. Assume we have only 3 students in this class so build a loop into this program. Obtain the student id #, the first test grade, second test score and 4 lab assignment scores from the keyboard. Validate that the 2 test scores are between 0-100. In the main routine, calculate the average by adding the six scores together and then dividing the result by six. Call a function, taking with you the average, that will figure and print the letter grade. Based on the Average, assign the student a letter grade as follows: Average Range Letter Grade 90 - 100 A 80 – 89.9 B 70 – 79.9 C 60 – 69.9 D 0 - 59.9 F
Do not double-post. Earlier thread: https://www.cplusplus.com/forum/beginner/270179/

You wrote:
This is for a class I am teaching showing them a basic on CPP can anyone show me the most basic command way of doing this without any hard arrays or loops that would be confusing for them starting out?
I think there is a meme that would fit here ...
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173

struct student {
    int id, test1, test2, lab1, lab2, lab3, lab4;
    float average;
    char grade;

    student()
        : id(id), test1(test1), test2(test2),lab1(lab1),lab2(lab2),lab3(lab3),lab4(lab4)  {}


    student verify() {
        this->_verify(this->test1, 1);
        this->_verify(this->test1,1);
        this->_verify(this->test2, 2);
        this->_verify(this->lab1, 3);
        this->_verify(this->lab2, 4);
        this->_verify(this->lab3, 5);
        this->_verify(this->lab4, 6);
        return *this;
    }

   student _verify(int a, int count) {
       if (a > 100 || a < 0) {
           std::cout << "Problem With Student ID " << this->id << " Grades Entered.  Please Enter Corrected Value " << "\n";
           if (count == 1) {
               std::cout << "Enter Test1 Score" << "\n";
               int in;
               std::cin >> in;
               this->test1 = in;
           }
           if (count == 2) {
               std::cout << "Enter Test2 Score" << "\n";
               int in;
               std::cin >> in;
               this->test2 = in;
           }
           if (count == 3) {
               std::cout << "Enter Lab1 Score" << "\n";
               int in;
               std::cin >> in;
               this->lab1 = in;
           }
           if (count == 4) {
               std::cout << "Enter Lab2 Score" << "\n";
               int in;
               std::cin >> in;
               this->lab2 = in;
           }
           if (count == 5) {
               std::cout << "Enter Lab3 Score" << "\n";
               int in;
               std::cin >> in;
               this->lab3 = in;
           }
           if (count == 6) {
               std::cout << "Enter Lab4 Score" << "\n";
               int in;
               std::cin >> in;
               this->lab4 = in;
           }
       }
        return *this;
    }

   student _average() {

      this->average = (this->test1 + this->test2 + this->lab1 + this->lab2 + this->lab3 + this->lab4) / 6.0f;
      return *this;
   }

   student _grade() {  //Grade 90 - 100 A 80 – 89.9 B 70 – 79.9 C 60 – 69.9 D 0 - 59.9 F
       if (this->average <= 100 && this->average >= 90) {
           this->grade = 'A';
       }
       else if (this->average < 90 && this->average > 79.99) {
           this->grade = 'B';
       }
       else if (this->average < 80 && this->average > 69.99) {
           this->grade = 'C';
       }
       else if (this->average < 70 && this->average > 59.89) {
           this->grade = 'D';
       }
       else {
           this->grade = 'F';
       }
       return *this;
   }

   void GradeInput() {

       int in = 0;

       std::cout << "Enter Student ID" << "\n";

       std::cin >> in;
       this->id = in;

       in = 0;

       std::cout << "Enter Test1 Score" << "\n";

       std::cin >> in;
       this->test1 = in;

       in = 0;

       std::cout << "Enter Test2 Score" << "\n";

       std::cin >> in;
       this->test2 = in;

       in = 0;

       std::cout << "Enter Lab1 Score" << "\n";

       std::cin >> in;
       this->lab1 = in;

       in = 0;

       std::cout << "Enter Lab2 Score" << "\n";

       std::cin >> in;
       this->lab2 = in;

       in = 0;

       std::cout << "Enter Lab3 Score" << "\n";

       std::cin >> in;
       this->lab3 = in;

       in = 0;

       std::cout << "Enter Lab4 Score" << "\n";

       std::cin >> in;
       this->lab4 = in;

   }
   
   void output() {
       std::cout << "Student ID : " << this->id << "\n";
       std::cout << "Test1 : " << this->test1<<"\n";
      
           std::cout << "Test2 : " << this->test2 << "\n";
      
           std::cout << "Lab1 : " << this->lab1 << "\n";
           std::cout << "Lab2 : " << this->lab2 << "\n";
           std::cout << "Lab3 : " << this->lab3 << "\n";
           std::cout << "Lab4 : " << this->lab4 << "\n";
           std::cout << "Average : " << this->average<< "\n";
           std::cout << "Final Grade : " << this->grade << "\n";
           std::cout << "\n";
           std::cout << "\n";
   }
};



int main() {
    for (int i = 0; i < 3; i++) {
        student x;
        x.GradeInput();
        x.verify();
        x._average();
        x._grade();
        x.output();
       
    }
}
Last edited on
this is probably alot simplier lol

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
char calc_grade(float avg) {
    if (avg <= 100 && avg >= 90) {
        return 'A';
    }
    else if (avg < 90 && avg > 79.99) {
        return 'B';
    }
    else if (avg < 80 && avg > 69.99) {
        return 'C';
    }
    else if (avg < 70 && avg > 59.89) {
        return 'D';
    }
    else {
        return 'F';
    }
 
}

int main() {
    int i = 0;
    while (i < 3) {
        for (; i < 3; i++) {
            int studentID=0;
            int T1=0;
            int T2=0;
            int lab1=0;
            int lab2=0;
            int lab3=0;
            int lab4=0;

            std::cout << "Enter Student ID" << "\n";
            std::cin >> studentID;
            std::cout << "Enter Test 1 Score" << "\n";
            std::cin >> T1;
            std::cout << "Enter Test 2 Score" << "\n";
            std::cin >> T2;
            std::cout << "Enter Lab 1 Score" << "\n";
            std::cin >> lab1;
            std::cout << "Enter Lab 2 Score" << "\n";
            std::cin >> lab2;
            std::cout << "Enter Lab 3 Score" << "\n";
            std::cin >> lab3;
            std::cout << "Enter Lab 4 Score" << "\n";
            std::cin >> lab4;

            if (T1 > 100 || T1 < 0 || T2>100 || T2 < 0) {
                std::cout << "Test Scores Failed To Verify"<<"\n";
                std::cout << "\n";
                std::cout << "\n";
                i--;
                break;
            }

            float average = (T1 + T2 + lab1 + lab2 + lab3 + lab4) / 6.0f;

            char grade = calc_grade(average);

            std::cout << "Student Grade : " << grade << "\n";
            std::cout << "\n";
            std::cout << "\n";
        }
    }
}
closed account (LE8p216C)
Yes that is much simpler thank you!
> closed account (LE8p216C)
Another free food and fcuk off driveby gets to stay on the course for one more week before eventually being found out.
Topic archived. No new replies allowed.