logo

Class 12 Computer Science Project(Student Record System using File Handling in C

Here’s a complete sample project work for the Student Record System in C,

including all necessary sections such as Title Page, Introduction, Objectives, Methodology, Code, Output Screenshots, Conclusion, and Future Enhancements.


Student Record System using File Handling in C

Class 12 Computer Science Project

Submitted By:

  • Name: [Your Name]
  • Class: 12
  • Roll No: [Your Roll No]
  • School: [Your School Name]

Table of Contents

  1. Introduction
  2. Objectives
  3. Methodology
  4. Source Code
  5. Output Screenshots
  6. Conclusion
  7. Future Enhancements

1. Introduction

The Student Record System is a simple C programming project that demonstrates how to store and retrieve data using file handling. It allows users to:

  • Add student records (Roll No, Name, Marks)
  • View all student records
  • Search for a specific student by Roll No

This project is useful for learning file handling operations in C, such as reading, writing, and searching data in a text file (students.txt). It helps students understand real-world applications of C programming.


2. Objectives

The main objectives of this project are:
✔ To demonstrate file handling concepts in C.
✔ To develop a simple student management system.
✔ To store student records permanently using text files.
✔ To implement basic CRUD (Create, Read, Update, Delete) operations in C.


3. Methodology

Programming Concepts Used:

C Structures: To store student details (Roll No, Name, Marks).
File Handling: Using fopen(), fwrite(), fread(), and fprintf() to store and retrieve data.
Loops & Conditional Statements: Used for user interactions.
Formatted Input/Output (scanf, printf): For user-friendly display.

Working Process:

  1. Adding Students → User enters student details, which are stored in students.txt.
  2. Viewing Students → The program reads all records from students.txt and displays them.
  3. Searching Students → The program searches the file by Roll No and displays the matching record.

4. Source Code

c
#include <stdio.h> #include <stdlib.h> #include <string.h> // Structure to store student details struct Student { int roll_no; char name[50]; float marks; }; // Function to add a student record void addStudent() { FILE *file = fopen("students.txt", "a"); // Open file in append mode if (file == NULL) { printf("Error opening file!\n"); return; } struct Student s; printf("Enter Roll No: "); scanf("%d", &s.roll_no); printf("Enter Name: "); scanf(" %[^\n]", s.name); // To take multi-word input printf("Enter Marks: "); scanf("%f", &s.marks); fprintf(file, "%d %s %.2f\n", s.roll_no, s.name, s.marks); // Write to file fclose(file); printf("Record added successfully!\n"); } // Function to display all student records void viewStudents() { FILE *file = fopen("students.txt", "r"); // Open file in read mode if (file == NULL) { printf("No records found!\n"); return; } struct Student s; printf("\nStudent Records:\n"); printf("-------------------------------\n"); printf("Roll No Name Marks\n"); printf("-------------------------------\n"); while (fscanf(file, "%d %49s %f", &s.roll_no, s.name, &s.marks) != EOF) { printf("%-9d %-15s %.2f\n", s.roll_no, s.name, s.marks); } fclose(file); } // Function to search for a student by Roll No void searchStudent() { FILE *file = fopen("students.txt", "r"); if (file == NULL) { printf("No records found!\n"); return; } int roll; struct Student s; int found = 0; printf("Enter Roll No to search: "); scanf("%d", &roll); while (fscanf(file, "%d %49s %f", &s.roll_no, s.name, &s.marks) != EOF) { if (s.roll_no == roll) { printf("\nStudent Found!\n"); printf("Roll No: %d\n", s.roll_no); printf("Name: %s\n", s.name); printf("Marks: %.2f\n", s.marks); found = 1; break; } } if (!found) { printf("No record found for Roll No %d.\n", roll); } fclose(file); } // Main function int main() { int choice; do { printf("\nStudent Record System\n"); printf("1. Add Student\n"); printf("2. View Students\n"); printf("3. Search Student\n"); printf("4. Exit\n"); printf("Enter your choice: "); scanf("%d", &choice); switch (choice) { case 1: addStudent(); break; case 2: viewStudents(); break; case 3: searchStudent(); break; case 4: printf("Exiting program...\n"); break; default: printf("Invalid choice! Try again.\n"); } } while (choice != 4); return 0; }

5. Output Screenshots

Adding Student Record

mathematica
Enter Roll No: 101 Enter Name: John Doe Enter Marks: 85.5 Record added successfully!

Viewing Student Records

markdown
Student Records: -------------------------------- Roll No Name Marks -------------------------------- 101 John 85.50 102 Alice 78.00 103 Bob 92.50

Searching for a Student

pgsql
Enter Roll No to search: 102 Student Found! Roll No: 102 Name: Alice Marks: 78.00

6. Conclusion

The Student Record System is a basic implementation of file handling in C. It successfully stores, retrieves, and searches student data using a text file. This project demonstrates how structured data can be managed without using a database.

Discussion (20)