Advertisement
Niloy007

Sample Project

Mar 11th, 2021
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.83 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. struct school {
  4.     char name[100];
  5.     int roll;
  6.     double marks;
  7. };
  8.  
  9. struct school student[100];
  10. int size = 0;
  11.  
  12. void menu() {
  13.     printf("Main Menu\n");
  14.     printf("1. Insert\n");
  15.     printf("2. Display\n");
  16.     printf("3. Search\n");
  17.     printf("4. Update\n");
  18.     printf("5. Exit\n");
  19. }
  20.  
  21.  
  22. void insert() {
  23.     printf("How many students do you have?\n");
  24.     scanf("%d", &size);
  25.     for (int i = 0; i < size; i++) {
  26.         printf("Enter student's name:\n");
  27.         fflush(stdin);
  28.         gets(student[i].name);
  29.         fflush(stdout);
  30.         printf("Enter student's roll no:\n");
  31.         scanf("%d", &student[i].roll);
  32.         printf("Enter student's total marks:\n");
  33.         scanf("%lf", &student[i].marks);
  34.     }
  35. }
  36.  
  37. void display() {
  38.     if (size == 0) {
  39.         printf("Array is empty\n\n");
  40.     } else {
  41.         printf("Student's Information\n");
  42.         for (int i = 0; i < size; i++) {
  43.             printf("Name: %s\t", student[i].name);
  44.             printf("Roll: %d\t", student[i].roll);
  45.             printf("Marks: %.2lf\n", student[i].marks);
  46.         }
  47.         printf("\n");
  48.     }
  49. }
  50.  
  51.  
  52. void search() {
  53.     if (size == 0) {
  54.         printf("Array is empty\n\n");
  55.     } else {
  56.         int temp;
  57.         printf("Enter studen't roll no:\n");
  58.         scanf("%d", &temp);
  59.         int flag = 1;
  60.  
  61.         for (int i = 0; i < size; i++) {
  62.             if (student[i].roll == temp) {
  63.                 printf("Name: %s\t", student[i].name);
  64.                 printf("Roll: %d\t", student[i].roll);
  65.                 printf("Marks: %.2lf\n", student[i].marks);
  66.                 flag = 0;
  67.             }
  68.         }
  69.         if (flag == 1) {
  70.             printf("Invalid Information\n\n");
  71.         }
  72.     }
  73. }
  74.  
  75. void update() {
  76.     if (size == 0) {
  77.         printf("Array is empty\n\n");
  78.     } else {
  79.         int temp;
  80.         printf("Enter studen't roll no:\n");
  81.         scanf("%d", &temp);
  82.         int flag = 1;
  83.  
  84.         for (int i = 0; i < size; i++) {
  85.             if (student[i].roll == temp) {
  86.                 double value;
  87.                 printf("Enter the updated marks:\n");
  88.                 scanf("%lf", &value);
  89.                 student[i].marks = value;
  90.  
  91.                 flag = 0;
  92.             }
  93.         }
  94.         if (flag == 1) {
  95.             printf("Invalid Information\n\n");
  96.         }
  97.     }
  98. }
  99.  
  100. int main() {
  101.     printf("Student Mangement System\n");
  102.     while (1) {
  103.         int choice;
  104.         menu();
  105.         printf("Enter your choice\n");
  106.         scanf("%d", &choice);
  107.         if (choice == 1) {
  108.             insert();
  109.         } else if (choice == 2) {
  110.             display();
  111.         } else if (choice == 3) {
  112.             search();
  113.         } else if (choice == 4) {
  114.             update();
  115.         } else if (choice == 5) {
  116.             break;
  117.         } else {
  118.             printf("Invalid Information\n\n");
  119.         }
  120.     }
  121. }
  122.  
  123. /*
  124.     Project Submission Date: April -> 24
  125.  
  126.     Structure
  127.         -> insert
  128.         -> Search
  129.         -> update
  130.         -> delete (optional)
  131.     File -> (optional) // (Bonus!)
  132. */
  133.  
  134.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement