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.
#include <c++header.h>
#include <project_description.h>
#include <iostream> //header
#include <string>
#include <cmath>
#include <cstdlib>
usingnamespace 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;
}
}
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)
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";
elseif (avgs.final_grade>=50,avgs.final_grade<=60) cout<<"The Final Grade is a C-";
elseif (avgs.final_grade>=61,avgs.final_grade<=69) cout<<"The Final Grade is a C";
elseif (avgs.final_grade>=70,avgs.final_grade<=75) cout<<"The Final Grade is a C+";
elseif (avgs.final_grade>=76,avgs.final_grade<=84) cout<<"The Final Grade is a B";
elseif (avgs.final_grade>=85,avgs.final_grade<=89) cout<<"The Final Grade is a B+";
elseif (avgs.final_grade>=90,avgs.final_grade<=94) cout<<"The Final Grade is a A";
elseif (avgs.final_grade>=95,avgs.final_grade<=100)cout<<"The Final Grade is a A+";
> 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.
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+.