Code:
#include<stdio.h>
/* ASrray definitions*/
#define STU_ROWSIZE 6
#define STU_COLSIZE 2
#define BILL_ROWSIZE 6
#define BILL_COLSIZE 3
/*Function prototypes*/
int checkID(int stuInfo[][STU_COLSIZE], int idEntered);
void processUndergrad(double billInfo[][BILL_COLSIZE], int id, int rowNumber);
void processGraduate(double billInfo[][BILL_COLSIZE], int id, int rowNumber);
void processPhD(double billInfo[][BILL_COLSIZE], int id, int rowNumber);
int checkHours(int hours, int type);
void processFinalReport(int stuInfo[][STU_COLSIZE], double billInfo[][BILL_COLSIZE]);
int main(void)
{
/* The Student info Array*/
int stuInfo[STU_ROWSIZE][STU_COLSIZE]={ {394003920, 2},
{388920394, 3},
{499230076, 1},
{298760112, 2},
{592493811, 3},
{355982306, 3} };
/* The Billing info array*/
double billInfo[BILL_ROWSIZE][BILL_COLSIZE]={ {0.0, 0.0, 0.0},
{0.0, 0.0, 0.0},
{0.0, 0.0, 0.0},
{0.0, 0.0, 0.0},
{0.0, 0.0, 0.0},
{0.0, 0.0, 0.0} };
int idEntered, type, id, rowNumber, tuition;
/* Variable to exit the program */
int exit=1;
/* program repetition controller*/
while(exit==1)
{
printf("Enter the student ID. \n");
scanf("%d", &idEntered);
while(checkID(stuInfo, idEntered)== -1)
{
printf("Invalid student ID. Please try again. \n");
scanf("%d", &idEntered);
}
int rowID=checkID(stuInfo, idEntered);
switch(stuInfo[rowID][1])
{
case 1:
processUndergrad(billInfo,idEntered,rowID);
break;
case 2:
processGraduate(billInfo,idEntered,rowID);
break;
case 3:
processPhD(billInfo, idEntered,rowID);
break;
}
/*Prompt user to exit program*/
printf("\nDo you want to continue to the next student? If yes enter 1, else enter 0. \n");
scanf("%d", &exit);
processFinalReport(stuInfo, billInfo);
}
return 0;
}
int checkID(int stuInfo[STU_ROWSIZE][STU_COLSIZE], int idEntered)
{
int i=0,j=0;
for(i=0;i<STU_ROWSIZE;i++)
{
for(j=0;j<STU_COLSIZE;j++)
{
if(stuInfo[i][j]==idEntered)
{
return i;
}
}
}
return -1;
}
void processUndergrad(double billInfo[BILL_ROWSIZE][BILL_COLSIZE],int idEntered, int rowID)
{
int hours;
printf("Enter the number of credit hours \n");
scanf("%d", &hours);
while(checkHours(hours, rowID)==0)
{
printf("Undergrad students must be enrolled in 3-18 hours. \n");
scanf("%d", &hours);
}
int tuition=hours*750;
int scholarshipCompare=tuition*.50;
int scholarship;
printf("Enter scholarship amount \n");
scanf("%d", &scholarship);
while(scholarship>scholarshipCompare)
{
printf("Scholarship can't be greater than 50%% of the tuition. Enter again. \n");
scanf("%d", &scholarship);
}
int finalTuition=tuition-scholarship;
billInfo[rowID][0]=tuition;
billInfo[rowID][1]=scholarship;
billInfo[rowID][2]=finalTuition;
printf("Undergrad student %d tuition is : \n", idEntered);
printf("Gross $ %.2lf\n", billInfo[rowID][0]);
printf("Scholarship Amount $ %.2lf\n", billInfo[rowID][1]);
printf("Total Tuition Bill $ %.2lf\n", billInfo[rowID][2]);
}
void processGraduate(double billInfo[BILL_ROWSIZE][BILL_COLSIZE], int idEntered, int rowID)
{
int hours;
printf("Enter the number of credit hours \n");
scanf("%d", &hours);
while(checkHours(hours, rowID)==0)
{
printf("Graduate students must be enrolled in 3-12 hours. \n");
scanf("%d", &hours);
}
int tuition=hours*1000;
int scholarshipCompare=tuition*.75;
int scholarship;
printf("Enter scholarship amount \n");
scanf("%d", &scholarship);
while(scholarship>scholarshipCompare)
{
printf("Scholarship can't be greater than 75%% of the tuition. Enter again. \n");
scanf("%d", &scholarship);
}
int finalTuition=tuition-scholarship;
billInfo[rowID][0]=tuition;
billInfo[rowID][1]=scholarship;
billInfo[rowID][2]=finalTuition;
printf("\nGraduate student %d tuition is : \n", idEntered);
printf("Gross $ %.2lf\n", billInfo[rowID][0]);
printf("Scholarship Amount $ %.2lf\n", billInfo[rowID][1]);
printf("Total Tuition Bill $ %.2lf\n", billInfo[rowID][2]);
}
void processPhD(double billInfo[BILL_ROWSIZE][BILL_COLSIZE], int idEntered, int rowID)
{
int hours;
printf("Enter the number of credit hours \n");
scanf("%d", &hours);
while(checkHours(hours, rowID)==0)
{
printf("PhD students must be enrolled in 3-9 hours. \n");
scanf("%d", &hours);
}
int tuition=hours*1200;
int stipendCompare=10000;
int stipend;
printf("Enter stipend amount \n");
scanf("%d", &stipend);
while(stipend<1 ||stipend>10000)
{
printf("Scholarship can't be greater than 10,000. Enter again. \n");
scanf("%d", &stipend);
}
int finalTuition=tuition-stipend;
billInfo[rowID][0]=tuition;
billInfo[rowID][1]=stipend;
billInfo[rowID][2]=finalTuition;
printf("Undergrad student %d tuition is : \n", idEntered);
printf("Gross $ %.2lf\n", billInfo[rowID][0]);
printf("Stipend $ %.2lf\n", billInfo[rowID][1]);
printf("Total Tuition Bill $ %.2lf\n", billInfo[rowID][2]);
}
int checkHours(int hours, int type)
{
switch(type)
{
case 1:
if(hours<3 || hours>18)
{
return 0;
}
else
{
return 1;
}
break;
case 2:
if(hours<3 || hours>12)
{
return 0;
}
else
{
return 1;
}
break;
case 3:
if(hours<3 || hours>9)
{
return 0;
}
else
{
return 1;
}
break;
}
}
void processFinalReport(int stuInfo[STU_ROWSIZE][STU_COLSIZE], double billInfo[BILL_ROWSIZE][BILL_COLSIZE])
{
printf("STUDENT BILLING REPORT \n\n\n\n");
printf(" ID TYPE GROSS DISCOUNT NET\n");
printf
}