Breaking

Saturday, 5 March 2016

C++ Cgpa Calcultor code

// GPA Calculator.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"//header file specific for visual studio only...!!!!
#include <iostream>
using namespace std;

#define MAX 7

void input(int data[][2], char sub[][20], char g[][3], int nn);
void process(int data[][2], float gpa[], int nn, float& res,int& crh);
void display(int data[][2], char sub[][20], char g[][3], float gpa[], int nn, float& res);


int main()
{
system("color f0");

int data[MAX][2], n, crh=0;
char sub[MAX][20], g[MAX][3], ch;
float gpa[MAX], res=0;

do{
system("cls");
cout<<"\t\tGPA Calculator\n\n"
<<" 1. Input Data\n"
<<" 2. Display Result Card\n"
<<" 3. Exit\n\n"
<<"Enter your choice : ";
cin>>ch;

switch(ch)
{
case '1' :
do
{
cout<<"Enter number of subjects [Max.7] : ";
cin>>n;
if((n>=1)&&(n<=7))
break;
else
cout<<"Invalid Input...\n";
} while(1);

input(data,sub,g,n);
process(data,gpa,n,res,crh);

break;

case '2' :
display(data,sub,g,gpa,n,res);
break;

case '3' : exit(-1);

default : cout<<"Invalid Choice...\n\n";

}



system("pause>nul");
} while(1);

return 0;
}

void input(int data[][2], char sub[][20], char g[][3], int nn)
{
for(int i=0; i<nn; i++)
{
system("cls");
cout<<"Enter the Name of Subject#"<<i+1<<" : ";
cin.ignore(10,'\n');
cin.get(sub[i],20);

cout<<"Enter Grade : ";
cin.ignore(10,'\n');
cin.get(g[i],3);

cout<<"Enter the number of Credit Hours : ";
cin>>data[i][0];

do
{
cout<<"Enter the %age : ";
cin>>data[i][1];

if((data[i][1]>=0)&&(data[i][1]<=100))
break;
else
cout<<"Invalid Input..."<<endl;
} while(1);


}
}


void process(int data[][2], float gpa[], int nn, float& res,int& crh)
{
for(int i=0; i<nn; i++)
{
if(data[i][1]>=80)
gpa[i]=4.0;

else if((data[i][1]>=75)&&(data[i][1]<80))
gpa[i]=3.5;

else if((data[i][1]>=70)&&(data[i][1]<75))
gpa[i]=3.0;

else if((data[i][1]>=65)&&(data[i][1]<70))
gpa[i]=2.5;

else if((data[i][1]>=60)&&(data[i][1]<65))
gpa[i]=2.0;

else if((data[i][1]>=55)&&(data[i][1]<60))
gpa[i]=1.5;

else
gpa[i]=1.0;


res=res+(gpa[i]*data[i][0]);
crh=crh+(data[i][0]);

}//end of for

res=res/static_cast<float>(crh);
}


void display(int data[][2], char sub[][20], char g[][3], float gpa[], int nn, float& res)
{
system("cls");

cout<<"\t\t\tGPA CALCULATOR\n\n"
<<"Sr.#\t"<<"Subject\t"<<"CRH\t"<<"%age\t"<<"Grade\t"<<"GPA\n";
for(int i=0; i<nn; i++)
cout<<i+1<<"\t"<<sub[i]<<"\t"<<data[i][0]<<"\t"<<data[i][1]<<"\t"<<g[i]<<"\t"<<gpa[i]<<endl;

cout<<"\n______________________________________________________________________________\n\n";

cout<<"\t\t\tGPA = "<<res;
}

No comments:

Post a Comment