C Project - Complete Calculator Application using C Programming
- Author Maniruzzaman Akash
- Published April 23, 2024
- Word count 1,194
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.
Full source code in C Programming
#include
// 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;
}
Check the below links to get the full article
I'm Maniruzzaman Akash. A Full stack Web Developer and a Programmer working 6+ years in this industry. I love to write articles on various programming technologies and make them easier for beginners.
You can read Full article with step by step source code here - https://devsenv.com/tutorials/c-programming-student-management-application-project
Article source: https://articlebiz.comRate article
Article comments
There are no posted comments.
Related articles
- “When the Camera Lies: The True Stories Behind Hollywood’s Greatest Myths.”
- The Weight of Deception: Unmasking False Promises in the Weight Loss Market.
- The Silent Saboteur: Unraveling the Health Risks of Being Overweight.
- “Chaos Behind the Camera: Legendary On-Set Feuds and Filmmaking Nightmares That Changed Hollywood Forever.”
- The Expanding Burden: How Excess Weight Reshapes Human Health
- “Alternate Reels: How Cinema Might Have Changed if History Rolled Differently.”
- ICCTA Successfully Completes Second Beijing International Week of Intangible Cultural Heritage
- Weight Loss Myths: The Hidden Truth Behind Why So Many People Struggle to Keep the Weight Off
- CNC Milling In The Prototype-To-Production Process: How It Speeds Up Product Development
- The Hidden Truth About Weight Loss: Why Your Body Resists and How to Work With It.
- “Francis Ford Coppola: Genius and Chaos in the Making of a Hollywood Legend.”
- Why the ARRI Alexa Mini Still Outnumbers Every 4K Flagship on Professional Sets
- Beyond the Scale: The Real Truth About Weight Loss and Weight Management.
- “Marlon Brando: The Actor Who Changed Hollywood Forever.”
- “The Genius and the Scandal: Woody Allen’s Films and the Shadows Behind Them.”
- Grounded Farmhouse Living: The Soul of Vintage Furniture
- “Leonardo DiCaprio: The Reluctant Star Who Redefined Hollywood Stardom.”
- The Grounded Bohemian Home: Hand-Painted Antique Doors & Vintage Furniture
- “Behind the Curtain: The Private World of Raymond Burr.”
- Cabin Decor: A Perfect Mountain Hideaway
- Vintage Carved Wood: Where Ancient Symbols Meet Vibrant Color
- “From Pixels to Projectors: How Video Games Reshaped Modern Cinema.”
- Zimbabwe News as a Catalyst: How Informed Journalism is Shaping a New African Reality
- Africa News and the Information Imperative: Forging an Informed Society in the Age of Misinformation
- Uganda News as a Microcosm: How Quality Journalism is Building an Informed African Society
- Kenya News: A Blueprint for an Informed Africa
- Ghana News and the Quest for an Informed Africa
- Nigeria News and the Heartbeat of an Informed Africa
- “The Art of the Slow Burn: Revisiting 1970s American Cinema.”
- Designing a Bedroom Around a Single Bed That Grows With Your Child