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

Project Code

This document describes a student record management system project that uses C++. It defines classes to represent different types of students (BS, MS, PhD) and stores student objects in a database. The database allows users to add, search, update, display, and delete student records. The main function provides a menu for interacting with the database to manage the student records.

Uploaded by

nabila
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)
42 views

Project Code

This document describes a student record management system project that uses C++. It defines classes to represent different types of students (BS, MS, PhD) and stores student objects in a database. The database allows users to add, search, update, display, and delete student records. The main function provides a menu for interacting with the database to manage the student records.

Uploaded by

nabila
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/ 12

Project final

STUDENT RECORD MANAGEMENT SYSTEM

Submitted to: Mam Arooj Zahra


SUBMITTED BY NABILA KHAN
Project code.
#include <iostream>

#include <vector>

#include <string>

#include <iomanip>

using namespace std;

class Student {

public:

string name;

int rollNumber;

string department;

int semester;

float cgpa;

Student() {

name = "";

rollNumber = 0;

department = "";

semester = 0;

cgpa = 0.0;

void inputStudentDetails() {

cout << "Enter student name: ";

cin.ignore();

getline( cin,name);

cout << "Enter roll number: ";

cin >> rollNumber;

cout << "Enter department: ";

cin.ignore();

getline( cin,department);
cout << "Enter semester: ";

cin >> semester;

void displayStudentDetails() const {

cout << "Name: " << name << "\n";

cout << "Roll Number: " << rollNumber << "\n";

cout << "Department: " << department << "\n";

cout << "Semester: " << semester << "\n";

cout << "CGPA: " << fixed << setprecision(2) << cgpa << "\n";

virtual void calculateCGPA() = 0;

};

class BsStudent : public Student {

public:

void calculateCGPA() override {

float totalMarks = 0.0;

int numSubjects;

cout << "Enter the number of subjects: ";

cin >> numSubjects;

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

float marks;

string subject_name;

cout<<"enter sujects name : "<<endl;

cin.ignore();

getline( cin,subject_name);

cout << "Enter marks for subject " <<subject_name<< i + 1 << ": ";

cin >> marks;

totalMarks += marks;

}
cgpa = (totalMarks / (numSubjects * 100.0)) * 4.0;

};

class MsStudent : public Student {

public:

void calculateCGPA() override {

float totalMarks = 0.0;

int numCourses;

cout << "Enter the number of courses: ";

cin >> numCourses;

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

float marks;

string course_name;

cout<<"enter course name :"<<endl;

cin.ignore();

getline( cin,course_name);

cout << "Enter marks for course "<<course_name << i + 1 << ": ";

cin >> marks;

totalMarks += marks;

cgpa = totalMarks / numCourses / 4.0;

};

class PhdStudent : public Student {

public:

void calculateCGPA() override {


cout << "PhD students are not graded using CGPA.\n";

};

class Database {

private:

vector<Student*> students;

public:

~Database() {

for (Student* student : students) {

delete student;

void addStudent() {

int choice;

cout << "Select student type:\n";

cout << "1. Bachelor's Student\n";

cout << "2. Master's Student\n";

cout << "3. PhD Student\n";

cout << "Enter your choice: ";

cin >> choice;

Student* student;

switch (choice) {

case 1:

student = new BsStudent();

break;

case 2:

student = new MsStudent();

break;

case 3:
student = new PhdStudent();

break;

default:

cout << "Invalid choice.\n";

return;

student->inputStudentDetails();

student->calculateCGPA();

students.push_back(student);

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

void searchStudentByRollNumber(int rollNumber) {

for (const Student* student : students) {

if (student->rollNumber == rollNumber) {

student->displayStudentDetails();

return;

cout << "Student with roll number " << rollNumber << " not found.\n";

void updateStudentRecord(int rollNumber) {

for (Student* student : students) {

if (student->rollNumber == rollNumber) {

cout << "Updating record for student with roll number " << rollNumber << "\n";

int numSubjects;

cout << "Enter the updated number of subjects: ";

cin >> numSubjects;


student->semester = student->semester; // Keep the semester unchanged

// Update subjects' names and marks

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

string subjectName;

float marks;

cout << "Enter name of subject " << i + 1 << ": ";

cin.ignore();

getline(cin, subjectName);

cout << "Enter marks for subject " << i + 1 << ": ";

cin >> marks;

student->calculateCGPA(); // Recalculate the CGPA based on the updated information

return;

cout << "Student with roll number " << rollNumber << " not found.\n";

void displayStudentRecord(int rollNumber) {

for (const Student* student : students) {

if (student->rollNumber == rollNumber) {

student->displayStudentDetails();

return;

}
cout << "Student with roll number " << rollNumber << " not found.\n";

void deleteStudent(int rollNumber) {

for (auto it = students.begin(); it != students.end(); ++it) {

if ((*it)->rollNumber == rollNumber) {

delete *it;

students.erase(it);

cout << "Student with roll number " << rollNumber << " deleted.\n";

return;

cout << "Student with roll number " << rollNumber << " not found.\n";

};

int main() {

Database database;

int choice;

do {

cout << "\nStudent Record Management System\n";

cout << "1. Add Student\n";

cout << "2. Search Student by Roll Number\n";

cout << "3. Update Student Record\n";

cout << "4. Display Student Record\n";

cout << "5. Delete Student\n";

cout << "6. Exit\n";

cout << "Enter your choice: ";

cin >> choice;


switch (choice) {

case 1:

database.addStudent();

break;

case 2: {

int rollNumber;

cout << "Enter roll number: ";

cin >> rollNumber;

database.searchStudentByRollNumber(rollNumber);

break;

case 3: {

int rollNumber;

cout << "Enter roll number: ";

cin >> rollNumber;

database.updateStudentRecord(rollNumber);

break;

case 4: {

int rollNumber;

cout << "Enter roll number: ";

cin >> rollNumber;

database.displayStudentRecord(rollNumber);

break;

case 5: {

int rollNumber;

cout << "Enter roll number: ";


cin >> rollNumber;

database.deleteStudent(rollNumber);

break;

case 6:

cout << "Exiting...\n";

break;

default:

cout << "Invalid choice. Please try again.\n";

break;

} while (choice != 6);

return 0;

Output

Image 01
Image 02

Image 03
Image 04

You might also like