Commentate on my work

closed account (ETA9216C)
Please commentate on my project. This is for a class i am taking. If there are any mistakes please let me know. I am not the best in fact probably last in class, this might be the best i can 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
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
#include <c++header.h>
#include <project_description.h>

#include <iostream>           //header
#include <string>
#include <cmath>
#include <cstdlib>



using namespace std;

struct data
{

double average;
string student;
int final_grade;
int lab;
int test1;
int midterm;
int finalexam;
string course;

};

    void getinput(data&);
    double calculations(data&);
    void students_avg(data&);
    void final_grades(data&);
    void system_pause();
    void display_grades(data&);
    void proceed();                            //header

int main()
{
    data avgs;
    char flag= 'y';

     while(flag=='y')
        {
        getinput(avgs);
        students_avg(avgs);
        final_grades(avgs);

              cout<<"Do you have other students? y, yes.Anything else is no";
              cout<<endl;
              cin>>flag;
                if (flag=='y')
                   {
                    proceed();
                    system_pause();
                    system("CLS");
                   }
                else
                    {
                    system("CLS");
                    display_grades(avgs);
                    system_pause();
                   }
             }

    return 0;
}

void getinput(data&avgs)        // display grading policy and user inputs student's grade
{
    cout<<"Grading Policy"<<endl;
    cout<<"15% test 1 ";
    cout<<"25% midterm";
    cout<<"30% final";
    cout<<"30% lab"<<endl<<endl;


        cout<<"  Student's name: ";
        cin>> avgs.student;
        cout<<"  Course: ";
        cin>>avgs.course;
        cout<<endl;


        cout<<"  Enter grade for test 1: ";
        cin>>avgs.test1;
        cout<<"  Enter grade for midterm: ";
        cin>>avgs.midterm;
        cout<<"  Enter Grade for Final exam: ";
        cin>>avgs.finalexam;
        cout<<"  Enter grade for lab ";
        cin>>avgs.lab;
}

double calculations(data&avgs)          //Calculates the students grade into a final grade
{
    int avg1;
    int avg2;
    int avg3;
    int lab1;

        avg1=((avgs.test1/100)*15);
        avg2=((avgs.midterm/100)*25);
        avg3=((avgs.finalexam/100)*30);
        lab1=((avgs.lab/100)*30);

        avgs.final_grade=avg1+avg2+avg3+lab1;


return avgs.final_grade;
}

void students_avg(data&avgs)      //gives a letter grade from calculation function
{
    if (avgs.final_grade>=0,avgs.final_grade<=49)  cout<<"The Final Grade is a F";
    if (avgs.final_grade>=50,avgs.final_grade<=60) cout<<"The Final Grade is a C-";
    if (avgs.final_grade>=61,avgs.final_grade<=69) cout<<"The Final Grade is a C";
    if (avgs.final_grade>=70,avgs.final_grade<=75) cout<<"The Final Grade is a C+";
    if (avgs.final_grade>=76,avgs.final_grade<=84) cout<<"The Final Grade is a B";
    if (avgs.final_grade>=85,avgs.final_grade<=89) cout<<"The Final Grade is a B+";
    if (avgs.final_grade>=90,avgs.final_grade<=94) cout<<"The Final Grade is a A";
    if (avgs.final_grade>=95,avgs.final_grade<=100)cout<<"The Final Grade is a A+";
}

void display_grade(data&avgs)       //Displays the students data
{
    cout<<avgs.student;
    cout<<avgs.course;
    cout<<endl;

    cout<<"lab: "<<avgs.lab;
    cout<<"test 1: "<<avgs.test1;
    cout<<"mideterm: "<<avgs.midterm;
    cout<<"final exam: "<<avgs.finalexam;
    cout<<endl;

    cout<<avgs.final_grade;
}

void system_pause() //alternative to system("pause")
{
    cout << endl;
    cin.sync();
    cout << "Press any key...";
    cin.ignore();
}

void proceed()  //this function let's the user to either make the student retake the course or have them pass the course
{
   int x;

    cout<<"What would you like to do?"<<endl;
    cout<<"type 1 or 2"<<endl;
    cout<<"1. Have student to retake course"<<endl;
    cout<<"2.Student may proceed to next course"<<endl<<endl;
    cin>>x;
        switch(x)
        {
         case 1: cout<<"student MUST retake the course due to average not meeting the requirements.";break;
         case 2: cout<<"Student can proceed to the next course.";break;
         default: cout<<"Please type in the correct input";break;

        }
}


Last edited on
closed account (ETA9216C)
I also have the functions and main on separate .cpp files. This is a MUST for the project. I can't seem to get them to compile along with my headers. Of course, I have it as a project on code blocks.
name of student icludes surname too? if so, you have to use other input-function, because cin >> avgs.student; will read a string until first white-space character, for example space

use getline(cin, avgs.student) instead

also in void students_avg(data&avgs) you should use else if, because if the program finds that final grade is between 0 to 49, it prints the msq, but still checks another IF conditions ( = time consumer)
Last edited on
closed account (ETA9216C)
I'm getting error "undefined reference to final_grades(data&)" and "undefined reference to display_grades(data&)" when i try to compile.

Thank you for the suggestions, I wasn't even thinking about surname at the time.

For the If else, I guess it does make sense to do that. I was trying to make it look "pretty" to rack up points for readability as my professor is very strict about it.

this is what you meant correct?

1
2
3
4
5
6
7
8
    if (avgs.final_grade>=0,avgs.final_grade<=49)  cout<<"The Final Grade is a F";
    else if (avgs.final_grade>=50,avgs.final_grade<=60) cout<<"The Final Grade is a C-";
    else if (avgs.final_grade>=61,avgs.final_grade<=69) cout<<"The Final Grade is a C";
    else if (avgs.final_grade>=70,avgs.final_grade<=75) cout<<"The Final Grade is a C+";
    else if (avgs.final_grade>=76,avgs.final_grade<=84) cout<<"The Final Grade is a B";
    else if (avgs.final_grade>=85,avgs.final_grade<=89) cout<<"The Final Grade is a B+";
    else if (avgs.final_grade>=90,avgs.final_grade<=94) cout<<"The Final Grade is a A";
    else if (avgs.final_grade>=95,avgs.final_grade<=100)cout<<"The Final Grade is a A+";
Last edited on
closed account (Dy7SLyTq)
well you havent defined final grades anywhere. and the declaration for display_grades is actually display_grade
closed account (ETA9216C)
The mistakes are so minor i can't even see it for myself, thank you for catching them for me.
Last edited on
If you could tell us what is your program supposed to do, that would be great.

> if (avgsfinal_grade>=0,avgs.final_grade<=49)
¿what do you think the comma operator does?

1
2
#include <c++header.h>
#include <project_description.h> 

annoying

> I was trying to make it look "pretty" to rack up points for readability
> as my professor is very strict about it.
You may want to indent your code then.
closed account (ETA9216C)
dont worry about the #<c++header.h. and <project_description>. C++ header.h include all of the includes like iostream,cmath and so on and my structure and my prototypes.

project_description.h include my project description which is just a massive comment.

I thought it was self explanatory what my program does, but it just suppose get your total average from collected data like tests, midterm, labs etc...

then it calculates it into a final average which that massive IF statements come in to tell you your letter grade from F to an A+.

sorry for the confusion.

closed account (ETA9216C)
I got my code working, but the calculating function is not working properly. The final average always go to a crazy number.
Last edited on
Topic archived. No new replies allowed.