GPa Calculator in c++
#include<iostream.h>
#include <stdlib.h>
using namespace std;
void main()
{
char number[40] ={0}; //this array use to store enrollment number
char name[40] ={0}; // this array use to store students name
float arr[9] = {0}; // this array use to store number and gpa
float gpa,s = 0; // declare variable,,"s" variable use to store credit hours of every subject
int totalcredithours=18; // total credit hours
for(int p=0;p<1;p++) // this loop depend on number of students in class
{ // start braces for loop "p"
gpa = 0;
cout<<"\t\t\tEnrollment Number:";
cin.ignore();
cin.getline(number,80,'\n');
cout<<"\t\t\tStudent Name:";
cin.ignore();
cin.getline(name,80,'\n');
for(int i=1;i<=8;i++) // this loop run only 6 times to get subject number and this loop use only in switch statement
{ // start braces for loop "i"
int x; //declare variable to get number from user
switch(i) //conditional statement
{ // start braces for switch statement
case 1:
cout<<"\n\t\t\tDiscrete Structures "<<endl;
cout<<"\t\t\tEnter Number=";
s=0+3;
break;
case 2:
cout<<"\t\t\tObject Oriented Programming"<<endl;
cout<<"\t\t\tEnter Number=";
s=0+3;
break;
case 3:
cout<<"\t\t\tCommunication Skills"<<endl;
cout<<"\t\t\tEnter Number=";
s=0+3;
break;
case 4:
cout<<"\t\t\tBasic electronics"<<endl;
cout<<"\t\t\tEnter Number=";
s=0+2;
break;
case 5:
cout<<"\t\t\tPakistan Studies"<<endl;
cout<<"\t\t\tEnter Number=";
s=0+2;
break;
case 6:
cout<<"\t\t\tscoiology"<<endl;
cout<<"\t\t\tEnter number=";
s=0+3;
break;
case 7:
cout<<"\t\t\tObject Oriented Programming lab"<<endl;
cout<<"\t\t\tEnter number=";
s=0+1;
break;
case 8:
cout<<"\t\t\tBasic electronics lab"<<endl;
cout<<"\t\t\tEnter number=";
s=0+1;
break;
default:
cout<<"\t\t\tNot Valid";
} //end braces for switch statement
cin>>x; //get numbers from user
//now we using if else statements to check grades
if(x>=87&&x<=100)
{
cout<<"\t\t\tGrade A"<<endl<<endl;
arr[i] = (4.0)*s;
}
else if(x>=79&&x<=86)
{
cout<<"\t\t\tgrade B+"<<endl<<endl;
arr[i] = (3.5)*s;
}
else if(x>=72&&x<=79)
{
cout<<"\t\t\tgrade B"<<endl<<endl;
arr[i] = (3.0)*s;
}
else if(x>=66&&x<=71)
{
cout<<"\t\t\tgrade c+"<<endl<<endl;
arr[i] = (2.5)*s;
}
else if(x>=60&&x<=65)
{
cout<<"\t\t\tgrade c"<<endl<<endl;
arr[i] = (2.0)*s;
}
else if(x>=50&&x<=59)
{
cout<<"\t\t\tgrade D"<<endl<<endl;
arr[i] = (1.5)*s;
}
else if(x<50&&x>=0)
{
cout<<"\t\t\tgrade F"<<endl<<endl;
arr[i] = (0)*s;
}
else if(x>100)
{
cout<<"\t\t\tPlease Enter Numbers '0' to '100'"<<endl<<endl;
}
if(x<0)
{
cout<<"\t\t\tPlease Enter Numbers '0' to '100'"<<endl<<endl;
}
} //end for loop "i"
float sum = 0;
for(int j=1;j<=8;j++)
{ // start braces for loop "j"
sum+= arr[j];
} // end braces for loop "j"
gpa=(sum)/totalcredithours; //formula to calculate gpa
cout<<"\t\t\tGPA="<<gpa<<endl<<endl;
if(gpa<2.0&&gpa>1.5)
{
cout<<"\t\t\tprob :(";
}
else if(gpa<1.5&&gpa>1.0)
{
cout<<"\t\t\tchance :(";
}
} //end braces for loop "p"
} //end braces main funtion
0 comments:
Post a Comment