Student Management System Project in C Language

In this tutorial, we'll create a basic Student Management System using the C language. This project will help beginners understand the fundamentals of C, including structures, functions, and array manipulation. 

Overview 

The goal is to design a system that supports basic CRUD operations (Create, Read, Update, Delete) for student records. 

Features: 

  • Add a student's details 
  • Display all student details 
  • Update student details using roll number 
  • Delete a student using roll number 

Data Structure 

We will use a structure to define a student:

typedef struct {
    int roll_no;
    char name[50];
    float marks;
} Student;

Student Management System Project using C Language

We will utilize a menu-driven approach in the main function for the user to interact with our system. After compiling and running the code, the user can choose any operation by entering the corresponding number.

Creating a Student Record: We prompt the user to input the roll number, name, and marks. This information is then stored in our student's array.

Displaying All Student Records: We simply loop through the student's array and print each student's details.

Updating a Student's Record: The user provides a roll number, and we update the respective student's details if found.

Deleting a Student's Record: We find the student with the given roll number and shift all subsequent students up in the array to delete the record.

Here is the implementation of the Student Management System using the C language:

#include <stdio.h>
#include <string.h>

#define MAX_STUDENTS 100
#define NAME_LENGTH 50

typedef struct {
    int roll_no;
    char name[NAME_LENGTH];
    float marks;
} Student;

int currentIndex = 0;
Student students[MAX_STUDENTS];

void createStudent() {
    if (currentIndex < MAX_STUDENTS) {
        printf("Enter roll number: ");
        scanf("%d", &students[currentIndex].roll_no);
        
        printf("Enter name: ");
        scanf(" %[^\n]", students[currentIndex].name);
        
        printf("Enter marks: ");
        scanf("%f", &students[currentIndex].marks);
        
        currentIndex++;
    } else {
        printf("Database full!\n");
    }
}

void displayStudents() {
    for (int i = 0; i < currentIndex; i++) {
        printf("Roll Number: %d\n", students[i].roll_no);
        printf("Name: %s\n", students[i].name);
        printf("Marks: %.2f\n\n", students[i].marks);
    }
}

void updateStudent(int roll_no) {
    for (int i = 0; i < currentIndex; i++) {
        if (students[i].roll_no == roll_no) {
            printf("Enter new name: ");
            scanf(" %[^\n]", students[i].name);
            
            printf("Enter new marks: ");
            scanf("%f", &students[i].marks);
            
            return;
        }
    }
    printf("Student not found!\n");
}

void deleteStudent(int roll_no) {
    int index = -1;
    for (int i = 0; i < currentIndex; i++) {
        if (students[i].roll_no == roll_no) {
            index = i;
            break;
        }
    }
    if (index != -1) {
        for (int i = index; i < currentIndex - 1; i++) {
            students[i] = students[i + 1];
        }
        currentIndex--;
    } else {
        printf("Student not found!\n");
    }
}

int main() {
    int choice, roll_no;
    
    do {
        printf("\nStudent Management System:\n");
        printf("1. Add student\n");
        printf("2. Display all students\n");
        printf("3. Update student by roll number\n");
        printf("4. Delete student by roll number\n");
        printf("5. Exit\n");
        printf("Enter your choice: ");
        scanf("%d", &choice);
        
        switch (choice) {
            case 1:
                createStudent();
                break;
            case 2:
                displayStudents();
                break;
            case 3:
                printf("Enter roll number to update: ");
                scanf("%d", &roll_no);
                updateStudent(roll_no);
                break;
            case 4:
                printf("Enter roll number to delete: ");
                scanf("%d", &roll_no);
                deleteStudent(roll_no);
                break;
            case 5:
                break;
            default:
                printf("Invalid choice.\n");
        }
    } while (choice != 5);
    
    return 0;
}

We use a do-while loop to display a menu until the user chooses to exit. Inside this loop, a switch-case statement facilitates the selection of an appropriate operation. Each CRUD operation is handled by its own function, keeping the code modular and clean.

Output:

Student Management System:
1. Add student
2. Display all students
3. Update student by roll number
4. Delete student by roll number
5. Exit
Enter your choice: 1
Enter roll number: 100
Enter name: Ramesh
Enter marks: 45
Student Management System:
1. Add student
2. Display all students
3. Update student by roll number
4. Delete student by roll number
5. Exit
Enter your choice: 2
Roll Number: 100
Name: Ramesh
Marks: 45.00
Student Management System:
1. Add student
2. Display all students
3. Update student by roll number
4. Delete student by roll number
5. Exit
Enter your choice: 3
Enter roll number to update: 100
Enter new name: Ram
Enter new marks: 55
Student Management System:
1. Add student
2. Display all students
3. Update student by roll number
4. Delete student by roll number
5. Exit
Enter your choice: 4
Enter roll number to delete: 100
Student Management System:
1. Add student
2. Display all students
3. Update student by roll number
4. Delete student by roll number
5. Exit
Enter your choice: 
2
Student Management System:
1. Add student
2. Display all students
3. Update student by roll number
4. Delete student by roll number
5. Exit
Enter your choice: 2
Student Management System:
1. Add student
2. Display all students
3. Update student by roll number
4. Delete student by roll number
5. Exit
Enter your choice: 5

Conclusion 

This simple Student Management System provides a practical application of C language basics. While the system can be expanded with more features like search functionality or storage to a file, this base version is perfect for those just starting out with C. 

Happy coding! If you have questions or would like to see more features added, please leave a comment below.


Comments