Niloy007

Student Management System (Sample Project)

Nov 29th, 2020 (edited)
590
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. struct school {
  4.     char name[40];
  5.     int roll;
  6.     double marks;
  7. };
  8.  
  9. struct school student[50];
  10. int number = 0;
  11.  
  12. void insert() {
  13.     printf("Enter student's number:\n");
  14.     scanf("%d", &number);
  15.  
  16.     for (int i = 0; i < number; i++) {
  17.         printf("Enter student's name:\n");
  18.         fflush(stdin);
  19.         gets(student[i].name);
  20.         fflush(stdout);
  21.         printf("Enter student's roll\n");
  22.         scanf("%d", &student[i].roll);
  23.         printf("Enter student's marks:\n");
  24.         scanf("%lf", &student[i].marks);
  25.     }
  26. }
  27.  
  28. void display() {
  29.     if(number == 0) {
  30.         printf("Please insert the value first!\n");
  31.     } else {
  32.         for (int i = 0; i < number; i++) {
  33.             printf("Name: %s\n", student[i].name);
  34.             printf("Roll: %d\n", student[i].roll);
  35.             printf("Marks: %.2lf\n\n", student[i].marks);
  36.         }
  37.     }
  38. }
  39.  
  40. void search() {
  41.     if(number == 0) {
  42.         printf("Please insert the value first!\n");
  43.     } else {
  44.         int value, flag = 1;
  45.         printf("Enter the roll number\n");
  46.         scanf("%d", &value);
  47.  
  48.         // Search Operation
  49.         for (int i = 0; i < number; i++) {
  50.             if(value == student[i].roll) {
  51.                 printf("Name: %s\n", student[i].name);
  52.                 printf("Roll: %d\n", student[i].roll);
  53.                 printf("Marks: %.2lf\n", student[i].marks);
  54.                 flag = 0;
  55.             }
  56.         }
  57.  
  58.         if(flag == 1) {
  59.             printf("Roll number doesn't exist\n");
  60.         }
  61.     }
  62. }
  63.  
  64.  
  65. int main() {
  66.     printf("Welcome to our project!\n");
  67.  
  68.     while(1) {
  69.         printf("Main Menu:\n");
  70.         printf("1. Insert\n");
  71.         printf("2. Display\n");
  72.         printf("3. Search\n");
  73.         printf("4. Exit\n");
  74.         int choise;
  75.         printf("Enter your choise:\n");
  76.         scanf("%d", &choise);
  77.         if(choise == 1) {
  78.             insert();
  79.         } else if (choise == 2) {
  80.             display();
  81.         } else if (choise == 3) {
  82.             search();
  83.         } else if (choise == 4) {
  84.             break;
  85.         } else {
  86.             printf("\nWrong Input\nYou have to choose between 1 - 3\n\n");
  87.         }
  88.     }
  89. }
  90.  
  91. /*
  92.     Project Submission Date:
  93.  
  94.     Structure
  95.         -> insert
  96.         -> query
  97.         -> update
  98.         -> delete (optional)
  99.     File -> (optional) // (Bonus!)
  100. */
RAW Paste Data