I’m using Borland C++ for this !
Auto Arranging Names
And Auto Computing Grade
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<iostream.h>
int main()
{
loop:
float a=0, GPA[2];
float P [5], M [5], F [5];
int i,j,choice=0;
char name[2][20],temp[20];
for(i=0;i<2;i++)
{
printf("Enter the name of %d person:\n",i+1);
scanf("%s",&name[i]);
}
printf("\n\nThe names in original order are:\n");
for(i=0;i<2;i++)
{
printf("%d.%s\n",i+1,name[i]);
}
for(i=0;i<2-1;i++)
{
for(j=i+1;j<2; j++)
{
if(strcmp(name[i],name[j]) > 0 )
{
strcpy(temp,name[i]);
strcpy(name[i],name[j]);
strcpy(name[j],temp);
}
}
}
printf("\n\nThe names in alphabetical order are:\n");
for(i=0;i<2;i++)
{
printf("%d.%s\n",i+1,name[i]);
}
{
getch();
for (int i=0;i<2;i++)
{
cout <<"\t Name of the Student's: " <<name[i]<< endl;
cout <<"\n\n";
cout <<"\nPrelime:\n";
cin>>P[i];
cout <<"\nMidTerm:\n";
cin>>M[i];
cout <<"\nFinal:\n";
cin>>F[i];
GPA[i]=(P[i]+M[i]+F[i])/3;
cout <<"GPA=" <<GPA[i]<<"\n\n";
}
cout <<"\n\n";
cout <<"\n\nName"<<"\t\t"<<"Prelim"<<"\t\t"<<"MidTerm"<<"\t\t"<<"Final"<<"\t\t"<<"GPA\n";
for (int i=0;i<2;i++)
{
cout <<name[i]<<"\t\t"<<P [i]<<"\t\t"<<M [i]<<"\t\t"<<F [i]<<"\t\t"<<GPA [i]<<endl;
}
getch();
int bench;
clrscr();
cout <<"Do it again?\n";
cout <<"Press 1 to continue.\n";
cout <<"Press 2 to NO.\n";
cout <<"Enter:";
cin>>bench;
if(bench==1)
{
goto loop;
}
else if (bench==2)
{
return 0;
}
}
}