The document outlines a Student Management System implemented in C, which allows for adding, viewing, and sorting student records based on average marks. It includes detailed pseudo code and program structure, utilizing structures, nested structures, and pointers for efficient data management. Additionally, it describes functionalities for managing student data, including file operations for saving and deleting records.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0 ratings0% found this document useful (0 votes)
22 views15 pages
CP Record
The document outlines a Student Management System implemented in C, which allows for adding, viewing, and sorting student records based on average marks. It includes detailed pseudo code and program structure, utilizing structures, nested structures, and pointers for efficient data management. Additionally, it describes functionalities for managing student data, including file operations for saving and deleting records.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 15
(An Autonomous Institution, Affiliated to Anna University, Chennai)
@ Meenakshi Sundararajan Engineering College
ae< 2408101 - Programming in C - Laboratory Component
Enter student ID: 101
Enter marks for 3 subjects
Subject 1: 85
Subject 2: 90
Subject 3: 78
Enter attendance percentage: 80
Student Management System
1. Add Student
2. View All Students
3, Sort Students by Average Marks
4, Exit
Enter your choice: 2
Student 1
Name: Alice
ID: 101
Marks
Subject 1: 85.00
Subject 2: 90.00
Subject 3: 78.00
Attendance: 80.00%
Average Marks: 84.33
Performance: Excellent
Attendance: Satisfactory
Student Management System
1. Add Student
2. View All Students
3, Sort Students by Average Marks
4. Exit
Enter your choice: 4
REAL TIME APPLICATION
1 Student Management System: Structures: Store student details like name, ID, and marks
Nested Structures: Include a department structure within the student structure. Pointers: Allow
efficient access to student records. Arrays: Manage multiple student records easily.
2 Inventory Management System: Structures; Define products with attributes like name,
quantity, and price. Nested Structures: Group related data, like supplier details. Pointers: Help in
updating product records dynamically. Arrays, Keep track of all items in inventory.
3.Employee Management System: Structures: Hold employee information such as name, 1D,
and salary. Nested Structures: Include department details within employee records. Pointers:
Facilitate efficient searching and sorting of employee data, Arrays: Store records for all
employees in a company.
4, Banking System: Structures: Represent customer accounts with details like account number
and balance. Nested Structures: Store additional info like transaction history. Pointers: Manage
account records dynamically. Arrays: Handle multiple customer accounts easily
Department:CSE/AT/AIDS MSEC R2024
PAGE NO 85Meenakshi Sundararajan Engineering College
(An Autonomous Institution, Affiliated to Anna University, Chennai)
—*
U24CS101 - Programming in C - Laboratory Component
if (students[i] average < students[j] average) {
// Swap students[i] and students|j)
temp = studentsfi];
students[i] = students[j];
students[j] = temp;
}
}
printf("\n Students have been sorted by their average marks \n");
}
1! Main function
int main() {
int choice;
while (1) {
printf("\n--- Student Management System ---\n"),
printf(" 1. Add Student\n’ ;
printf("2. View All Students\n");
printf("3. Sort Students by Average Marks\n’);
printf("4. Exit\n");
printf("Enter your choice: "),
scanf("%d", &choice);
switch (choice) {
case 1
addStudent();
break;
case 2:
display Students();
break,
case 3
sortStudentsByAverage();,
break:
case 4
return 0;
default:
printi(" Invalid choice! Please try again \n");
return 0;
}
OUTPUT:
~~ Student Management System —
1. Add Student
2. View All Students
3. Sort Students by Average Marks
4. Exit
Enter your choice: |
Enter student name: Alice
Department:CSE/IT/AIDS MSEC R2024
PAGE NO 84Meenakshi Sundararajan Engineering College
(An Autonomous Institution, Affiliated to Anna University, Chennai)
wot
U24CS101 - Programming in C - Laboratory Component
PSEUDO CODE:
DEFINE constants MAX_STUDENTS and NUM_SUBJECTS
DEFINE structure Student with fields name, id, marks (array of NUM_SUBJECTS), attendance
and average
INITIALIZE array students of type Student
INITIALIZEe num_students to 0
FUNCTION addStudent
DEFINE addStudent()
IFnum_students >= MAX_STUDENTS THEN
PRINT error message
ENDIF
RETURN
READ student name
D student ID
FOR each subject DO
READ marks
ENDFOR
READ attendance percentage
CALCULATE average marks
INCREMENT num_students
RETURN
FUNCTION displayStudents
DEFINE displayStudents()
IFnum_students == 0 THEN
PRINT "No students to display"
ENDIF
RETURN
FOR each student DO
PRINT student details namely name, ID, marks, attendance and average
COMPUTE performance based on average marks
PRINT performance
COMPUTE attendance status
PRINT attendance status
ENDFOR
RETURN
FUNCTION sortStudentsByAverage
DEFINE sortStudentsBy Average()
FOR each student i DO
FOR each student j after i DO
IF students[i] average < studentsfj.averageTHEN
SWAP students[i] and students{j]
ENDIF
ENDFOR
ENDFOR
PRINT "Students have been sorted by their average marks"
Department:CSE/IT/AIDS MSEC R2024
PAGE NO 81(An Autonomous Institution, Affiliated to Anna University, Chennai)
@ Meenakshi Sundararajan Engineering College
—*+ U24CS101 - Programming in C - Laboratory Component
RETURN
BEGIN
WHILE true DO
PRINT menu options
READ user's choice
IF choice is 1 THEN
CALL addStudent()
ELSE IF choice is 2 THEN
CALL displayStudents()
ELSE IFchoice is 3 THEN
CALL sortStudentsByAverage()
ELSE IF choice is 4 THEN
Exit program
ELSE Print "Invalid choice! Please try again"
ENDIF
ENDWHILE
END
PROGRAM:
Hinclude
#include
#define MAX_STUDENTS 100
#define NUM_SUBJECTS 3
struct Student { // Define the structure for a student
char name[50);
int id;
float marks[NUM_SUBJECTS],
float attendance;
float average;
h
struct Student students[MAX_STUDENTS]; // Array of students
int num_students = 0; // Keep track of the number of students
// Function to add a student
void addStudent() {
if (num_students >= MAX_STUDENTS) {
printf("Error: Maximum number of students reached!\n");,
return;
struct Student *student = &students{num_students];
printf{"Enter student name: ");
scanf(" %[*\n]%*c", student->name), // Read string with spaces
printf("Enter student ID: ");
scanf("%d", &student->id),
printf{"Enter marks for 3 subjects:\n"),
for (int i = 0; i < NUM_SUBJECTS; i++) {
printf("Subject %d: ", i+ 1);
scanf{"t", &student->marksi]);
MSEC R2024
PAGE NO 82(An Autonomous Institution, Affiliated to Anna University, Chennai)
@ Meenakshi Sundararajan Engineering College
Ze U24C8101 - Programming in C - Laboratory Component
print{("Enter attendance percentage: ");
scanf{"%f", &student->attendance),
// Calculate the student's average marks
float sum = 0;
for (int
4
student->average = sum / NUM_SUBIECTS;
num_students++, // Increment the student count
marks[i];
sum
+
// Function to display student records
void displayStudents() {
if (num_students == 0) {
printf("No students to display \n"),
return;
1
for (int i= 0; i = 75.0) {
printf(" Performance: Excellent\n’);
} else if (students[i] average >= 50.0) {
Printf(""Performance: Average\n");
J else {
printf(* Performance: Poorin");
}
// Conditional statement for attendance evaluation
if (studentsfi) attendance >= 75.0) {
printi(" Attendance: Satisfactory\n");
} else {
printf(" Attendance: Unsatisfactory\n" );
‘
}
// Function to sort students by average grade
void sortStudentsBy Average() {
struct Student temp;
for (int i= 0; i ),
4.How do you access structure members using pointers?
Structure members can be aecessed using the arrow operator, For example, if ptr is a
pointer to a Student structure, you can access the name with ptr->name
S.What are the advantages of using pointers to structures?
Pointers to structures allow for efficient memory management by avoiding copying the
entire structure when passing it to functions. They also enable dynamic memory allocation and
the creation of complex data structures like linked lists
6.What is an array of structures?
An array of structures is a collection of structures that allow to manage multiple records
of the same type. For example, an array of Student structures can hold the details of multiple
students,
RESULT :
‘The program for developing student management system using structure, nested
structure, and pointer to structures was executed successfully.
Department:CSE/IT/AIDS MSEC R2024(An Autonomous Institution, Affiliated to Anna University, Chennai)
@ Meenakshi Sundararajan Engineering College
ee U24CS101 - Programming in C - Laboratory Component
PSEUDOCOD!
DEFINE MAX_NAME_LE!
DEFINE NUM_SUBJECTS = 3
DEFINE a structure Student with name, id, marks, attendance and average
FUNCTION addStudent()
DECLARE student AS Student
READ student name
READ student id
FOR i FROM 0 TO NUM_SUBIECTS - 1
READ student. marks(i]
ENDFOR
READ student attendance
ASSIGN sum = 0
FOR i from 0 to NUM_SUBJECTS - 1
sum = sum + student marks[i)
student average = sum / NUM_SUBJECTS
CALL saveStudent ToFile(student)
RETURN
FUNCTION saveStudentToFile(student)
OPEN file "students dat" in append mode
IF file is NULL:
PRINT "Error opening file!"
RETURN
ENDIF
WRITE student to file
: file
"Student added and saved to file successfully!"
RETURN
FUNCTION displayStudents()
OPEN file "students dat” IN read mode
IF file is NULL:
PRINT "Error opening file or no students found!"
RETURN
ENDIF
DECLARE student AS Student
WHILE READ student from file:
PRINT student name, student.id
FOR i from 0 to NUM_SUBJECTS - 1
PRINT student marks[i}
ENDFOR
PRINT student attendance, student average
CLOSE file
RETURN
FUNCTION deleteStudent(),
Department:CSE/IT/AIDS MSEC R2024
PAGE NO 110Meenakshi Sundararajan Engineering College
(An Autonomous Institution, Affiliated to Anna University, Chennai)
—* U24CS101 - Programming in C - Laboratory Component
READ id
OPEN file "students dat” in read mode
IF file is NULL:
PRINT "Error opening file!"
RETURN
ENDIF
OPEN tempFile "temp dat" in write mode
IF tempFile is NULL
PRINT "Error creating temp file!"
CLOSE file
RETURN
ENDIF
DECLARE student AS Student
ASSIGN found = FALS!
WHILE READ student from file:
IF student id == id THEN
RUE
Student details deleted successfully.”
WRITE student to tempFile
ENDIF
ENDWHILE
IF !found THEN
PRINT "Student not found!"
ENDIF
CLOSE file
CLOSE tempFile
REMOVE "students dat"
RENAME "temp dat" TO "students.dat”
RETURN
BEGIN
WHILE true:
PRINT "--- Student Management System —-"
PRINT "1. Add Student”
PRINT "2. View Alll Students"
PRINT "3. Delete Student by ID"
PRINT "4. Exit"
PRINT "Enter your choice"
READ choice
SWITCH choice:
CASE 1: CALL addStudent()
CASE2: CALL displayStudents()
CASE3: — CALL deleteStudent()
CASE4: EXIT
DEFAULT: PRINT "Invalid choice! Please try again."
ENDSWITCH
END
Department:CSE/IT/AIDS MSEC R2024
PAGE NO Ill(An Autonomous Institution, Affiliated to Anna University, Chennai)
@ Meenakshi Sundararajan Engineering College
ee ——_U24CS101 - Programming in C - Laboratory Component
PROGRAM:
#include
dinclude
include
define MAX_NAME_LEN 50
define NUM_SUBJECTS 3
struct Student { // Define the structure for a student
char name[MAX_NAME_LEN);
int id,
float marks[NUM_SUBJECTS];
float attendance;
float average;
h
1/ Function prototypes
void addStudent();
void displayStudents();
void deleteStudent();
void saveStudentToFile(struct Student student);
void loadStudentsFromFile();
void rewriteFile(),
1! Global variables
char filename{] = "students dat";
int num_students = 0;
void addStudent() { // Function to add a student
struct Student student;
printf("Enter student name: ");
scanf{" %{*\n}%*e", student name); // Read string with spaces
printf("Enter student ID: ");
scanf{"%d", &student id);
printf("Enter marks for 3 subjects:\n"),
for (int i= 0; i< NUM_SUBJECTS; i++) {
printf(" Subject %d: ", i+ 1);
seanf("%t", &student marksfi]);
printf("Enter attendance percentage: ");
scanf{"%t", &student attendance),
float sum=0; // Calculate the student's average marks
for (int i= 0; 1< NUM_SUBJECTS; i++) {
sum += student marks[i};
student average = sum / NUM_SUBJECTS;
saveStudentToFile(student); 7/ Save the student to the file
}
void saveStudentToFile(struct Student student) { // Function to save student to file
FILE *file = fopen(filename, "ab"), // Open file in append mode
Department:CSE/IT/AIDS MSEC R2024
PAGE NO 112(An Autonomous Institution, Affiliated to Anna University, Chennai)
@ Meenakshi Sundararajan Engineering College
—* U24CS101
rogramming in C - Laboratory Component
printf("Error opening file!\n");
return;
}
fwrite(&student, sizeof{struct Student), 1, file); // Write student struct to file
felose({ile),
printf{"Student added and saved to file successfully!\n"),
}
void displayStudents() { // Function to load students from file and display them
fopen(filename, "rb"); // Open file in read mode
ULL) {
printf("Error opening file or no students found!\n"),
return;
}
struct Student student,
printf("\n--- Student Records --\n");
while (fread(&student, sizeof{struct Student), 1, file)) {
printf("\nName: %s\n", student.name);
printf{"ID: %d\n", student.id),
for (int i= 0; i< NUM_SUBJECTS; i++) {
printf(" Subject %d: % 2f\n', i + 1, student marks[il);
3
printf(" Attendance: %.21%%\n", student attendance);
printf(" Average Marks: % 2f\n", student average);
}
felose({ile);
}
void deleteStudent() { —// Function to delete a student by ID
int id;
printf("Enter the student ID to delete: ");
scanfi"%d", &id);
FILE *file = fopen(filename, "rb"); // Open file in read mode
ULL) {
printf("Error opening file!\n");
return;
}
FILE *tempFile = fopen(*temp dat", "wb"); // Temporary file to store remaining
students
if (tempFile == NULL) {
printf("Error creating temp file!\n");
felose( ile);
return,
3
struct Student student;
int found = 0;
while (fread(&student, sizeof{struct Student), 1, file)) {
Department:CSE/IT/AIDS MSEC R2024
PAGE NO 113(An Autonomous Institution, Affiliated to Anna University, Chennai)
@ Meenakshi Sundararajan Engineering College
—*+ U24CS101 - Programming in C - Laboratory Component
if (student id
found = 1;
printf("Student with ID %d deleted successfully \n", id);
Dt
}
else {
fwrite(&student, sizeofstruct Student), 1, tempFile);
}
if (found) {
printf(" Student with ID %d not found!\n’, id);
}
felose({ile);
felose(tempFile);
remove( filename), // Remove original file
rename("temp.dat", filename), // Rename temp file to original
}
int main() { —_// Main function
int choice;
while (1) {
printf("\n--- Student Management System -~\n"),
printf("1. Add Student\n");
printf("2. View All Students\n");
printf("3. Delete Student by ID\n"),
printf("4. Exit\n");
printf("Enter your choice: ");
scanf{"*%d", &choice);
switeh (choice) {
case 1: addStudent();
break;
case 2: displayStudents();,
break;
case 3: deleteStudent()
break;
case 4: exit(0);
default: printf("Invalid choice! Please try again \n"),
Outpu
1. Adding a Student
Enter student name: John Doe
Enter student ID: 123
Enter marks for 3 subjects: Subject 1: 85 Subject 2: 90 Subject 3: 78
Enter attendance percentage: 92.5
Student added and saved to file successfully!
2. Viewing All Students
Department:CSE/IT/AIDS MSEC R2024
PAGE NO 114(An Autonomous Institution, Affiliated to Anna University, Chennai)
@ Meenakshi Sundararajan Engineering College
aeve —_U24C8101 - Programming in C - Laboratory Component
~- Student Records ---
Name: John Doe
ID: 123
Subject 1: 85.00
Subject 2: 90.00
Subject 3: 78.00
Attendance: 92.50%
Average Marks: 84.33
3, Deleting a Student by ID
Enter the student ID to delete: 123
Student with ID 123 deleted successfully.
RESULT:
The program to enhance the student management system by storing student information
ina file has been executed successfully
Department:CSE/IT/AIDS MSEC R2024Meenakshi Sundararajan Engineering College
(An Autonomous Institution, Affiliated to Anna University, Chennai)
U24CS101 - Programming in C - Laboratory Component
PROGRAM
#include
Hinclude
define MAX_STUDENTS 100
define MAX_SUBJECTS 5
void addStudent(char names{}[50], int grades(][MAX_SUBJECTS], int *n); // Call by
reference
void displayStudents(char names{}{50), int grades{}[MAX_SUBJECTS}, float avg{], int
n); /! Call by value
float caleulateAverage(int grades(], int n), // Call by value
void sortStudents(char names{]{50}, int grades{][MAX_SUBJECTS], float aval}, int n);
1 Recursive sort using call by reference
Main function
int main() {
char names[MAX_STUDENTS][50}; // Array to store student names
int grades{MAX_STUDENTS][MAX_SUBIECTS); // Array to store student grades
float ave[MAX_STUDENTS]; 1/ Array to store average grades
intn=0; 1 Number of students
int choice,
dof
printf("\nl. Add Student\n2. Display Students\n3. Sort by Average Grade\nd
Exit\n");
printi("Enter your choice: ");
seanf{"%d", &choice);
switch(choice) {
case |
addStudent(names, grades, &n),
break;
case 2
1 Calculate average for all students before displaying
for (int sii; ++) {
ayg[i] = calculateAverage(grades[i), MAX_SUBJECTS),
}
displayStudents(names, grades, avg, n);
break;
case 3
sortStudents(names, grades, avg, n);
printf("Students sorted by average grades \n’
break;
case 4:
printf(" Exiting .\n");
break;
default:
printf("Invalid choice! Try again \n");
} while(choice != 4);
Department:CSE/IT/AIDS MSEC R2024
PAGE NO 61Meenakshi Sundararajan Engineering College
(An Autonomous Institution, Affiliated to Anna University, Chennai)
ee —_U24CS101 - Programming in C - Laboratory Component
return 0;
}
// Function to add student data (Call by reference)
void addStudent(char names{]{50], int grades[][MAX_SUBJECTS], int *n) {
printf("Enter student's name: ");
seanf("%s", names{*n}); // Add name
printf{"Enter %d grades: ", MAX_SUBJECTS);
for (int i= 0; i< MAX_SUBJECTS; i++) {
scanf("%d", &grades|*n]fi)); // Add grades
h
(¢n)++; // Inerement number of students
+
// Function to calculate average grade (Call by value)
float calculateAverage( int gradesf], int n) {
int sum = 0;
for (int i= 0; i