Open In App

Student Information Management System

Improve
Improve
Like Article
Like
Save
Share
Report

Prerequisites: Switch Case in C/C++ Problem Statement: Write a program to build a simple Software for Student Information Management System which can perform the following operations:

  1. Store the First name of the student.
  2. Store the Last name of the student.
  3. Store the unique Roll number for every student.
  4. Store the CGPA of every student.
  5. Store the courses registered by the student.

Approach: The idea is to form an individual functions for every operation. All the functions are unified together to form software.

  1. Add Student Details: Get data from user and add a student to the list of students. While adding the students into the list, check for the uniqueness of the roll number.
  2. Find the student by the given roll number: This function is to find the student record for the given roll number and print the details.
  3. Find the student by the given first name: This function is to find all the students with the given first name and print their details.
  4. Find the students registered in a course: This function is to find all the students who have registered for a given course.
  5. Count of Students: This function is to print the total number of students in the system
  6. Delete a student: This function is to delete the student record for the given roll number.
  7. Update Student: This function is to update the student records. This function does not ask for new details for all fields but the user should be able to pick and choose what he wants to update.

Add




// Function to add the student into the database
void add_student()
{
 
    printf("Add the Students Details\n");
    printf("-------------------------\n");
    printf("Enter the first name of student\n");
 
    // First name of the student
    st[i].fname = "Rahul";
    printf("Enter the last name of student\n");
 
    // Last name of the student
    st[i].lname = "Kumar";
    printf("Enter the Roll Number\n");
 
    // Roll Number of the student
    st[i].roll = 1;
    printf("Enter the CGPA you obtained\n");
 
    // CGPA of the student
    st[i].cgpa = 8;
    printf("Enter the course ID"
           " of each course\n");
 
    // Storing the courses every student
    // is enrolled in
    for (int j = 0; j < 5; j++) {
        st[i].cid[j] = j;
    }
    i = i + 1;
}


Find by Roll No




// Function to find the details
// of the student by roll number
void find_rl()
{
    int x;
    printf("Enter the Roll Number"
           " of the student\n");
 
    // Roll number for which the details
    // needs to be found
    x = 1;
 
    // Iterating through all the students
    for (int j = 0; j < i; j++) {
 
        // If the roll number is found
        if (x == st[j].roll) {
            printf("The Students Details are\n");
            printf("The First name is %s\n",
                   st[j].fname);
            printf("The Last name is %s\n",
                   st[j].lname);
            printf("The CGPA is %f\n",
                   st[j].cgpa);
 
            // Printing the courses
            // in which the student
            // is enrolled
            for (int k = 0; k < 5; k++) {
                printf(
                    "The course ID are %d\n",
                    st[j].cid[k]);
            }
            break;
        }
    }
}


Find by Name




// Function to search the students list
// by the given first name
void find_fn()
{
    char a[50];
    printf("Enter the First Name"
           " of the student\n");
    a = "Rahul";
    int c = 0;
 
    // Iterating through the students list
    for (int j = 0; j <= i; j++) {
 
        // Compare the first names
        if (!strcmp(st[j].fname, a)) {
 
            printf(
                "The Students Details are\n");
            printf(
                "The First name is %s\n",
                st[j].fname);
            printf(
                "The Last name is %s\n",
                st[j].lname);
            printf(
                "The Roll Number is %d\n ",
                st[j].roll);
            printf(
                "The CGPA is %f\n",
                st[j].cgpa);
            printf("Enter the course ID "
                   "of each course\n");
 
            // Print the course ID's
            for (int k = 0; k < 5; k++) {
                printf(
                    "The course ID are %d\n",
                    st[j].cid[k]);
            }
            c = 1;
        }
    }
}


Find registered student




// Function to find all the students
// who have registered for a given course
void find_c()
{
    int id;
    printf("Enter the course ID \n");
 
    // Course ID
    id = 1;
    int c = 0;
 
    // Iterating through the students list
    for (int j = 0; j <= i; j++) {
 
        // Checking if the student
        // has registered in the
        // given course or not
        for (int d = 0; d < 5; d++) {
            if (id == st[j].cid[d]) {
 
                printf(
                    "The Students Details are\n");
                printf(
                    "The First name is %s\n",
                    st[j].fname);
                printf(
                    "The Last name is %s\n",
                    st[j].lname);
                printf(
                    "The Roll Number is %d\n ",
                    st[j].roll);
                printf(
                    "The CGPA is %f\n",
                    st[j].cgpa);
 
                c = 1;
                break;
            }
        }
    }
}


Count




// Function to print the
// total number of students
void tot_s()
{
    printf("The total number of"
           " Student is %d\n",
           i);
    printf("\n you can have a "
           "max of 50 students\n");
    printf("you can have %d more"
           " students\n",
           50 - i);
}


Delete




// Function to delete a student
// by the roll number
void del_s()
{
    int a;
    printf("Enter the Roll Number"
           " which you want to delete\n");
    a = 1;
 
    // Iterating through the list and
    // find the student with the given
    // roll number
    for (int j = 0; j <= i; j++) {
        if (a == st[j].roll) {
            for (int k = j; k < 49; k++)
                st[k] = st[k + 1];
            i--;
        }
    }
    printf("The Roll Number is "
           "removed Successfully\n");
}


Update




// Function to update the
// details of the student
void up_s()
{
 
    printf("Enter the roll number"
           " to update the entry: ");
    long int x;
    x = 1;
    for (int j = 0; j < i; j++) {
        if (st[j].roll == x) {
 
            printf("1. first name\n"
                   "2. last name\n"
                   "3. roll no.\n"
                   "4. CGPA\n"
                   "5. courses\n");
            int z;
 
            // Updating the CGPA
            z = 4;
            switch (z) {
            case 1:
                printf("Enter the new
 first name : \n");
                scanf("%s", st[j].fname);
                break;
            case 2:
                printf("Enter the new
 last name : \n");
                scanf("%s", st[j].lname);
                break;
            case 3:
                printf("Enter the new
 roll number : \n");
                scanf("%d", &st[j].roll);
                break;
            case 4:
                printf("Enter the new CGPA : \n");
                st[j].cgpa = 9;
                break;
            case 5:
                printf("Enter the new courses \n");
                scanf("%d%d%d%d%d", &st[j].cid[0],
                      &st[j].cid[1], &st[j].cid[2],
                      &st[j].cid[3], &st[j].cid[4]);
                break;
            }
            printf("UPDATED SUCCESSFULLY.\n");
        }
    }
}


Below is the implementation of the above approach: 

C




// C program for the implementation of
// menu driven program for student
// management system
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
// Variable to keep track of
// number of students
int i = 0;
 
// Structure to store the student
struct sinfo {
    char fname[50];
    char lname[50];
    int roll;
    float cgpa;
    int cid[10];
} st[55];
 
// Function to add the student
void add_student()
{
 
    printf("Add the Students Details\n");
    printf("-------------------------\n");
    printf("Enter the first "
           "name of student\n");
    scanf("%s", st[i].fname);
    printf("Enter the last name"
           " of student\n");
    scanf("%s", st[i].lname);
    printf("Enter the Roll Number\n");
    scanf("%d", &st[i].roll);
    printf("Enter the CGPA "
           "you obtained\n");
    scanf("%f", &st[i].cgpa);
    printf("Enter the course ID"
           " of each course\n");
    for (int j = 0; j < 5; j++) {
        scanf("%d", &st[i].cid[j]);
    }
    i = i + 1;
}
 
// Function to find the student
// by the roll number
void find_rl()
{
    int x;
    printf("Enter the Roll Number"
           " of the student\n");
    scanf("%d", &x);
    for (int j = 1; j <= i; j++) {
        if (x == st[i].roll) {
            printf(
                "The Students Details are\n");
            printf(
                "The First name is %s\n",
                st[i].fname);
            printf(
                "The Last name is %s\n",
                st[i].lname);
            printf(
                "The CGPA is %f\n",
                st[i].cgpa);
            printf(
                "Enter the course ID"
                " of each course\n");
        }
        for (int j = 0; j < 5; j++) {
            printf(
                "The course ID are %d\n",
                st[i].cid[j]);
        }
        break;
    }
}
 
// Function to find the student
// by the first name
void find_fn()
{
    char a[50];
    printf("Enter the First Name"
           " of the student\n");
    scanf("%s", a);
    int c = 0;
 
    for (int j = 1; j <= i; j++) {
        if (!strcmp(st[j].fname, a)) {
 
            printf(
                "The Students Details are\n");
            printf(
                "The First name is %s\n",
                st[i].fname);
            printf(
                "The Last name is %s\n",
                st[i].lname);
            printf(
                "The Roll Number is %d\n ",
                st[i].roll);
            printf(
                "The CGPA is %f\n",
                st[i].cgpa);
            printf(
                "Enter the course ID of each course\n");
 
            for (int j = 0; j < 5; j++) {
                printf(
                    "The course ID are %d\n",
                    st[i].cid[j]);
            }
            c = 1;
        }
        else
            printf(
                "The First Name not Found\n");
    }
}
 
// Function to find
// the students enrolled
// in a particular course
void find_c()
{
    int id;
    printf("Enter the course ID \n");
    scanf("%d", &id);
    int c = 0;
 
    for (int j = 1; j <= i; j++) {
        for (int d = 0; d < 5; d++) {
            if (id == st[j].cid[d]) {
 
                printf(
                    "The Students Details are\n");
                printf(
                    "The First name is %s\n",
                    st[i].fname);
                printf(
                    "The Last name is %s\n",
                    st[i].lname);
                printf(
                    "The Roll Number is %d\n ",
                    st[i].roll);
                printf(
                    "The CGPA is %f\n",
                    st[i].cgpa);
 
                c = 1;
 
                break;
            }
            else
                printf(
                    "The First Name not Found\n");
        }
    }
}
 
// Function to print the total
// number of students
void tot_s()
{
    printf("The total number of"
           " Student is %d\n",
           i);
    printf("\n you can have a "
           "max of 50 students\n");
    printf("you can have %d "
           "more students\n",
           50 - i);
}
 
// Function to delete a student
// by the roll number
void del_s()
{
    int a;
    printf("Enter the Roll Number"
           " which you want "
           "to delete\n");
    scanf("%d", &a);
    for (int j = 1; j <= i; j++) {
        if (a == st[j].roll) {
            for (int k = j; k < 49; k++)
                st[k] = st[k + 1];
            i--;
        }
    }
    printf("The Roll Number"
           " is removed Successfully\n");
}
 
// Function to update a students data
void up_s()
{
 
    printf("Enter the roll number"
           " to update the entry : ");
    long int x;
    scanf("%ld", &x);
    for (int j = 0; j < i; j++) {
        if (st[j].roll == x) {
            printf("1. first name\n"
                   "2. last name\n"
                   "3. roll no.\n"
                   "4. CGPA\n"
                   "5. courses\n");
            int z;
            scanf("%d", &z);
            switch (z) {
            case 1:
                printf("Enter the new "
                       "first name : \n");
                scanf("%s", st[j].fname);
                break;
            case 2:
                printf("Enter the new "
                       "last name : \n");
                scanf("%s", st[j].lname);
                break;
            case 3:
                printf("Enter the new "
                       "roll number : \n");
                scanf("%d", &st[j].roll);
                break;
            case 4:
                printf("Enter the new CGPA : \n");
                scanf("%f", &st[j].cgpa);
                break;
            case 5:
                printf("Enter the new courses \n");
                scanf(
                    "%d%d%d%d%d", &st[j].cid[0],
                    &st[j].cid[1], &st[j].cid[2],
                    &st[j].cid[3], &st[j].cid[4]);
                break;
            }
            printf("UPDATED SUCCESSFULLY.\n");
        }
    }
}
 
// Driver code
void main()
 
{
    int choice, count;
    while (i = 1) {
        printf("The Task that you "
               "want to perform\n");
        printf("1. Add the Student Details\n");
        printf("2. Find the Student "
               "Details by Roll Number\n");
        printf("3. Find the Student "
               "Details by First Name\n");
        printf("4. Find the Student "
               "Details by Course Id\n");
        printf("5. Find the Total number"
               " of Students\n");
        printf("6. Delete the Students Details"
               " by Roll Number\n");
        printf("7. Update the Students Details"
               " by Roll Number\n");
        printf("8. To Exit\n");
        printf("Enter your choice to "
               "find the task\n");
        scanf("%d", &choice);
        switch (choice) {
        case 1:
            add_student();
            break;
        case 2:
            find_rl();
            break;
        case 3:
            find_fn();
            break;
        case 4:
            find_c();
            break;
        case 5:
            tot_s();
            break;
        case 6:
            del_s();
            break;
        case 7:
            up_s();
            break;
        case 8:
            exit(0);
            break;
        }
    }
}


Output:The Task that you want to perform 1. Add the Student Details 2. Find the Student Details by Roll Number 3. Find the Student Details by First Name 4. Find the Student Details by Course Id 5. Find the Total number of Students 6. Delete the Students Details by Roll Number 7. Update the Students Details by Roll Number 8. TO Exit Enter your choice to find the task 1 Add the Students Details ————————- Enter the first name of student Rahul Enter the last name of student Kumar Enter the Roll Number 1 Enter the CGPA you obtained 8 Enter the course ID of each course 1 2 3 4 5 The Task that you want to perform 1. Add the Student Details 2. Find the Student Details by Roll Number 3. Find the Student Details by First Name 4. Find the Student Details by Course Id 5. Find the Total number of Students 6. Delete the Students Details by Roll Number 7. Update the Students Details by Roll Number 8. TO Exit Enter your choice to find the task 2 Enter the Roll Number of the student 1 The Students Details are The First name is Rahul The Last name is Kumar The CGPA is 8.000000 Enter the course ID of each course The course ID are 1 The course ID are 2 The course ID are 3 The course ID are 4 The course ID are 5 The Task that you want to perform 1. Add the Student Details 2. Find the Student Details by Roll Number 3. Find the Student Details by First Name 4. Find the Student Details by Course Id 5. Find the Total number of Students 6. Delete the Students Details by Roll Number 7. Update the Students Details by Roll Number 8. TO Exit Enter your choice to find the task 3 Enter the First Name of the student Rahul The Students Details are The First name is Rahul The Last name is Kumar The Roll Number is 1 The CGPA is 8.000000 Enter the course ID of each course The course ID are 1 The course ID are 2 The course ID are 3 The course ID are 4 The course ID are 5 The Task that you want to perform 1. Add the Student Details 2. Find the Student Details by Roll Number 3. Find the Student Details by First Name 4. Find the Student Details by Course Id 5. Find the Total number of Students 6. Delete the Students Details by Roll Number 7. Update the Students Details by Roll Number 8. TO Exit Enter your choice to find the task 4 Enter the course ID 1 The Students Details are The First name is Rahul The Last name is Kumar The Roll Number is 1 The CGPA is 8.000000 The Task that you want to perform 1. Add the Student Details 2. Find the Student Details by Roll Number 3. Find the Student Details by First Name 4. Find the Student Details by Course Id 5. Find the Total number of Students 6. Delete the Students Details by Roll Number 7. Update the Students Details by Roll Number 8. TO Exit Enter your choice to find the task 5 The total number of Student is 1 you can have a max of 50 students you can have 49 more students The Task that you want to perform 1. Add the Student Details 2. Find the Student Details by Roll Number 3. Find the Student Details by First Name 4. Find the Student Details by Course Id 5. Find the Total number of Students 6. Delete the Students Details by Roll Number 7. Update the Students Details by Roll Number 8. TO Exit Enter your choice to find the task 6 Enter the Roll Number which you want to delete 1 The Roll Number is removed Successfully The Task that you want to perform 1. Add the Student Details 2. Find the Student Details by Roll Number 3. Find the Student Details by First Name 4. Find the Student Details by Course Id 5. Find the Total number of Students 6. Delete the Students Details by Roll Number 7. Update the Students Details by Roll Number 8. TO Exit Enter your choice to find the task 2 Enter the Roll Number of the student 1 The course ID are 0 The course ID are 0 The course ID are 0 The course ID are 0 The course ID are 0 The Task that you want to perform 1. Add the Student Details 2. Find the Student Details by Roll Number 3. Find the Student Details by First Name 4. Find the Student Details by Course Id 5. Find the Total number of Students 6. Delete the Students Details by Roll Number 7. Update the Students Details by Roll Number 8. TO Exit Enter your choice to find the task 8


Last Updated : 24 Mar, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads