Welcome to the Student Database Management System! This C++ application helps you manage student records efficiently. You can add, view, search, update, and delete student information. It also allows you to sort records, filter by branch, and save or load data from a file.
- Add Student: 📥 Add new student records.
- Show All Students: 📋 Display a list of all students.
- Search Student: 🔍 Find students by registration number, name, or branch.
- Update Student: ✏️ Modify details of existing students.
- Delete Student: 🗑️ Remove specific students or clear all records.
- Save to File: 💾 Save student records to a file.
- Load from File: 📂 Load student records from a file.
- Sort by Name: 🔢 Sort students alphabetically by name.
- Filter by Branch: 🔎 View students from a specific branch.
This project uses the following technologies:
- Language:
- C++ 🖥️
- Libraries:
<iostream>
for input/output operations 📝<vector>
for dynamic array management 📊<fstream>
for file operations 📂<string>
for string handling 🔠<algorithm>
for sorting and other operations ⚙️<limits>
for handling input limits ⛔
Before you start, ensure you have:
- A C++ compiler (e.g., g++, clang++)
- Basic understanding of C++ and its standard libraries
To compile the project, open your terminal and run:
g++ -o student_database student_database.cpp
This command creates an executable file named student_database
.
To run the program, use:
./student_database
Here's a step-by-step guide on how to use the application:
-
Add a New Student:
- Choose option
1
from the menu. - Enter the student's details:
- Name: e.g.,
John Doe
- Registration Number: e.g.,
123456
- Branch: e.g.,
Computer Science
- Class: e.g.,
2nd Year
- Name: e.g.,
- Choose option
-
Show All Students:
- Choose option
2
to display all student records.
- Choose option
-
Search for a Student:
- Choose option
3
. - Select the search criterion (registration number, name, or branch).
- Enter the search query. For example:
- If searching by name:
John Doe
- If searching by name:
- Choose option
-
Update Student Information:
- Choose option
4
. - Enter the registration number of the student to be updated.
- Choose the field to update (name, branch, or class) and provide new information. For example:
- To update the branch:
Electrical Engineering
- To update the branch:
- Choose option
-
Delete a Student:
- Choose option
5
. - Decide whether to delete a specific student or clear all records.
- Choose option
-
Save Data to File:
- Choose option
6
to save all student records tostudents.txt
.
- Choose option
-
Load Data from File:
- Choose option
7
to load student records fromstudents.txt
.
- Choose option
-
Sort Students by Name:
- Choose option
8
to sort students alphabetically by their names.
- Choose option
-
Filter Students by Branch:
- Choose option
9
to display students from a specific branch.
- Choose option
Here is a simplified example of how to use the StudentDatabase
class:
#include <iostream>
#include "student_database.h" // Assuming the class is declared in this header file
int main() {
StudentDatabase db;
// Load data from file
db.loadFromFile("students.txt");
// Add a new student
db.add();
// Show all students
db.showAll();
// Search for a student by name
db.search();
// Update a student's details
db.update();
// Delete a student
db.deleteStudent();
// Save data to file
db.saveToFile("students.txt");
// Sort students by name
db.sortByName();
// Filter students by branch
db.filterByBranch();
return 0;
}
-
Classes and Methods:
Student
: Represents a student with attributes for name, registration number, branch, and class.StudentDatabase
: Manages a collection ofStudent
objects. Provides methods for adding, viewing, searching, updating, and deleting students.
-
Core Functions:
add()
: Adds new student records.showAll()
: Displays details of all students.search()
: Finds and displays students based on the search criterion.update()
: Updates student details by registration number.deleteStudent()
: Removes students from the database.saveToFile()
: Saves student records to a file.loadFromFile()
: Loads student records from a file.sortByName()
: Sorts students alphabetically by name.filterByBranch()
: Displays students from a specific branch.
Q1: How do I handle input errors?
Ans: The code currently handles some basic input errors, but you can enhance it by adding more validation. For example, to ensure the registration number is not empty:
bool isValidRegistrationNumber(const std::string& regNo) const {
return !regNo.empty();
}
Q2: What if the file operations fail?
Ans: The program includes basic error handling for file operations. For example, when saving to a file:
void saveToFile(const std::string& filename) const {
try {
std::ofstream file(filename);
if (!file) throw std::runtime_error("Unable to open file for writing.");
// Write data to file...
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
}
}
Q3: How do I add more features to the application?
Ans: To add new features, you can extend the StudentDatabase
class. For example, to add a feature for calculating the average grade:
1. Add a `grade` attribute to the `Student` class.
2. Implement methods in `StudentDatabase` to handle this new attribute.
Q4: Can I integrate this with a database?
Ans: Yes, you can replace file operations with database operations for more advanced data management. Consider using SQLite or another database for persistence.
Q5: How can I improve the user interface?
Ans: You can enhance the user interface by adding error messages and confirmation prompts. For example:
void showAll() const {
if (students.empty()) {
std::cout << "No student records available. 😢\n";
} else {
for (size_t i = 0; i < students.size(); ++i) {
show(i);
}
}
}
Contributions are welcome! If you have suggestions or improvements, please follow these steps:
- Fork the Repository: Click the "Fork" button on the top-right corner of this page.
- Clone Your Fork: Use
git clone https://github.com/Slygriyrsk/student-database-management.git
to clone your fork to your local machine. - Create a Branch: Create a new branch with
git checkout -b main
. - Make Changes: Implement your changes or add features.
- Commit Changes: Commit your changes with
git commit -am 'Add some feature'
. - Push to GitHub: Push your changes with
git push origin main
. - Open a Pull Request: Go to the original repository and create a new Pull Request.
This project is licensed under the MIT License. See the LICENSE
file for more details.