Advertisement
kartu

StudentManagement

Jan 30th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <malloc.h>
  4.  
  5. struct student{
  6.     char name[50];
  7.     int rollNo;
  8.     float marks[5];
  9.     float totalMarks;
  10.     float per;
  11.     char result[15];
  12. }*p, *s;
  13.  
  14. void printStars(int n){
  15.     int i=0;
  16.     for(i=0;i<n;i++)
  17.         printf("*");
  18. }
  19.  
  20. main()
  21. {
  22.       int nStudents,nSubjects;
  23.       char **subNames;
  24.      
  25.       const int NO_OF_STARS = 29;
  26.       int i,j,l=0;
  27.       //clrscr();
  28.      
  29.       printStars(NO_OF_STARS);
  30.       printf("\nSTUDENT MANAGEMENT SYSTEM\n");
  31.       printStars(NO_OF_STARS);
  32.    
  33.       printf("\nEnter the no. of students : ");
  34.       scanf("%d",&nStudents);
  35.      
  36.       p=malloc(nStudents * sizeof(struct student));
  37.       //p=(struct student*)malloc(nStudents * sizeof(struct student));
  38.    
  39.       s=p;
  40.      
  41.       printf("\nEnter no. of Subjects : ");
  42.       scanf("%d",&nSubjects);
  43.      
  44.       subNames = malloc(nSubjects *  sizeof(char*));
  45.      
  46.       for(i=0;i<nSubjects;i++){
  47.          
  48.         subNames[i] =  malloc(sizeof(char) * (15 + 1));
  49.         printf("\nEnter Subject %d name : ",i+1);
  50.         //fflush(stdin);
  51.         scanf(" %s",subNames[i]);
  52.       }
  53.    
  54.       printf("\n\n");
  55.       printStars(NO_OF_STARS);
  56.       printf("\nEnter Students Information\n");
  57.       printStars(NO_OF_STARS);
  58.    
  59.       for(i=0;i<nStudents;i++)
  60.       {
  61.           printf("\nStudent %d details:",i+1);
  62.           printf("\nRoll no. : ");
  63.           scanf("%d",&p->rollNo);
  64.           printf("\nName : ");
  65.           scanf("%d",&p->name);
  66.      
  67.           p-> totalMarks=0;
  68.           l=0;
  69.          
  70.           for(j=0;j<nSubjects;j++)
  71.           {
  72.             printf("%s Marks : ",subNames[j]);
  73.             scanf("%f",&p->marks[j]);
  74.             p->totalMarks+=p->marks[j];
  75.             //printf("Value of marks is : %f",p->marks[j]);
  76.             if(p->marks[j] < 35)
  77.                 l=1;
  78.           }
  79.          
  80.           p->per = p-> totalMarks / nSubjects;
  81.          
  82.           if(l == 0){
  83.               if(p->per >= 60)
  84.                 strcpy(p->result, "Distinction");
  85.               else if(p->per < 60 && p->per >= 50 )
  86.                 strcpy(p->result, "First Class");
  87.               else if(p->per < 50 && p->per >= 40 )
  88.                 strcpy(p->result, "Second Class");
  89.               else if(p->per < 40 && p->per >= 35)
  90.                 strcpy(p->result, "Pass");
  91.               else
  92.                 strcpy(p->result, "Fail");
  93.           }else{
  94.             strcpy(p->result,"FAIL");
  95.           }
  96.           p++;
  97.        }
  98.        
  99.         printStars(NO_OF_STARS);
  100.         printf("\nStudent Results\n");
  101.         printStars(NO_OF_STARS);
  102.        
  103.         printf("%10d","Roll No.");
  104.         printf("%20s","Name");
  105.        
  106.         printf("%15s","Total");
  107.         printf("%20s","Per.");
  108.         printf("%15s","Result");
  109.        
  110.         printStars(NO_OF_STARS);
  111.        
  112.        for(i=0;i<nStudents;i++)
  113.        {
  114.             //printf("\n%s\t%s",s->name,s->result);
  115.             printf("%10s", s->rollNo);
  116.             printf("%15s", s->name);
  117.            
  118.             for(j=0;j<nSubjects;j++){
  119.                 printf("%5d", s->marks[j]);
  120.             }
  121.            
  122.             printf("%6d", s->totalMarks);
  123.             printf("%6f", s->per);
  124.             printf("%15s",s->result);
  125.            
  126.             s++;
  127.        }
  128.      
  129.    
  130.     printf("\n\n");
  131.     printStars(NO_OF_STARS);
  132.     printf("\nMaximum Marks\n");
  133.     printStars(NO_OF_STARS);
  134.    
  135.     printf("%15s","Subject");
  136.     printf("%10s","Roll No.");
  137.     printf("%10s\n","Marks");
  138.    
  139.       for(i=0;i<nSubjects;i++){
  140.          
  141.         int highestMarks = 0;
  142.         int stuId = 0;
  143.      
  144.         for(j=0;j<nStudents;j++){
  145.            
  146.             if(s->marks[i] > highestMarks){
  147.                 highestMarks = s->marks[i];
  148.                 stuId = j;
  149.             }
  150.         }
  151.         /*
  152.         printf("%15s",nSubjects[i]);
  153.         printf("%10d", stuId);
  154.         printf("%10d\n",highestMarks);
  155.         */
  156.       }
  157.        
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement