0% found this document useful (0 votes)
8 views3 pages

Real

The document is a C program for a University Student Management System that allows users to manage student records. It provides functionalities to add, find, display, delete, and update student details using a structured approach. The program uses a loop to present a menu for user interaction until the exit option is selected.

Uploaded by

ka943
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Real

The document is a C program for a University Student Management System that allows users to manage student records. It provides functionalities to add, find, display, delete, and update student details using a structured approach. The program uses a loop to present a menu for user interaction until the exit option is selected.

Uploaded by

ka943
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <stdio.

h>
#include <string.h>
struct Student {
int sid;
char fname[50];
char address[100];
char num[15];
float icp;
};

// Function
void insertNewStudent(struct Student records[], int *totalStudents);
void findStudentByID(struct Student records[], int totalStudents);
void displayAllStudents(struct Student records[], int totalStudents);
void deleteStudentByID(struct Student records[], int *totalStudents);
void updateStudentDetails(struct Student records[], int totalStudents);

int main() {
struct Student records[100];
int totalStudents = 0;
int choice;

do {
//options
printf("\n======== University Student Management System ========\n");
printf("1. Add New Student\n");
printf("2. Find Student by ID\n");
printf("3. Display All Students\n");
printf("4. Delete Student by ID\n");
printf("5. Update Student Details\n");
printf("6. Exit\n");
printf("======================================================\n");
printf("Enter your choice: ");
scanf("%d", &choice);

//menu options
switch (choice) {
case 1:
insertNewStudent(records, &totalStudents);
break;
case 2:
findStudentByID(records, totalStudents);
break;
case 3:
displayAllStudents(records, totalStudents);
break;
case 4:
deleteStudentByID(records, &totalStudents);
break;
case 5:
updateStudentDetails(records, totalStudents);
break;
case 6:
printf("Exiting program. Goodbye!\n");
break;
default:
printf("Invalid choice! Please try again.\n");
}
} while (choice != 6);

return 0;
}

//new student
void insertNewStudent(struct Student records[], int *totalStudents) {
printf("\nEnter details for the new student:\n");
printf("Student ID: ");
scanf("%d", &records[*totalStudents].sid);
printf("Full Name: ");
getchar();
fgets(records[*totalStudents].fname, 50, stdin);
records[*totalStudents].fname[strcspn(records[*totalStudents].fname, "\n")]
= '\0';
printf("Address: ");
fgets(records[*totalStudents].address, 100, stdin);
records[*totalStudents].address[strcspn(records[*totalStudents].address, "\
n")] = '\0';
printf("Contact Number: ");
scanf("%s", records[*totalStudents].num);
printf("ICP Marks: ");
scanf("%f", &records[*totalStudents].icp);

(*totalStudents)++;
printf("Student added successfully!\n");
}

//student by ID
void findStudentByID(struct Student records[], int totalStudents) {
int id, found = 0;
printf("\nEnter Student ID to search: ");
scanf("%d", &id);

for (int i = 0; i < totalStudents; i++) {


if (records[i].sid == id) {
printf("\nStudent Found:\n");
printf("ID: %d\n", records[i].sid);
printf("Name: %s\n", records[i].fname);
printf("Address: %s\n", records[i].address);
printf("Contact: %s\n", records[i].num);
printf("ICP Marks: %.2f\n", records[i].icp);
found = 1;
break;
}
}
if (!found) {
printf("No student found with ID %d.\n", id);
}
}

//display all students


void displayAllStudents(struct Student records[], int totalStudents) {
if (totalStudents == 0) {
printf("\nNo students to display.\n");
return;
}
printf("\nList of All Students:\n");
for (int i = 0; i < totalStudents; i++) {
printf("ID: %d | Name: %s | Address: %s | Contact: %s | ICP Marks: %.2f\
n",
records[i].sid, records[i].fname, records[i].address,
records[i].num, records[i].icp);
}
printf("\nTotal Number of Students: %d\n", totalStudents);
}

// delete a student by ID
void deleteStudentByID(struct Student records[], int *totalStudents) {
int id, found = 0;
printf("\nEnter Student ID to delete: ");
scanf("%d", &id);

for (int i = 0; i < *totalStudents; i++) {


if (records[i].sid == id) {
found = 1;
for (int j = i; j < *totalStudents - 1; j++) {
records[j] = records[j + 1];
}
(*totalStudents)--;
printf("Student with ID %d deleted successfully.\n", id);
break;
}
}
if (!found) {
printf("No student found with ID %d.\n", id);
}
}

// update student details


void updateStudentDetails(struct Student records[], int totalStudents) {
int id, found = 0;
printf("\nEnter Student ID to update: ");
scanf("%d", &id);

for (int i = 0; i < totalStudents; i++) {


if (records[i].sid == id) {
printf("Updating details for Student ID %d:\n", id);
printf("New Name: ");
getchar();
fgets(records[i].fname, 50, stdin);
records[i].fname[strcspn(records[i].fname, "\n")] = '\0';
printf("New Address: ");
fgets(records[i].address, 100, stdin);
records[i].address[strcspn(records[i].address, "\n")] = '\0';
printf("New Contact Number: ");
scanf("%s", records[i].num);
printf("New ICP Marks: ");
scanf("%f", &records[i].icp);
printf("Details updated successfully!\n");
found = 1;
break;
}
}
if (!found) {
printf("No student found with ID %d.\n", id);
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy