0% found this document useful (0 votes)
21 views

Student Data Management in C++ - GeeksforGeeks

The document discusses a Student Data Management system implemented in C++, focusing on managing student information through a text file. It outlines the data structure for storing student details, including registration number, name, and marks, and provides a code example for various operations like adding students, logging in, and viewing data. The program allows different user roles to interact with the data, including students, faculty, proctors, and administrators.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Student Data Management in C++ - GeeksforGeeks

The document discusses a Student Data Management system implemented in C++, focusing on managing student information through a text file. It outlines the data structure for storing student details, including registration number, name, and marks, and provides a code example for various operations like adding students, logging in, and viewing data. The program allows different user roles to interact with the data, including students, faculty, proctors, and administrators.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

2/24/25, 5:14 PM Student Data Management in C++ - GeeksforGeeks

Trending Now DSA Web Tech Foundational Courses Data Science Practice Problem Python M

Student Data Management in C++


Last Updated : 24 Nov, 2022

Databases are being used in every aspect of our lives right now. Trillions
of bytes of data are being stored in servers around the world. SQL is
one of the most basic methods to use such a database. But have you
ever thought about using C++ to maintain such a database. In this post,
we will talk about implementing different views on a text file according
to the type of user and edit accordingly.

The data stored using this code are:


1) Registration number
2) Name
3) Marks in CSE1001
4) Marks in CSE1002
5) Proctor ID

Following code is a simple implementation of Student Management


Project written in C++

C++

// Include all the necessary libraries.


#include <fstream>
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

int main()
{
// Considering the max length of data entered (name) to

https://www.geeksforgeeks.org/student-data-management-c/ 1/17
2/24/25, 5:14 PM Student Data Management in C++ - GeeksforGeeks

// be 15.
char data[15];
int n = 0, option = 0, count_n = 0;
// This is the initial mark allotted to a subject.
string empty = "00";
string proctor = "";
// Name of the file in which DB is stored.
ifstream f("Example.txt");
string line;

// The following for loop counts the total number of


// lines in the file.
for (int i = 0; std::getline(f, line); ++i) {
count_n++;
}

while (option != 6) {
// This prints out all the available options in the
// DB
cout << "\nAvailable operations: \n1. Add New "
"Students\n2."
<< "Student Login\n3. Faculty Login\n4. "
"Proctor Login\n5. Admin View\n"
<< "6. Exit\nEnter option: ";
cin >> option;

if (option == 1) {
cout << "Enter the number of students: ";
cin >> n;

count_n = count_n + n;

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


ofstream outfile;
outfile.open("Example.txt", ios::app);
// The entire data of a single student is
// stored line-by-line.
cout << "Enter your registration number: ";
cin >> data;
outfile << data << "\t";

cout << "Enter your name: ";


cin >> data;
int len = strlen(data);

while (len < 15) {


data[len] = ' ';
len = len + 1;
}
outfile << data << "\t";

https://www.geeksforgeeks.org/student-data-management-c/ 2/17
2/24/25, 5:14 PM Student Data Management in C++ - GeeksforGeeks

// Inserting empty data initially into the


// file
outfile << empty << "\t";
outfile << empty << "\t";

cout << "Enter your proctor ID: ";


cin >> proctor;

outfile << proctor << endl;


}
}

else if (option == 2) {
char regno[9];
cout << "Enter your registration number: ";
cin >> regno;
ifstream infile;
int check = 0;
infile.open("Example.txt", ios::in);

// This loop prints out the data according to


// the registration number specified.
while (infile >> data) {
if (strcmp(data, regno) == 0) {
cout
<< "\nRegistration Number: " << data
<< endl;
infile >> data;
cout << "Name: " << data << endl;

infile >> data;


cout << "CSE1001 mark: " << data
<< endl;

infile >> data;


cout << "CSE1002 mark: " << data
<< endl;

infile >> data;


cout << "Proctor ID: " << data << endl;

infile.close();
check = 1;
}
}

if (check == 0) {
cout << "No such registration number found!"
<< endl;
}

https://www.geeksforgeeks.org/student-data-management-c/ 3/17
2/24/25, 5:14 PM Student Data Management in C++ - GeeksforGeeks

// This loop is used to view and add marks to the


// database of a student.
else if (option == 3) {
char subcode[7];
cout << "Enter your subject code: ";
cin >> subcode;
string code1 = "CSE1001", code2 = "CSE1002",
mark = "";
ifstream infile;
int check = 0;

cout << "\nAvailable operations: \n1. Add data "


"about marks\n"
<< "2. View data\nEnter option: ";
cin >> option;

if (option == 1) {
cout
<< "Warning! You would need to add mark"
<< "details for all the students!"
<< endl;
for (int i = 0; i < count_n; i++) {
fstream file("Example.txt");

// The seek in file has been done


// according to the length
// of the data being inserted. It needs
// to adjusted accordingly for different
// lengths of data.

if (strcmp(subcode, code1.c_str())
== 0) {
file.seekp(26 + 37 * i,
std::ios_base::beg);
cout << "Enter the mark of student#"
<< (i + 1) << " : ";
cin >> mark;
file.write(mark.c_str(), 2);
}

if (strcmp(subcode, code2.c_str())
== 0) {
file.seekp(29 + 37 * i,
std::ios_base::beg);
cout << "Enter the mark of student#"
<< (i + 1) << " : ";
cin >> mark;
file.write(mark.c_str(), 2);

https://www.geeksforgeeks.org/student-data-management-c/ 4/17
2/24/25, 5:14 PM Student Data Management in C++ - GeeksforGeeks

}
}
}

// This loop is used to view marks of a student.


// The extra infile commands have been used to
// get a specific mark only since the data has
// been separated by a tabspace.

else if (option == 2) {
infile.open("Example.txt", ios::in);
if (strcmp(subcode, code1.c_str()) == 0) {
cout << "Registration number - Marks\n"
<< endl;
while (infile >> data) {
cout << data;
infile >> data;
infile >> data;
cout << " - " << data << endl;
infile >> data;
infile >> data;
check = 1;
}
}

infile.close();
infile.open("Example.txt", ios::in);

if (strcmp(subcode, code2.c_str()) == 0) {
cout << "Registration number - Marks\n"
<< endl;
while (infile >> data) {
cout << data;
infile >> data;
infile >> data;
infile >> data;
cout << " - " << data << endl;
infile >> data;
check = 1;
}
}
}

infile.close();

if (check == 0) {
cout << "No such subject code found!"
<< endl;
}
}

https://www.geeksforgeeks.org/student-data-management-c/ 5/17
2/24/25, 5:14 PM Student Data Management in C++ - GeeksforGeeks

// This loop displays all the details of students


// under the same proctor ID.

else if (option == 4) {
char procid[7];
cout << "Enter your proctor ID: ";
cin >> procid;
int check = 0;
char temp1[100], temp2[100], temp3[100];
char temp4[100], id[100];
ifstream infile;
infile.open("Example.txt", ios::in);

while (infile >> temp1) {


infile >> temp2;
infile >> temp3;
infile >> temp4;
infile >> id;

if (strcmp(id, procid) == 0) {
cout << "\nRegistration Number: "
<< temp1 << endl;
cout << "Name: " << temp2 << endl;
cout << "CSE1001 Mark: " << temp3
<< endl;
cout << "CSE1002 Mark: " << temp4
<< endl;
check = 1;
}
}

if (check == 0) {
cout << "No such proctor ID found!" << endl;
}
}

// This loop acts as an admin view to see all the


// data in the file.

else if (option == 5) {
char password[25];
cout << "Enter the admin password: ";
cin >> password;

// This variable value can be changed according


// to your requirement of the administrator
// password.

string admin_pass = "admin";

https://www.geeksforgeeks.org/student-data-management-c/ 6/17
2/24/25, 5:14 PM Student Data Management in C++ - GeeksforGeeks

if (strcmp(password, admin_pass.c_str()) == 0) {
cout << "Reg No. "
"\tName\tCSE1001\tCSE1002\tProctor "
"ID"
<< endl;
ifstream infile;
infile.open("Example.txt", ios::in);
char data[20];

while (infile >> data) {


cout << data << "\t";
infile >> data;
cout << data << "\t";
infile >> data;
cout << data << "\t";
infile >> data;
cout << data << "\t";
infile >> data;
cout << data << endl;
}
}
}
}
}

Output:

Available operations:
1. Add New Students
2. Student Login
3. Faculty Login
4. Proctor Login
5. Admin View
6. Exit
Enter option: 1
Enter the number of students: 2
Enter your registration number: 15BCE2083
Enter your name: Dheeraj
Enter your proctor ID: 1001
Enter your registration number: 15BCE2082
Enter your name: Rohan
Enter your proctor ID: 1002

https://www.geeksforgeeks.org/student-data-management-c/ 7/17
2/24/25, 5:14 PM Student Data Management in C++ - GeeksforGeeks

Available operations:
1. Add New Students
2. Student Login
3. Faculty Login
4. Proctor Login
5. Admin View
6. Exit
Enter option: 3
Enter your subject code: CSE1001

Available operations:
1. Add data about marks
2. View data
Enter option: 1
Warning! You would need to add mark details for all the students!
Enter the mark of student#1 : 52
Enter the mark of student#2 : 89
No such subject code found!

Available operations:
1. Add New Students
2. Student Login
3. Faculty Login
4. Proctor Login
5. Admin View
6. Exit
Enter option: 5
Enter the admin password: admin
Reg No. Name CSE1001 CSE1002 Proctor ID
15BCE2083 Dheeraj 52 00 1001
15BCE2082 Rohan 89 00 1002

Available operations:
1. Add New Students
2. Student Login
3. Faculty Login
4. Proctor Login
5. Admin View
6. Exit
Enter option: 6

https://www.geeksforgeeks.org/student-data-management-c/ 8/17
2/24/25, 5:14 PM Student Data Management in C++ - GeeksforGeeks

------------------
(program exited with code: 0)
Press return to continue

Do note that I have set the pointer position according to the length of
the data I am entering in the text file. Some of the things which I had
assumed are the registration number is always 9 characters long,
subject code is either CSE1001/CSE1002, proctor ID is 4 characters
long, marks is just 2 characters long. You would need to change the
code accordingly if you want to enter some other type of data.

Get 90% Course fee refund on completing 90% course in 90 days!


Take the Three 90 Challenge today.

The next 90 Days of focus & determination can unlock your full
potential. The Three 90 challenge has started and this is your chance
to upskill and get 90% refund. What more motivation do you need?
Start the challenge right away!

Comment More info Next Article


Student Information Management
Advertise with us System

Similar Reads
Student Information Management System
Prerequisites: Switch Case in C/C++ Problem Statement: Write a program
to build a simple Software for Student Information Management System…

14 min read

https://www.geeksforgeeks.org/student-data-management-c/ 9/17
2/24/25, 5:14 PM Student Data Management in C++ - GeeksforGeeks

CRUD Operations in Student Management System in Java


CRUD stands for Create, Read/Retrieve, Update and Delete and these are
the four basic operations that we perform on persistence storage. CRUD …

7 min read

Student Management System using Express.js and EJS Templating…


In this article, we build a student management student which will have
features like adding students to a record, removing students, and updati…

5 min read

Java program to store a Student Information in a File using AWT


Swing is a part of the JFC (Java Foundation Classes). Building Graphical
User Interface in Java requires the use of Swings. Swing Framework…

4 min read

Student Record System using Java Swing


Consider a scenario of a school where everyday teachers, staff, authorities
need to go through the records of their students for various purposes lik…

7 min read

Design a Student Attendance Portal in HTML CSS & JavaScript


The Student Attendance Portal is a web application that allows users to
mark attendance for students in different classes, add class and students…

10 min read

Project Idea | Smart Waste Management Systems


Project Title: Smart Waste Management System Introduction: One of the
essential components of a smart city is a Clean and Green Environment…

3 min read

Perl | Database management using DBI


Prerequisites: Introduction to Perl Database Systems Creating database
programs is one of the most common uses of Perl. Using Perl, we can…
https://www.geeksforgeeks.org/student-data-management-c/ 10/17
2/24/25, 5:14 PM Student Data Management in C++ - GeeksforGeeks

7 min read

Menu-Driven Program for Bank Management System


Prerequisite: Switch Case in C/C++Problem Statement: Write a program to
build a simple Bank Management System using C++ which can perform…

10 min read

Project Idea | Water Management System


Introduction: Water is one of the most important basic needs for living
beings. But with the modernization and development of human lifestyles…

5 min read

Health Management System using Python


Sometimes we are so busy that we are not even able to care for our body
and by caring we mean fitness, food, exercises and much more, and then…

7 min read

Department Store Management System(DSMS) using C++


A Department Store Management System (DSMS) in C++ is a software
tool used to manage the inventory and sales of items in a department…

8 min read

Project Idea | Smart Waste Management System


INTRODUCTION: Brief presentation of the project (MUST SEE before
reading further) The Internet of Things (IoT) is a concept in which…

9 min read

E -Library Management System


In this article, we will discuss the approach to creating an E-Library
Management System where the user has the following options: Add boo…

10 min read

Hotel Management System


https://www.geeksforgeeks.org/student-data-management-c/ 11/17
2/24/25, 5:14 PM Student Data Management in C++ - GeeksforGeeks

Given the data for Hotel management and User:Hotel Data: Hotel Name
Room Available Location Rating Price per RoomH1 4 Bangalore 5 100H…

15+ min read

Document Management System with React and Express.js


This project is a Document Management System (DMS) developed with a
combination of NodeJS, ExpressJS for the server side and React for the…

7 min read

Content Management System (CMS) using React and Express.js


This project is a Content Management System (CMS) Admin Panel
developed using React for the frontend and NodeJS and ExpressJS for th…

8 min read

Expense Management System using MERN Stack


In this article, we’ll walk through the step-by-step process of creating a
Expense Management System using the MERN (MongoDB, ExpressJS,…

14 min read

Document Management System using NextJS


The Document Management System is a web application developed using
Next.js, that allows users to efficiently manage their documents. The…

5 min read

Event Management Web App using MEAN


In this guide, we'll walk through the step-by-step process of building a
feature-rich Event Management Web App. We will make use of the MEA…

8 min read

Customer Relationship Management (CRM) System with Node.js an…


CRM systems are important tools for businesses to manage their
customer interactions, both with existing and potential clients. In this…

15+ min read

https://www.geeksforgeeks.org/student-data-management-c/ 12/17
2/24/25, 5:14 PM Student Data Management in C++ - GeeksforGeeks

Hospital Management System using MEAN Stack


The Hospital Management App is an important application that ensures
seamless coordination to revolutionize healthcare administration. In this…

15+ min read

Real Estate Management using MEAN


In this tutorial, we'll create a Real Estate Management Application using
Angular for the front end and Express with MongoDB for the back end.…

9 min read

Subscription Management System with NodeJS and ExpressJS


In this article, we’ll walk through the step-by-step process of creating a
Subscription Management System with NodeJS and ExpressJS. This…

5 min read

Volunteer Management System using MERN Stack


In this article, we will explore the development of a Volunteer
Management System using NodeJS and ExpressJS and MongoDB as a…

7 min read

Create an Employee Management using React-Native


Creating the Employee Management Application using React-Native is
skill developing project. In this project, the application admin can manag…

6 min read

Task Management System using Node and Express.js


Task Management System is one of the most important tools when you
want to organize your tasks. NodeJS and ExpressJS are used in this articl…

15+ min read

User Management System Backend


User Management System Backend includes numerous endpoints for
performing user-dealing tasks. The backend could be constructed with t…
https://www.geeksforgeeks.org/student-data-management-c/ 13/17
2/24/25, 5:14 PM Student Data Management in C++ - GeeksforGeeks

4 min read

Library Management Application Backend


Library Management System backend using Express and MongoDB
contains various endpoints that will help to manage library users and…

10 min read

Appointment Management System using React


The Appointment Management System is a web application that allows
users to schedule, manage, and view appointments. It provides an easy-…

5 min read

Corporate & Communications Address:


A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Pradesh
(201305)

Registered Address:
K 061, Tower K, Gulshan Vivante
Apartment, Sector 137, Noida, Gautam
Buddh Nagar, Uttar Pradesh, 201305

Advertise with us

Company Explore
About Us Job-A-Thon Hiring Challenge
Legal Hack-A-Thon
Privacy Policy GfG Weekly Contest
Careers Offline Classes (Delhi/NCR)
In Media DSA in JAVA/C++

https://www.geeksforgeeks.org/student-data-management-c/ 14/17
2/24/25, 5:14 PM Student Data Management in C++ - GeeksforGeeks

Contact Us Master System Design


GFG Corporate Solution Master CP
Placement Training Program GeeksforGeeks Videos
Geeks Community

Languages DSA
Python Data Structures
Java Algorithms
C++ DSA for Beginners
PHP Basic DSA Problems
GoLang DSA Roadmap
SQL DSA Interview Questions
R Language Competitive Programming
Android Tutorial

Data Science & ML Web Technologies


Data Science With Python HTML
Data Science For Beginner CSS
Machine Learning JavaScript
ML Maths TypeScript
Data Visualisation ReactJS
Pandas NextJS
NumPy NodeJs
NLP Bootstrap
Deep Learning Tailwind CSS

Python Tutorial Computer Science


Python Programming Examples GATE CS Notes
Django Tutorial Operating Systems
Python Projects Computer Network
Python Tkinter Database Management System
Web Scraping Software Engineering
OpenCV Tutorial Digital Logic Design
Python Interview Question Engineering Maths

DevOps System Design


Git High Level Design
AWS Low Level Design
Docker UML Diagrams
Kubernetes Interview Guide
Azure Design Patterns
GCP OOAD
DevOps Roadmap System Design Bootcamp
Interview Questions

School Subjects Commerce


Mathematics Accountancy
Physics Business Studies
Chemistry Economics

https://www.geeksforgeeks.org/student-data-management-c/ 15/17
2/24/25, 5:14 PM Student Data Management in C++ - GeeksforGeeks

Biology Management
Social Science HR Management
English Grammar Finance
Income Tax

Databases Preparation Corner


SQL Company-Wise Recruitment Process
MYSQL Resume Templates
PostgreSQL Aptitude Preparation
PL/SQL Puzzles
MongoDB Company-Wise Preparation
Companies
Colleges

Competitive Exams More Tutorials


JEE Advanced Software Development
UGC NET Software Testing
UPSC Product Management
SSC CGL Project Management
SBI PO Linux
SBI Clerk Excel
IBPS PO All Cheat Sheets
IBPS Clerk Recent Articles

Free Online Tools Write & Earn


Typing Test Write an Article
Image Editor Improve an Article
Code Formatters Pick Topics to Write
Code Converters Share your Experiences
Currency Converter Internships
Random Number Generator
Random Password Generator

DSA/Placements Development/Testing
DSA - Self Paced Course JavaScript Full Course
DSA in JavaScript - Self Paced Course React JS Course
DSA in Python - Self Paced React Native Course
C Programming Course Online - Learn C with Data Structures Django Web Development Course
Complete Interview Preparation Complete Bootstrap Course
Master Competitive Programming Full Stack Development - [LIVE]
Core CS Subject for Interview Preparation JAVA Backend Development - [LIVE]
Mastering System Design: LLD to HLD Complete Software Testing Course [LIVE]
Tech Interview 101 - From DSA to System Design [LIVE] Android Mastery with Kotlin [LIVE]
DSA to Development [HYBRID]
Placement Preparation Crash Course [LIVE]

Machine Learning/Data Science Programming Languages


Complete Machine Learning & Data Science Program - [LIVE] C Programming with Data Structures
C++ Programming Course

https://www.geeksforgeeks.org/student-data-management-c/ 16/17
2/24/25, 5:14 PM Student Data Management in C++ - GeeksforGeeks

Data Analytics Training using Excel, SQL, Python & PowerBI - Java Programming Course
[LIVE] Python Full Course
Data Science Training Program - [LIVE]
Mastering Generative AI and ChatGPT
Data Science Course with IBM Certification

Clouds/Devops GATE
DevOps Engineering GATE CS & IT Test Series - 2025
AWS Solutions Architect Certification GATE DA Test Series 2025
Salesforce Certified Administrator Course GATE CS & IT Course - 2025
GATE DA Course 2025
GATE Rank Predictor

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved

https://www.geeksforgeeks.org/student-data-management-c/ 17/17

You might also like