C Programming
Student Management Complete Application Using C Programming
- Introduction
- Program Structure
- Key Concepts
- Conclusion
- Lets start building the application
- Let’s Start Building the Application
- Complete Example Source Code
- Output Demo
¶Introduction
In this article, we’ll delve into a comprehensive example of a student management system implemented in the C programming language. This program allows users to manage a list of students, record their grades, search for students, and display relevant information. It serves as an excellent illustration of struct usage, file organization, and the implementation of a menu-driven console application.
¶Program Structure
¶Header and Definitions
The program begins with including the necessary header files and defining constants. The MAX_STUDENTS
and MAX_SUBJECTS
constants determine the maximum number of students and subjects, respectively. The structure Student
is defined to store student information, including their name, roll number, and grades.
¶Main Function
The main
function initializes an array of Student
structures, students
, and tracks the number of students using the numStudents
variable. It enters a loop where the user is presented with a menu of options, and the chosen option is executed through a switch statement.
¶Menu-Driven Options
-
Add New Student: This option prompts the user to enter details for a new student, including their name, roll number, and initializes their grades. The information is stored in the
students
array. -
Record Grades: Users can record grades for a specific student by entering the student’s roll number. The program then prompts the user to enter grades for each subject.
-
Display Grades: Users can view the grades of a specific student by providing the student’s roll number. The program displays the grades for each subject along with the student’s name.
-
Search Student: Users can search for a student either by roll number or name. The program displays relevant information if the student is found.
-
Modify Grades: Users can modify the grades of a specific student by entering the student’s roll number. The program prompts the user to enter new grades for each subject.
-
Display Students: This option displays a list of all students along with their names, roll numbers, grades for each subject, average, and GPA (Grade Point Average).
-
Exit: The program exits the loop and terminates.
¶Functions
The program includes several functions for specific tasks, such as adding a new student (addNewStudent
), recording grades (recordGrades
), displaying grades (displayGrades
), searching for a student (searchStudent
), modifying grades (modifyGrades
), and displaying the list of students (displayStudents
).
¶Key Concepts
¶1. Structs in C
The program utilizes structs to encapsulate student information. The Student
struct bundles related data (name, roll number, and grades) into a single unit.
¶2. Functions and Modularization
Functions are employed to modularize the code, making it more readable and maintainable. Each function handles a specific task, such as adding a student or displaying grades.
¶3. File Organization
The program is well-organized into sections, with the main function controlling the flow of the program. This aids in readability and understanding.
¶4. Menu-Driven Interface
The menu-driven approach enhances user interaction. Users can easily navigate through various options to perform specific tasks.
¶Conclusion
This student management system in C provides a practical example for understanding key programming concepts, including structs, functions, modularization, and file organization. It serves as a foundation for developing more complex systems and is a valuable resource for students learning the C programming language.
¶Lets start building the application
¶Let’s Start Building the Application
Now that we have a broad understanding of the student management system in C, let’s delve into each method, step by step, and explore how they contribute to the functionality of our program. This breakdown will help novice C programmers grasp the implementation details.
¶1. addNewStudent
Function
The addNewStudent
function is responsible for adding a new student to the system. It begins by checking if the maximum number of students has been reached. If not, it increments the numStudents
variable and proceeds to collect details for the new student.
void addNewStudent(struct Student students[], int *numStudents) {
if (*numStudents < MAX_STUDENTS) {
printf("Enter the details for the new student:\n");
// Increment the number of students
(*numStudents)++;
// Get the details from the user
printf("Name: ");
scanf("%s", students[*numStudents - 1].name);
printf("Roll Number: ");
scanf("%d", &students[*numStudents - 1].rollNumber);
// Initialize grades to -1 (indicating not yet recorded)
for (int i = 0; i < MAX_SUBJECTS; i++) {
students[*numStudents - 1].grades[i] = -1;
}
printf("Student added successfully!\n");
} else {
printf("Maximum number of students reached!\n");
}
}
In this function:
- The
numStudents
pointer is dereferenced and incremented, ensuring we add the new student at the correct index in thestudents
array. - User input is collected for the student’s name and roll number using
scanf
. - Grades are initialized to -1 for each subject, indicating that they haven’t been recorded yet.
¶2. recordGrades
Function
The recordGrades
function allows users to record grades for a specific student. It prompts the user for the student’s roll number and then records grades for each subject.
void recordGrades(struct Student students[], int numStudents) {
int rollNumber;
printf("Enter the roll number of the student: ");
scanf("%d", &rollNumber);
// Search for the student
int studentIndex = -1;
for (int i = 0; i < numStudents; i++) {
if (students[i].rollNumber == rollNumber) {
studentIndex = i;
break;
}
}
if (studentIndex != -1) {
printf("Enter grades for the student (subject-wise):\n");
for (int i = 0; i < MAX_SUBJECTS; i++) {
printf("Subject %d: ", i + 1);
scanf("%d", &students[studentIndex].grades[i]);
}
printf("Grades recorded successfully for student %s!\n", students[studentIndex].name);
} else {
printf("Student not found!\n");
}
}
In this function:
- The user is prompted for the roll number of the student whose grades they want to record.
- The program searches for the student in the
students
array based on the entered roll number. - If the student is found, the program prompts the user to enter grades for each subject.
¶3. displayGrades
Function
The displayGrades
function allows users to view the grades of a specific student. Similar to the recordGrades
function, it prompts the user for the student’s roll number and then displays the grades.
void displayGrades(struct Student students[], int numStudents) {
int rollNumber;
printf("Enter the roll number of the student: ");
scanf("%d", &rollNumber);
// Search for the student
int studentIndex = -1;
for (int i = 0; i < numStudents; i++) {
if (students[i].rollNumber == rollNumber) {
studentIndex = i;
break;
}
}
if (studentIndex != -1) {
printf("\nGrades for student %s (Roll Number: %d):\n", students[studentIndex].name, students[studentIndex].rollNumber);
for (int i = 0; i < MAX_SUBJECTS; i++) {
printf("Subject %d: %d\n", i + 1, students[studentIndex].grades[i]);
}
printf("\n");
} else {
printf("Student not found!\n");
}
}
In this function:
- The user is prompted for the roll number of the student whose grades they want to display.
- The program searches for the student in the
students
array based on the entered roll number. - If the student is found, the program displays the grades for each subject.
¶4. searchStudent
Function
The searchStudent
function allows users to search for a student by either roll number or name. It provides flexibility in finding student information based on user preference.
void searchStudent(struct Student students[], int numStudents) {
int choice;
printf("Search student by:\n");
printf("1. Roll Number\n");
printf("2. Name\n");
printf("Enter your choice: ");
scanf("%d", &choice);
if (choice == 1) {
int rollNumber;
printf("Enter the roll number of the student: ");
scanf("%d", &rollNumber);
// Search for the student
int studentIndex = -1;
for (int i = 0; i < numStudents; i++) {
if (students[i].rollNumber == rollNumber) {
studentIndex = i;
break;
}
}
if (studentIndex != -1) {
printf("Student found!\n");
printf("Name: %s, Roll Number: %d\n", students[studentIndex].name, students[studentIndex].rollNumber);
} else {
printf("Student not found!\n");
}
} else if (choice == 2) {
char name[50];
printf("Enter the name of the student: ");
scanf("%s", name);
// Search for the student
int studentIndex = -1;
for (int i = 0; i < numStudents; i++) {
if (strcmp(students[i].name, name) == 0) {
studentIndex = i;
break;
}
}
if (studentIndex != -1) {
printf("Student found!\n");
printf("Name: %s, Roll Number: %d\n", students[studentIndex].name, students[studentIndex].rollNumber);
} else {
printf("Student not found!\n");
}
} else {
printf("Invalid choice. Please enter a valid option.\n");
}
}
In this function:
- The user is presented with options to search by roll number or name.
- Based on the chosen option, the program prompts the user for the relevant information (roll number or name).
- It then searches for the student in the
students
array and displays the information if the student is found.
¶5.
modifyGrades
Function
The modifyGrades
function allows users to modify the grades of a specific student. It follows a similar pattern to the recordGrades
function but updates the existing grades.
void modifyGrades(struct Student students[], int numStudents) {
int rollNumber;
printf("Enter the roll number of the student: ");
scanf("%d", &rollNumber);
// Search for the student
int studentIndex = -1;
for (int i = 0; i < numStudents; i++) {
if (students[i].rollNumber == rollNumber) {
studentIndex = i;
break;
}
}
if (studentIndex != -1) {
printf("Enter the new grades for the student (subject-wise):\n");
for (int i = 0; i < MAX_SUBJECTS; i++) {
printf("Subject %d: ", i + 1);
scanf("%d", &students[studentIndex].grades[i]);
}
printf("Grades modified successfully for student %s!\n", students[studentIndex].name);
} else {
printf("Student not found!\n");
}
}
In this function:
- The user is prompted for the roll number of the student whose grades they want to modify.
- The program searches for the student in the
students
array based on the entered roll number. - If the student is found, the program prompts the user to enter new grades for each subject.
¶6. displayStudents
Function
The displayStudents
function provides a comprehensive view of all students, including their names, roll numbers, grades for each subject, average, and GPA.
void displayStudents(struct Student students[], int numStudents) {
printf("\nList of Students:\n");
for (int i = 0; i < numStudents; i++) {
printf("Name: %s, Roll Number: %d\n", students[i].name, students[i].rollNumber);
// Display grades and average
printf("Grades:\n");
for (int j = 0; j < MAX_SUBJECTS; j++) {
float grade = students[i].grades[j];
if (grade > 0) {
printf("Subject %d: %.2f\n", j + 1, grade);
} else {
printf("Subject %d: %s\n", j + 1, "N/A");
}
}
// Calculate and display average
int sum = 0;
for (int j = 0; j < MAX_SUBJECTS; j++) {
sum += students[i].grades[j];
}
float average = (float)sum / MAX_SUBJECTS;
if (average > 0) {
printf("Average: %.2f\n", average);
} else {
printf("Average: %s\n", "N/A");
}
// Calculate and display GPA
float gpa = 0.0;
for (int j = 0; j < MAX_SUBJECTS; j++) {
float grade = students[i].grades[j];
if (grade >= 80) {
gpa += 4.0;
} else if (grade >= 70) {
gpa += 3.0;
} else if (grade >= 60) {
gpa += 2.0;
} else if (grade >= 50) {
gpa += 1.0;
}
}
gpa /= MAX_SUBJECTS;
printf("GPA: %.2f\n", gpa);
printf("\n");
}
}
In this function:
- The program iterates through the
students
array and displays the name and roll number for each student. - It then displays the grades for each subject and calculates the average and GPA based on specific criteria.
So, By breaking down each function of our student management system, we've provided a detailed walkthrough for novice C programmers. These functions collectively enable the program to manage student data effectively.
Understanding each part contributes to a better grasp of C programming concepts, including structs, functions, loops, and conditional statements. As you explore and modify this program, you'll gain practical experience in building console-based applications in C.
¶Complete Example Source Code
#include <stdio.h>
// Define the maximum number of students
#define MAX_STUDENTS 50
// Define the maximum number of subjects
#define MAX_SUBJECTS 5
// Define the structure for a student
struct Student {
char name[50];
int rollNumber;
int grades[MAX_SUBJECTS];
};
// Function to add a new student
void addNewStudent(struct Student students[], int *numStudents) {
if (*numStudents < MAX_STUDENTS) {
printf("Enter the details for the new student:\n");
// Increment the number of students
(*numStudents)++;
// Get the details from the user
printf("Name: ");
scanf("%s", students[*numStudents - 1].name);
printf("Roll Number: ");
scanf("%d", &students[*numStudents - 1].rollNumber);
// Initialize grades to -1 (indicating not yet recorded)
for (int i = 0; i < MAX_SUBJECTS; i++) {
students[*numStudents - 1].grades[i] = -1;
}
printf("Student added successfully!\n");
} else {
printf("Maximum number of students reached!\n");
}
}
// Function to record grades for a student
void recordGrades(struct Student students[], int numStudents) {
int rollNumber, subject;
printf("Enter the roll number of the student: ");
scanf("%d", &rollNumber);
// Search for the student
int studentIndex = -1;
for (int i = 0; i < numStudents; i++) {
if (students[i].rollNumber == rollNumber) {
studentIndex = i;
break;
}
}
if (studentIndex != -1) {
printf("Enter grades for the student (subject-wise):\n");
for (int i = 0; i < MAX_SUBJECTS; i++) {
printf("Subject %d: ", i + 1);
scanf("%d", &students[studentIndex].grades[i]);
}
printf("Grades recorded successfully for student %s!\n", students[studentIndex].name);
} else {
printf("Student not found!\n");
}
}
// Function to display grades for a student
void displayGrades(struct Student students[], int numStudents) {
int rollNumber;
printf("Enter the roll number of the student: ");
scanf("%d", &rollNumber);
// Search for the student
int studentIndex = -1;
for (int i = 0; i < numStudents; i++) {
if (students[i].rollNumber == rollNumber) {
studentIndex = i;
break;
}
}
if (studentIndex != -1) {
printf("\nGrades for student %s (Roll Number: %d):\n", students[studentIndex].name, students[studentIndex].rollNumber);
for (int i = 0; i < MAX_SUBJECTS; i++) {
printf("Subject %d: %d\n", i + 1, students[studentIndex].grades[i]);
}
printf("\n");
} else {
printf("Student not found!\n");
}
}
// Function to search for a student by roll number or name
void searchStudent(struct Student students[], int numStudents) {
int choice;
printf("Search student by:\n");
printf("1. Roll Number\n");
printf("2. Name\n");
printf("Enter your choice: ");
scanf("%d", &choice);
if (choice == 1) {
int rollNumber;
printf("Enter the roll number of the student: ");
scanf("%d", &rollNumber);
// Search for the student
int studentIndex = -1;
for (int i = 0; i < numStudents; i++) {
if (students[i].rollNumber == rollNumber) {
studentIndex = i;
break;
}
}
if (studentIndex != -1) {
printf("Student found!\n");
printf("Name: %s, Roll Number: %d\n", students[studentIndex].name, students[studentIndex].rollNumber);
} else {
printf("Student not found!\n");
}
} else if (choice == 2) {
char name[50];
printf("Enter the name of the student: ");
scanf("%s", name);
// Search for the student
int studentIndex = -1;
for (int i = 0; i < numStudents; i++) {
if (strcmp(students[i].name, name) == 0) {
studentIndex = i;
break;
}
}
if (studentIndex != -1) {
printf("Student found!\n");
printf("Name: %s, Roll Number: %d\n", students[studentIndex].name, students[studentIndex].rollNumber);
} else {
printf("Student not found!\n");
}
} else {
printf("Invalid choice. Please enter a valid option.\n");
}
}
// Function to modify grades for a student
void modifyGrades(struct Student students[], int numStudents) {
int rollNumber;
printf("Enter the roll number of the student: ");
scanf("%d", &rollNumber);
// Search for the student
int studentIndex = -1;
for (int i = 0; i < numStudents; i++) {
if (students[i].rollNumber == rollNumber) {
studentIndex = i;
break;
}
}
if (studentIndex != -1) {
printf("Enter the new grades for the student (subject-wise):\n");
for (int i = 0; i < MAX_SUBJECTS; i++) {
printf("Subject %d: ", i + 1);
scanf("%d", &students[studentIndex].grades[i]);
}
printf("Grades modified successfully for student %s!\n", students[studentIndex].name);
} else {
printf("Student not found!\n");
}
}
// Function to display the list of students
void displayStudents(struct Student students[], int numStudents) {
printf("\nList of Students:\n");
for (int i = 0; i < numStudents; i++) {
printf("Name: %s, Roll Number: %d\n", students[i].name, students[i].rollNumber);
// Display grades and average
printf("Grades:\n");
for (int j = 0; j < MAX_SUBJECTS; j++) {
float grade = students[i].grades[j];
if (grade > 0) {
printf("Subject %d: %.2f\n", j + 1, grade);
} else {
printf("Subject %d: %s\n", j + 1, "N/A");
}
}
// Calculate and display average
int sum = 0;
for (int j = 0; j < MAX_SUBJECTS; j++) {
sum += students[i].grades[j];
}
float average = (float)sum / MAX_SUBJECTS;
if (average > 0) {
printf("Average: %.2f\n", average);
} else {
printf("Average: %.2f\n", "N/A");
}
// Calculate and display GPA
float gpa = 0.0;
for (int j = 0; j < MAX_SUBJECTS; j++) {
float grade = students[i].grades[j];
if (grade >= 80) {
gpa += 4.0;
} else if (grade >= 70) {
gpa += 3.0;
} else if (grade >= 70) {
gpa += 2.0;
} else if (grade >= 60) {
gpa += 1.0;
}
}
gpa /= MAX_SUBJECTS;
printf("GPA: %.2f\n", gpa);
printf("\n");
}
}
int main() {
struct Student students[MAX_STUDENTS];
int numStudents = 0;
int choice;
do {
// Display menu
printf("Menu:\n");
printf("1. Add New Student\n");
printf("2. Record Grades\n");
printf("3. Display Grades\n");
printf("4. Search Student\n");
printf("5. Modify Grades\n");
printf("6. Display Students\n");
printf("7. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
addNewStudent(students, &numStudents);
break;
case 2:
recordGrades(students, numStudents);
break;
case 3:
displayGrades(students, numStudents);
break;
case 4:
searchStudent(students, numStudents);
break;
case 5:
modifyGrades(students, numStudents);
break;
case 6:
displayStudents(students, numStudents);
break;
case 7:
printf("Exiting program.\n");
break;
default:
printf("Invalid choice. Please enter a valid option.\n");
}
} while (choice != 7);
return 0;
}
¶Output Demo
To illustrate the functionality of the student management system, let’s walk through a demo of the program. We’ll showcase key features, including adding a new student, recording and displaying grades, searching for a student, modifying grades, and displaying the list of students.
¶1. Adding a New Student
Let’s start by adding a new student to the system. The user is prompted to enter details such as the student’s name and roll number.
Menu:
1. Add New Student
2. Record Grades
3. Display Grades
4. Search Student
5. Modify Grades
6. Display Students
7. Exit
Enter your choice: 1
Enter the details for the new student:
Name: Akash
Roll Number: 101
Student added successfully!
¶2. Recording Grades
Now, let’s record grades for the student we just added. The user enters the roll number of the student and then provides grades for each subject.
Menu:
1. Add New Student
2. Record Grades
3. Display Grades
4. Search Student
5. Modify Grades
6. Display Students
7. Exit
Enter your choice: 2
Enter the roll number of the student: 101
Enter grades for the student (subject-wise):
Subject 1: 85
Subject 2: 78
Subject 3: 92
Subject 4: 88
Subject 5: 90
Grades recorded successfully for student Akash!
¶3. Displaying Grades
Let’s now display the grades for the student with roll number 101.
Menu:
1. Add New Student
2. Record Grades
3. Display Grades
4. Search Student
5. Modify Grades
6. Display Students
7. Exit
Enter your choice: 3
Enter the roll number of the student: 101
Grades for student Akash (Roll Number: 101):
Subject 1: 85
Subject 2: 78
Subject 3: 92
Subject 4: 88
Subject 5: 90
¶4. Searching for a Student
Now, let’s search for a student, both by roll number and by name.
¶Search by Roll Number
Menu:
1. Add New Student
2. Record Grades
3. Display Grades
4. Search Student
5. Modify Grades
6. Display Students
7. Exit
Enter your choice: 4
Search student by:
1. Roll Number
2. Name
Enter your choice: 1
Enter the roll number of the student: 101
Student found!
Name: Akash, Roll Number: 101
¶Search by Name
Menu:
1. Add New Student
2. Record Grades
3. Display Grades
4. Search Student
5. Modify Grades
6. Display Students
7. Exit
Enter your choice: 4
Search student by:
1. Roll Number
2. Name
Enter your choice: 2
Enter the name of the student: Akash
Student found!
Name: Akash, Roll Number: 101
¶5. Modifying Grades
Let’s modify the grades for the student with roll number 101.
Menu:
1. Add New Student
2. Record Grades
3. Display Grades
4. Search Student
5. Modify Grades
6. Display Students
7. Exit
Enter your choice: 5
Enter the roll number of the student: 101
Enter the new grades for the student (subject-wise):
Subject 1: 90
Subject 2: 85
Subject 3: 94
Subject 4: 91
Subject 5: 89
Grades modified successfully for student Akash!
¶6. Displaying Students
Finally, let’s display the list of all students, including their names, roll numbers, grades, average, and GPA.
Menu:
1. Add New Student
2. Record Grades
3. Display Grades
4. Search Student
5. Modify Grades
6. Display Students
7. Exit
Enter your choice: 6
List of Students:
Name: Akash, Roll Number: 101
Grades:
Subject 1: 90
Subject 2: 85
Subject 3: 94
Subject 4: 91
Subject 5: 89
Average: 89.80
GPA: 3.80
This output demo provides a glimpse into the functionality of the student management system. Users can seamlessly add, record, display, search, modify, and view a comprehensive list of students and their academic information. The modular structure of the program facilitates an intuitive user experience, making it a valuable tool for managing student data.
¶Tags:
Understanding and Building a Student Management System in C, Student Management Complete Project Complete Application Using C, C programming example, Student management in C, C Student Management application, C applicaiton, online c application, online c learning, c example, c programming, programming, student management system, c programming, example more, c example, c learning, c complete project, c project idea, c project demo
Pointer in C Programming Language with Practical Examples
C Project - Complete Calculator Application using C Programming
All Tutorials in this playlist
Popular Tutorials
Categories
-
Artificial Intelligence (AI)
11
-
Bash Scripting
1
-
Bootstrap CSS
0
-
C Programming
14
-
C#
0
-
ChatGPT
1
-
Code Editor
2
-
Computer Engineering
3
-
CSS
28
-
Data Structure and Algorithm
18
-
Design Pattern in PHP
2
-
Design Patterns - Clean Code
1
-
E-Book
1
-
Git Commands
1
-
HTML
19
-
Interview Prepration
2
-
Java Programming
0
-
JavaScript
12
-
Laravel PHP Framework
37
-
Mysql
1
-
Node JS
1
-
Online Business
0
-
PHP
28
-
Programming
8
-
Python
12
-
React Js
19
-
React Native
1
-
Redux
2
-
Rust Programming
15
-
SEO - Search Engine Optimization
1
-
Tailwind CSS
1
-
Typescript
10
-
Uncategorized
0
-
Vue JS
1
-
Windows Operating system
1
-
Woocommerce
1
-
WordPress Development
2
Tags
- Artificial Intelligence (AI)
- Bash Scripting
- Business
- C
- C Programming
- C-sharp programming
- C++
- Code Editor
- Computer Engineering
- CSS
- Data Structure and Algorithm
- Database
- Design pattern
- Express JS
- git
- Git Commands
- github
- HTML
- Java
- JavaScript
- Laravel
- Mathematics
- MongoDB
- Mysql
- Node JS
- PHP
- Programming
- Python
- React Js
- Redux
- Rust Programming Language
- SEO
- TypeScript
- Vue JS
- Windows terminal
- Woocommerce
- WordPress
- WordPress Plugin Development