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

Student Record Management System

This document is a C++ program that manages student records, allowing users to write, read, search, and delete student information stored in a text file. It defines a 'student' structure and uses a vector to hold student records, while providing a menu-driven interface for user interaction. Key functionalities include adding new records, displaying all records, searching for a specific student by roll number, and deleting records.

Uploaded by

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

Student Record Management System

This document is a C++ program that manages student records, allowing users to write, read, search, and delete student information stored in a text file. It defines a 'student' structure and uses a vector to hold student records, while providing a menu-driven interface for user interaction. Key functionalities include adding new records, displaying all records, searching for a specific student by roll number, and deleting records.

Uploaded by

Suraj Surve
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <bits/stdc++.

h>
#include <fstream>
using namespace std;

// Structure to store student details


struct student {
int roll;
string name, div, address;
};

// Global vector to store student records


vector<student> students;

// Function to write student data to the file


void Write() {
student s;
cout << "Enter the roll no of student: ";
cin >> [Link];

cout << "Enter the name of student: ";


[Link](); // Clear input buffer before getline
getline(cin, [Link]);

cout << "Enter the division of student: ";


cin >> [Link];

cout << "Enter the address of student: ";


[Link](); // Clear input buffer before getline
getline(cin, [Link]);

ofstream file("[Link]", ios::app); // Append mode


file << [Link] << "\t" << [Link] << "\t" << [Link] << "\t" << [Link] << "\n";
[Link]();

cout << "Student record added successfully!\n";


}

// Function to read and display all student records


void Read() {
ifstream file("[Link]");
string temp;

cout << "\nRoll no\tName\tDiv\tAddress\n";


while (getline(file, temp)) {
cout << temp << endl;
}

[Link]();
}

// Function to load student records from file into vector


void appendtovec() {
ifstream file("[Link]");
student s;
[Link](); // Remove old records

while (file >> [Link]) {


[Link](); // Skip tab after roll number
getline(file, [Link], '\t');
getline(file, [Link], '\t');
getline(file, [Link]);
students.push_back(s);
}

[Link]();
}

// Function to search for a student by roll number


void search() {
int roll;
cout << "Enter roll number to search: ";
cin >> roll;

bool found = false;


for (const auto& s : students) {
if ([Link] == roll) {
cout << "Student found: " << [Link] << "\t" << [Link] << "\t" << [Link]
<< "\t" << [Link] << endl;
found = true;
break;
}
}

if (!found) {
cout << "Student not found!" << endl;
}
}

// Function to delete a student record by roll number


void Delete() {
int roll;
cout << "Enter roll number to delete: ";
cin >> roll;

ofstream temp("[Link]", ios::app);


bool found = false;

for (const auto& s : students) {


if ([Link] == roll) {
found = true;
continue; // Skip writing this record
}
temp << [Link] << "\t" << [Link] << "\t" << [Link] << "\t" << [Link] <<
"\n";
}

[Link]();

if (!found) {
cout << "Student not found!" << endl;
remove("[Link]");
} else {
remove("[Link]");
rename("[Link]", "[Link]");
cout << "Student deleted successfully!" << endl;
}
}
// Main menu-driven function
int main() {
int choice = 0;

do {
cout << "\n1. Write to file";
cout << "\n2. Read from file";
cout << "\n3. Search in file";
cout << "\n4. Delete from file";
cout << "\n5. Exit session";

cout << "\n\nEnter your choice: ";


cin >> choice;

switch (choice) {
case 1:
Write();
break;
case 2:
Read();
break;
case 3:
appendtovec();
search();
break;
case 4:
appendtovec();
Delete();
break;
case 5:
cout << "\nExiting...\n";
break;
default:
cout << "Invalid choice! Please try again.\n";
break;
}

} while (choice != 5);

return 0;
}

You might also like