C S C O R N E R

Example: Grade Point Average Calculator in C/C++

//Using Turbo Compiler
//gpa calculator by Tasaddaq
 
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
 
char calcGrade(int);
char calcGP(char);
 
 char *course[7];
 int percentage[7];
 char Grade,gp, gp2[7], gpa;
 
int main (void)
{
 textmode(3);
 clrscr();
 
 gotoxy(18, 8);
 cout<<"Course code";
 
 gotoxy(32, 8);
 cout<<"Obtained %";
 
 gotoxy(45, 8);
 cout<<"Grade";
 
 gotoxy(53, 8);
 cout<<"Grade Point";
 
 gotoxy(15, 10);
 cout<<"1-";
 gotoxy(15, 11);
 cout<<"2-";
 gotoxy(15, 12);
 cout<<"3-";
 gotoxy(15, 13);
 cout<<"4-";
 gotoxy(15, 14);
 cout<<"5-";
 gotoxy(15, 15);
 cout<<"6-";
 
 gotoxy(15, 16);
 cout<<"7-";
 
 gotoxy(18, 10);
 cin>>course[0];
 
 gotoxy(32, 10);
 cin>>percentage[0];
 gotoxy(35, 10);
 cout<<"%";
 
 // call calc function
 gotoxy(45, 10);
 cout<<calcGrade(percentage[0]);
 gotoxy(53, 10);
 cout<<calcGP(Grade);
 gp2[0] = calcGP(Grade);
 
 gotoxy(18, 11);
 cin>>course[1];
 
 gotoxy(32, 11);
 cin>>percentage[1];
 gotoxy(35, 11);
 cout<<"%";
 
 
 gotoxy(45, 11);
 cout<<calcGrade(percentage[1]);
 gotoxy(53, 11);
 cout<<calcGP(Grade);
 gp2[1] = calcGP(Grade);
 
 gotoxy(18, 12);
 cin>>course[2];
 
 gotoxy(32, 12);
 cin>>percentage[2];
 gotoxy(35, 12);
 cout<<"%";
 
 gotoxy(45, 12);
 cout<<calcGrade(percentage[2]);
 gotoxy(53, 12);
 cout<<calcGP(Grade);
 gp2[2] = calcGP(Grade);
 
 gotoxy(18, 13);
 cin>>course[3];
 
 gotoxy(32, 13);
 cin>>percentage[3];
 gotoxy(35, 13);
 cout<<"%";
 
 gotoxy(45, 13);
 cout<<calcGrade(percentage[3]);
 gotoxy(53, 13);
 cout<<calcGP(Grade);
 gp2[3] = calcGP(Grade);
 
 gotoxy(18, 14);
 cin>>course[4];
 
 gotoxy(32, 14);
 cin>>percentage[4];
 gotoxy(35, 14);
 cout<<"%";
 
 gotoxy(45, 14);
 cout<<calcGrade(percentage[4]);
 gotoxy(53, 14);
 cout<<calcGP(Grade);
 gp2[4] = calcGP(Grade);
 
 gotoxy(18, 15);
 cin>>course[5];
 
 gotoxy(32, 15);
 cin>>percentage[5];
 gotoxy(35, 15);
 cout<<"%";
 
 gotoxy(45, 15);
 cout<<calcGrade(percentage[5]);
 gotoxy(53, 15);
 cout<<calcGP(Grade);
 gp2[5] = calcGP(Grade);
 
 gotoxy(18, 16);
 cin>>course[6];
 
 gotoxy(32, 16);
 cin>>percentage[6];
 gotoxy(35, 16);
 cout<<"%";
 
 gotoxy(45, 16);
 cout<<calcGrade(percentage[6]);
 gotoxy(53, 16);
 cout<<calcGP(Grade);
 
 gp2[6] = calcGP(Grade);
 
 
 //gdp calculations
 
 gpa = (gp2[0]+gp2[1]+gp2[2]+gp2[3]+gp2[4]+gp2[5]+gp2[6])/ 7 ;
 
 gotoxy(18, 18);
 cout<<"GPA";
 gotoxy(55, 18);
 cout<<gpa;
 
 
 getch();
 return 0;
 }
 
char calcGrade(int temp)
{
 if(temp >= 80)
 Grade = 'A';
 
 else if(temp >= 65)
 Grade = 'B';
 
 else if(temp >= 50)
 Grade = 'C';
 
 else if(temp >= 40)
 Grade = 'D';
 
 else if(temp < 40)
 Grade = 'F';
 
 
 return Grade;
 
}
 
char calcGP(char temp)
{
 if(Grade == 'A')
 gp = '4';
 
 else if(Grade == 'B')
 gp = '3';
 
 else if(Grade == 'C')
 gp = '2';
 
 else if(Grade == 'D')
 gp = '1';
 
 else if(Grade == 'F')
 gp = '0';
 
return gp;
 
}

No comments:

Powered by Blogger.