OOP (Lab) Project #1 Report
OOP (Lab) Project #1 Report
Name:
Reg no:
Teacher:
Introduction
This software will be developed for the University administration to keep record of students. Student
Database Management System will be implemented using C++ Class Constructors and Destructors.
Constructor is a method for a class that gets called automatically whenever an object of the class is
created. It is used to give the class’s data initial values.
Destructor is a method for a class that gets called automatically whenever an object of the class is
deleted. It is used to delete any memory that the class has dynamically allocated.
Default Constructor is a constructor that takes no parameters, and gives the class’s data default
initial values. It is always called for each array element when an array of the class’s objects is
created.
Copy Constructor is a constructor that takes another object of the same class as its reference
parameter, and makes the new object an exact copy of the argument
Project description
Student Database Management System is a C++ console application that helps the university
administration to keep record of students. This application will use file handling for managing
student data. Application will include following features
1. Add Student Record
2. Delete Student Record
3. Display Students
Students Database Management System
Code:
#include<iostream>
#include<fstream> //Header files
#include<stdlib.h>
#include<string.h>
#include<conio.h>
class Student
{
private:
int admNo;
//Addmission no
char name[20]; // Array
of names
char gender; // Gender of
each student
char course[20]; // Course of
students
char address[100]; // Address of
students
char phoneNo[15]; // Cell no of
students
public:
Student() //Default
Constructor
{ }
Student(Student &st) //Copy
Constructor
{
admNo = st.admNo;
strcpy(name, st.name); //The strcpy() function in C++ copies a character
string from source to destination.
gender = st.gender;
strcpy(course, st.course);
strcpy(address, st.address);
strcpy(phoneNo, st.phoneNo);
Students Database Management System
}
void getStdData();
void showStdData();
int getAdmNo() // Getter
for addmission no.
{
return admNo;
}
~Student() //
destructor
{ }
};
inline void Student::getStdData() // fucntion member
decleared outside the class
{
cout << "\n\nEnter Student Details......\n";
cout << "Enter Admission No. : ";
cin >> admNo;
cout << "Enter Full Name : ";
cin.ignore();
cin.getline(name, 20);
cout << "Enter Gender (M/F) : ";
cin >> gender;
cout << "Enter Course : ";
cin.ignore();
cin.getline(course, 20);
cout << "Enter Address : ";
cin.getline(address, 100);
cout << "Enter Phone No. : ";
cin.getline(phoneNo, 15);
cout << endl;
}
inline void Student::showStdData()
{
void addStdData()
{
ofstream fout;
fout.open("Students.dat", ios::binary | ios::out | ios::app); // fout used instead
of cout
std1.getStdData();
fout.write((char * ) &std1, sizeof(std1));
fout.close();
cout << "\n\nData Successfully Saved to File....\n";
}
void displayStdData()
{
ifstream fin;
// fin used insted of cin
fin.open("Students.dat", ios:: in | ios::binary);
while (fin.read((char * ) &std1, sizeof(std1)))
{
std1.showStdData();
}
fin.close();
cout << "\n\nData Reading from File Successfully Done....\n";
}
void deleteStdData()
{
int addno;
bool isfound = false;
ifstream fin;
ofstream tempFile;
if (isfound == false)
{
cout << "The Admission No. " << addno << " not found....\n\n";
}
remove("Students.dat");
rename("TempFile.dat", "Students.dat");
}
// Main Function Decleration
int main()
{
cout<<"\n";
cout<<"\n";
cout<<"\t\t\t\t\t*****************************************************"<<endl;
cout<<"\t\t\t\t\t Student Management System "<<endl;
cout<<"\t\t\t\t\t*****************************************************"<<endl;
cout<<"\n";
cout<<"\n";
cout<<"\n";
cout<<"\n";
cout<<"\t\t\t\t\tUniversity:"<<endl;
cout<<"\t\t\t\t\t___________"<<endl;
cout<<"\n";
cout<<"\t\t\t\t\t University"<<endl;
cout<<"\n";
cout<<"\t\t\t\t\tSubmitted to:"<<endl;
cout<<"\t\t\t\t\t_____________"<<endl;
cout<<"\n";
cout<<"\t\t\t\t\tSir "<<endl;
cout<<"\n";
cout<<"\t\t\t\t\tProject Made by:"<<endl;
cout<<"\t\t\t\t\t________________"<<endl;
cout<<"\n";
cout<<"\t\t\t\t\t1."<<endl;
cout<<"\t\t\t\t\tReg no. "<<endl;
cout<<"\t\t\t\t\tBS(CS) 2 "<<endl;
cout<<"\t\t\t\t\t2. "<<endl;
cout<<"\t\t\t\t\tReg no."<<endl;
cout<<"\t\t\t\t\tBS(CS) 2"<<endl;
cout<<"\n";
cout<<"To Continoue .... press any key..."<<endl;
getch();
system ("cls");
int ch;
do {
char choice_1;
cout << "0. Exit from Program\n";
cout << "1. Add Student Record\n";
cout << "2. Display Students\n";
cout << "3. Delete Student\n";
cout << "Enter your choice : ";
cin >> ch;
Students Database Management System
system("cls");
switch (ch) {
case 1:
addStdData();
break;
case 2:
displayStdData();
break;
case 3:
deleteStdData();
break;
}
// system("pause");
} while (ch);
return 0;
}