You are on page 1of 4

#include <iostream>

#include <string.h>
#include <fstream>

using namespace std;

void get_name(char name[])


{
cout<<"Enter the name of the student > ";
cin>>name;
}

double get_test_marks(double &x, double &y)


{
double marks;
do
{
cout<<"Enter test 1 marks : ";
cin>>x;
if(x > 100 || x < 0)
{
cout<<"Invalid. Test marks should be between 0 and 100.\n";
}
}while(x>100 || x<0);
do
{
cout<<"Enter test 2 marks : ";
cin>>y;
if(y > 100 || y < 0)
{
cout<<"Invalid. Test marks should be between 0 and 100.\n";
}
}while(y>100 || y<0);

if(x>y)
marks = (2*x+y)/3;
else
marks = (2*y+x)/3;
cout<<"The test marks considered for grading are : "<<marks;
return marks;
}

double get_project_marks(double pMarks[], int size)


{
double max = 0;
for(int i=0;i<size;i++)
{
cout<<"Enter Project "<<i+1<<" marks > ";
cin>>pMarks[i];
if(pMarks[i]>100 || pMarks[i]<0)
{
cout<<"Invalis. Project marks should be between 0 and 100.\n";
i=i-1;
continue;
}
if(pMarks[i]>max)
max = pMarks[i];
}
cout<<"The project marks considered for grading are : "<<max;
return max;
}

double get_lab_marks(double lMarks[], int size)


{
double sum = 0;
for(int i=0;i<size;i++)
{
cout<<"Enter Lab "<<i+1<<" marks > ";
cin>>lMarks[i];
if(lMarks[i]>100 || lMarks[i]<0)
{
cout<<"Invalid. Lab marks should be between 0 and 100.\n";
i=i-1;
continue;
}
sum+= lMarks[i];
}
cout<<"The lab marks considered for grading are : "<<sum/size;
return sum/size;
}

double get_total(double lab, double project, double test)


{
return lab*0.25 + project*0.25 + test*0.5;
}

void get_grade(double total, char &grade, char comments[])


{
if (total>=90)
{
grade = 'A';
comments = "Very_Good";
}
else if(total >=80)
{
grade = 'B';
comments = "Good";
}
else if(total >=70)
{
grade = 'C';
comments = "Needs_to_improve";
}
else if(total >=60)
{
grade = 'D';
comments = "Warning_of_Probation";
}
else
{
grade = 'F';
comments = "Failed";
}
}
void print(double test1, double test2, double lab[], int no_of_labs, double
project[], int no_of_projects, double weighthed_mean, double best_of_project,
double average_of_labs, double total_marks, char grade, char comments[], char
name[])
{
cout<<"\nStudent Name : "<<name<<" and Grade : "<<grade;
ofstream file;
file.open("student.dat");
file<<"Student Name : "<<name<<endl;
for(int i=0;i<no_of_projects;i++)
{
file<<"Project"<<i+1<<" marks : "<<project[i]<<endl;
}
file<<"The best of project marks are : "<<best_of_project<<endl;
file<<"Test1 marks : "<<test1<<endl;
file<<"Test2 marks : "<<test2<<endl;
file<<"The Weighted mean of test marks are : "<<weighthed_mean<<endl;
for(int i=0;i<no_of_labs;i++)
{
file<<"Lab"<<i<<" marks : "<<lab[i]<<endl;
}
file<<"The average of lab marks are: "<<average_of_labs<<endl;
file<<"Total marks obtained : "<<total_marks<<" Comments - "<<comments;
file.close();

int menu()
{
int ch;
static int flag[4] = {0,0,0,0};
do {
cout<<"\nSelect a menu choice from the following options.\n";
cout<<"1. Project Marks\n";
cout<<"2. Lab Marks\n";
cout<<"3. Test Marks\n";
cout<<"4. Calculate total marks\n";
cout<<"> ";
cin>>ch;
if(ch > 4)
{
cout<<"This is an invalid menu choice. So please select the correct
choice.\n";
continue;
}
else if(ch == 4 && (flag[0] == 0 || flag[1] == 0 || flag[2] == 0))
{
cout<<"You should select all other choices before selecting this choice.";
}
else if(flag[ch-1] == 1)
{
cout<<"This menu choice is already selected. Please select a choice which is
not selected yet.\n";
}
else
{
flag[ch-1] = 1;
return ch;
}
}while(1);
}

int main()
{
double test1, test2, total_marks, average_of_labs, weighthed_mean,
best_of_project;
double lab[10], project[10];
int no_of_labs=5, no_of_projects=3, choice=0;
char grade;
char name[30], comments[30];

get_name(name);
while(choice<4)
{
choice = menu();
switch(choice)
{
case 1: best_of_project = get_project_marks(project, no_of_projects);
break;
case 2: average_of_labs = get_lab_marks(lab, no_of_labs);
break;
case 3: weighthed_mean = get_test_marks(test1, test2);
break;
case 4: total_marks = get_total(average_of_labs, best_of_project,
weighthed_mean);
get_grade(total_marks, grade, comments);
print(test1, test2, lab, no_of_labs, project, no_of_projects,
weighthed_mean, best_of_project, average_of_labs, total_marks, grade, comments,
name);
}
}

You might also like