A C program to process the students evolution records using structures

By | October 15, 2013

Let’s identify variables needed for the structure inside the program.

In this student structure, we need several variables to store string as name and number for enrollment number and marks of student appeared in the term end examination.

First variable will be the one which will save the enrollment number and it will be ENROL. In C language we do not have string as variable so we have to use character array for the NAME to save the name of the student. Next are the marks of the student MCS011, MCS012, MCS013, MCS014, MCS015, MCS016, MCSL017 for the term end examination, We can use array for marks but i prefer different variables for the same, So in all Nine variables.
The identified variables are ENROL, NAME, MCS011, MCS012, MCS013, MCS014, MCS015, MCS016, MCSL017.

struct student
{
    unsigned long int ENROL;
    char NAME[15];
    int MCS011,MCS012,MCS013,MCS014,MCS015,MCS016,MCSL017;
}STUD[12]={
         {102038400,"GANESH",55,78,45,56,75,64,75},
         {102038401,"MAHESH",84,56,51,61,56,49,78},
         {102038402,"SURESH",51,95,16,18,91,19,51},
         {102038403,"KALPESH",87,98,74,54,15,61,64},
         {102038404,"RAHUL",74,65,45,41,55,56,54},
         {102038405,"SUBBU",19,84,68,67,45,64,65},
         {102038406,"RAKESH",55,78,45,56,75,64,75},
         {102038407,"ATUL",55,78,45,56,75,64,75},
         {102038408,"DHARMESH",55,78,45,56,75,64,75},
         {102038409,"AJAY",55,78,45,56,75,64,75},
         {102038410,"ABDUL",55,78,45,56,75,64,75},
         {102038411,"RASHMI",55,78,45,56,75,64,75}
     };

Now, Selection of data type will be int data type due to the values expected for enrollment number are decimals and they will be holding nine digit values i.e. 102038401 so int data type is not sufficient for ENROL_NO So to increase the capacity Unsigned for positive number and long modifier for double the storage size. Selection of data type will be int data type due to the values expected for marks are decimals and they will be holding smaller values 0 to 100, So int data type is sufficient for MCS011, MCS012, MCS013, MCS014, MCS015, MCS016, MCSL017. Selection of data type will be char data type due to string is a character array and we don’t have any string data type so char data type is selected for NAME.

Structure of student are initialized as database of the program with 12 records.

Let’s identify variables needed for this program.

In this program, we need only one variable to store enrollment number of the student entered by the user.

Only variable will be the one which will save the enrollment number entered by the user and it will be ENROL_NO so in all One variable.
The identified variables are ENROL_NO data type will be same as above.

For writing a function and using it in the C program, we should declare the function in the MAIN function. Declaration has to done in the area before the code starts, same area where we declare data variables.

    unsigned long int ENROL_NO;
    void gen_result(unsigned long int);

In this program, Give message to user to enter the required enrollment number and scan the enter number i.e. ENROL . Variable ENROL is used for CHECK the range of enrollment numbers present and pass it  to the function call if number is within the range else print the appropriate message. Finally printing of the result screen will be done in the function of the program.

#include<stdio.h>
void main()
{
    unsigned long int ENROL_NO;
    void gen_result(unsigned long int);
    clrscr();
    printf("ENTER THE EMPLOYEE NO TO GENERATE PAYSLIP : ");
    scanf("%ld",&ENROL_NO);
    if(ENROL_NO>102038399 && ENROL_NO<102038412)
        gen_result(ENROL_NO);
    else
        printf("\nYOU HAVE ENTERED WRONG ENROLMENT NO. !!");
    getch();
}

Let’s identify variables needed for function which is part of program outside main function.
Variable which are passed in the function may not be declared again which is  character pointer ENROL_NOENROL is passed to the function and saved in ENROL_NO variable of the function. Now the variable STATUS which will hold the status value to be printed as S or N. SC or NC are used as status as SUCCESSFULLY COMPLETED or NOT COMPLETED respectively in the FUNCTION. In SC and NC we have C common and S and N different so STATUS Variable will have to hold only one character so we use char as data type.  The identified variable is STATUS.

void gen_result(unsigned long int ENROL)
{
 char STATUS;
 printf("\n\t\t\tINDIRA GANDHI NATIONAL OPEN UNIVERSITY");
 printf("\n\t\t\tTERM-END EXAMINATION (DEC - 2013)");
 printf("\n\n\tENROLMENT NO.\t: %ld",ENROL);
 printf("\n\tNAME\t\t: %s",STUD[ENROL-102038400].NAME);
 printf("\n\tPROGRAMME CODE \t: MCA");
 printf("\n\t_______________________________________________________________");
 printf("\n\tCOURSE\t\tTERM END\tTERM END \t");
 printf("\n\t CODE \t\t THEORY \tPRACTICAL\tSTATUS");
 printf("\n\t_______________________________________________________________");
 if(STUD[ENROL-102038400].MCS011<40) STATUS='N'; else STATUS='S';
 printf("\n\tMCS011\t\t%d\t\t-\t\t%cC",STUD[ENROL-102038400].MCS011,STATUS);
 if(STUD[ENROL-102038400].MCS012<40) STATUS='N'; else STATUS='S';
 printf("\n\n\tMCS012\t\t%d\t\t-\t\t%cC",STUD[ENROL-102038400].MCS012,STATUS);
 if(STUD[ENROL-102038400].MCS013<40) STATUS='N'; else STATUS='S';
 printf("\n\n\tMCS013\t\t%d\t\t-\t\t%cC",STUD[ENROL-102038400].MCS013,STATUS);
 if(STUD[ENROL-102038400].MCS014<40) STATUS='N'; else STATUS='S';
 printf("\n\n\tMCS014\t\t%d\t\t-\t\t%cC",STUD[ENROL-102038400].MCS014,STATUS);
 if(STUD[ENROL-102038400].MCS015<40) STATUS='N'; else STATUS='S';
 printf("\n\n\tMCS015\t\t%d\t\t-\t\t%cC",STUD[ENROL-102038400].MCS015,STATUS);
 if(STUD[ENROL-102038400].MCS016<40) STATUS='N'; else STATUS='S';
 printf("\n\n\tMCS016\t\t%d\t\t-\t\t%cC",STUD[ENROL-102038400].MCS016,STATUS);
 if(STUD[ENROL-102038400].MCSL017<40) STATUS='N'; else STATUS='S';
 printf("\n\n\tMCSL017\t\t-\t\t%d\t\t%cC",STUD[ENROL-102038400].MCSL017,STATUS);
 printf("\n\t_______________________________________________________________");
 printf("\n\t\tSC :- SUCCESSFULL COMPLETED\tNC :- NOT COMPLETED");
}

In this program, we are passing only the enrollment number and the array of STUD which are the STRUCT STUDENT user defined data type and to find the index number of the array which is zero subtract 102038400 from enrollment number we will find the same. Access the student records in stud array by using dot operator to all the elements of structure student. print the record of the student by customizing the display by using \n new line character and \t tab character. also the status of SC and NC as the status depending upon the marks obtained. Less than 39 will be NC and else SC.

C program code :

  1. #include<stdio.h>
  2. struct student
  3. {
  4.     unsigned long int ENROL;
  5.     char NAME[15];
  6.     int MCS011,MCS012,MCS013,MCS014,MCS015,MCS016,MCSL017;
  7. }STUD[12]={
  8.          {102038400,"GANESH",55,78,45,56,75,64,75},
  9.          {102038401,"MAHESH",84,56,51,61,56,49,78},
  10.          {102038402,"SURESH",51,95,16,18,91,19,51},
  11.          {102038403,"KALPESH",87,98,74,54,15,61,64},
  12.          {102038404,"RAHUL",74,65,45,41,55,56,54},
  13.          {102038405,"SUBBU",19,84,68,67,45,64,65},
  14.          {102038406,"RAKESH",55,78,45,56,75,64,75},
  15.          {102038407,"ATUL",55,78,45,56,75,64,75},
  16.          {102038408,"DHARMESH",55,78,45,56,75,64,75},
  17.          {102038409,"AJAY",55,78,45,56,75,64,75},
  18.          {102038410,"ABDUL",55,78,45,56,75,64,75},
  19.          {102038411,"RASHMI",55,78,45,56,75,64,75}
  20.      };
  21. void main()
  22. {
  23.  unsigned long int ENROL_NO;
  24.     void gen_result(unsigned long int);
  25.     clrscr();
  26.     printf("ENTER THE EMPLOYEE NO TO GENERATE PAYSLIP : ");
  27.     scanf("%ld",&ENROL_NO);
  28.     if(ENROL_NO>102038399 && ENROL_NO<102038412)
  29.         gen_result(ENROL_NO);
  30.     else
  31.         printf("\nYOU HAVE ENTERED WRONG ENROLMENT NO. !!");
  32.     getch();
  33. }
  34. void gen_result(unsigned long int ENROL)
  35. {
  36.  char STATUS;
  37.  printf("\n\t\t\tINDIRA GANDHI NATIONAL OPEN UNIVERSITY");
  38.  printf("\n\t\t\tTERM-END EXAMINATION (DEC - 2013)");
  39.  printf("\n\n\tENROLMENT NO.\t: %ld",ENROL);
  40.  printf("\n\tNAME\t\t: %s",STUD[ENROL-102038400].NAME);
  41.  printf("\n\tPROGRAMME CODE \t: MCA");
  42.  printf("\n\t_______________________________________________________________");
  43.  printf("\n\tCOURSE\t\tTERM END\tTERM END \t");
  44.  printf("\n\t CODE \t\t THEORY \tPRACTICAL\tSTATUS");
  45.  printf("\n\t_______________________________________________________________");
  46.  if(STUD[ENROL-102038400].MCS011<40) STATUS='N'; else STATUS='S';
  47.  printf("\n\tMCS011\t\t%d\t\t-\t\t%cC",STUD[ENROL-102038400].MCS011,STATUS);
  48.  if(STUD[ENROL-102038400].MCS012<40) STATUS='N'; else STATUS='S';
  49.  printf("\n\n\tMCS012\t\t%d\t\t-\t\t%cC",STUD[ENROL-102038400].MCS012,STATUS);
  50.  if(STUD[ENROL-102038400].MCS013<40) STATUS='N'; else STATUS='S';
  51.  printf("\n\n\tMCS013\t\t%d\t\t-\t\t%cC",STUD[ENROL-102038400].MCS013,STATUS);
  52.  if(STUD[ENROL-102038400].MCS014<40) STATUS='N'; else STATUS='S';
  53.  printf("\n\n\tMCS014\t\t%d\t\t-\t\t%cC",STUD[ENROL-102038400].MCS014,STATUS);
  54.  if(STUD[ENROL-102038400].MCS015<40) STATUS='N'; else STATUS='S';
  55.  printf("\n\n\tMCS015\t\t%d\t\t-\t\t%cC",STUD[ENROL-102038400].MCS015,STATUS);
  56.  if(STUD[ENROL-102038400].MCS016<40) STATUS='N'; else STATUS='S';
  57.  printf("\n\n\tMCS016\t\t%d\t\t-\t\t%cC",STUD[ENROL-102038400].MCS016,STATUS);
  58.  if(STUD[ENROL-102038400].MCSL017<40) STATUS='N'; else STATUS='S';
  59.  printf("\n\n\tMCSL017\t\t-\t\t%d\t\t%cC",STUD[ENROL-102038400].MCSL017,STATUS);
  60.  printf("\n\t_______________________________________________________________");
  61.  printf("\n\t\tSC :- SUCCESSFULL COMPLETED\tNC :- NOT COMPLETED");
  62. }

SCREEN SHOTS:-

C_program_Students_Evaluation

C_program_Students_Evaluation_Output

Leave a Reply