/* OOP Group A - 1
Q2. Develop A Program In C++ To Create A Database Of Student's Information System Containing The Following
Information : Name, Roll Number, Class, Division, Date Of Birth, Blood Group, Telephone No And Other.
Consruct The Database With Suitable Member Functions. Make Use Of Constructer, Default Constructer,
Copy Constructer, Destructer, Static Member Functions, friend Class, this Pointer, inline Code, Dynamic
Memory Allocation, Operators - new and delete As Well As Exception Handling.
*/
#include <iostream>
using namespace std;
class Student
{
private:
string name;
int rollNo;
string className;
char division;
string bloodGroup;
string mobileNumber;
int total;
float percentage;
static int count;
public:
Student(); // Default Constucter Declaration
Student(Student &obj); // Copy Constructer
friend bool inline checkStudent(Student, int);
friend void inline printDetails(Student); // Friend Function Declaration
~Student() {} // Destructer
};
int Student::count = 0;
int inline checkInteger(int Input, string content)
{
while (!cin.good())
{
cout << "Wrong Input, Please Enter Integers Only!!\n";
cin.clear(); // Clears the previous Input
cin.ignore(100, '\n'); // Ignores the Wrong Input till 100 Characters
cout << content;
cin >> Input;
}
return Input;
}
// Default Constructer Definition
Student ::Student()
{
cout << "\nStudent " << ++this->count << endl;
cout << "\nEnter Name : ";
cin.clear();
cin.ignore(100, '\n');
getline(cin, name);
string content = "Enter Roll No : ";
cout << content;
cin >> rollNo;
rollNo = checkInteger(rollNo, content);
cout << "Enter Class : ";
cin.clear();
cin.ignore(100, '\n');
getline(cin, className);
cout << "Enter Division : ";
cin >> division;
cout << "Enter Blood Group : ";
cin >> bloodGroup;
cout << "Enter Mobile Number : ";
cin >> mobileNumber;
while (true)
{
string content1 = "\nEnter Total Marks Got Out of 500\n";
cout << content1;
cin >> total;
total = checkInteger(total, content1);
if (total > 500)
{
cout << "Marks Should Be Under 500 Only\n";
continue;
}
else
{
break;
}
}
percentage = ((float)total / 500) * 100;
}
bool checkStudent(Student obj, int rollNum)
{
if (obj.rollNo == rollNum)
{
return 1;
}
else
{
return 0;
}
}
// Friend Function Definition
void printDetails(Student obj)
{
cout << "Name : " << obj.name << endl
<< "Roll No : " << obj.rollNo << endl
<< "Class : " << obj.className << endl
<< "Division : " << obj.division << endl
<< "Mobile Number : " << obj.mobileNumber << endl
<< "Blood Group : " << obj.bloodGroup << endl
<< "\nTotal Marks : " << obj.total << endl
<< "Percentage : " << obj.percentage << " %" << endl;
}
// Copy Construter Definition
Student ::Student(Student &obj)
{
name = obj.name;
rollNo = obj.rollNo;
className = obj.className;
division = obj.division;
mobileNumber = obj.mobileNumber;
bloodGroup = obj.bloodGroup;
total = obj.total;
percentage = obj.percentage;
}
int main()
{
int count = 0;
int num;
int numberOfStudents = 0;
int numOfStudentsToDelete;
int rollNoOfStudentToDelete;
Student *stud[10];
Student *student[10];
string content1 = "Enter The Number Of Students\n";
string content2 = "Enter The Number Of Students You Want To Delete\n";
string content3 = "Enter The Roll No. of Student To delete\n";
label1:
while (true)
{
int userInput;
string content = "\n1. Press 1 To Add Students\n2. Press 2 To Display List of Students\n3. Press 3 To Delete Details of Students\n4. Press 4 To Display List of Students After Deletion\n5. Press 5 To Print Number of Students\n6. Press 6 To Exit\n";
cout << content;
cin >> userInput;
userInput = checkInteger(userInput, content);
switch (userInput)
{
case 1:
cout << content1;
cin >> numberOfStudents;
numberOfStudents = checkInteger(numberOfStudents, content1);
for (int i = 0; i < numberOfStudents; i++)
{
stud[i] = new (nothrow) Student(); // Dynamic Allocaion In The Heap Memory With The Help New Operator
if (!stud[i])
{
cout << "Memory Allocation Failed\n";
break;
}
}
cout << "Details of All Students Successfully Added\n";
goto label1;
break;
case 2:
if (numberOfStudents == 0)
cout << "No Details of Students To Display\n";
else
{
for (int i = 0; i < numberOfStudents; i++)
{
cout << "\n****** Entered Details Of Student " << i + 1 << " ******" << endl;
printDetails(*stud[i]);
}
}
break;
case 3:
if (numberOfStudents == 0)
{
cout << "No Students To Delete\n";
continue;
}
num = numberOfStudents;
cout << content3;
cin >> rollNoOfStudentToDelete;
rollNoOfStudentToDelete = checkInteger(rollNoOfStudentToDelete, content3);
for (int i = 0; i < num; i++)
{
if (checkStudent(*stud[i], rollNoOfStudentToDelete))
{
numberOfStudents--;
continue;
}
else
{
student[count] = new (nothrow) Student(*stud[i]);
if (!student[count])
{
cout << "Memory Allocation Failed\n";
break;
}
count++;
}
}
goto label1;
break;
case 4:
if (numberOfStudents == 0)
cout << "No Details of Students To Display\n";
else
{
for (int i = 0; i < numberOfStudents; i++)
{
cout << "\n****** Entered Details Of Student " << i + 1 << " ******" << endl;
printDetails(*student[i]);
}
}
break;
case 5:
cout << "Total Students = " << numberOfStudents << endl;
break;
case 6:
exit(0);
default:
cout << "Please Enter Correct Input\n";
break;
}
}
for (int i = 0; i < numberOfStudents; i++)
{
delete stud[i];
delete student[i];
}
return 0;
}
// Output
// 1. Press 1 To Add Students
// 2. Press 2 To Display List of Students
// 3. Press 3 To Delete Details of Students
// 4. Press 4 To Display List of Students After Deletion
// 5. Press 5 To Print Number of Students
// 6. Press 6 To Exit
// 1
// Enter The Number Of Students
// 2
// Student 1
// Enter Name : Ashish Patil
// Enter Roll No : 24
// Enter Class : Secomp
// Enter Division : A
// Enter Blood Group : A+
// Enter Mobile Number : 7891829818
// Enter Total Marks Got Out of 500
// 455
// Student 2
// Enter Name : Mayur Patil
// Enter Roll No : 14
// Enter Class : Secomp
// Enter Division : A
// Enter Blood Group : B+
// Enter Mobile Number : 8109819810
// Enter Total Marks Got Out of 500
// 445
// Details of All Students Successfully Added
// 1. Press 1 To Add Students
// 2. Press 2 To Display List of Students
// 3. Press 3 To Delete Details of Students
// 4. Press 4 To Display List of Students After Deletion
// 5. Press 5 To Print Number of Students
// 6. Press 6 To Exit
// 2
// ****** Entered Details Of Student 1 ******
// Name : Ashish Patil
// Roll No : 24
// Class : Secomp
// Division : A
// Mobile Number : 7891829818
// Blood Group : A+
// Total Marks : 455
// Percentage : 91 %
// ****** Entered Details Of Student 2 ******
// Name : Mayur Patil
// Roll No : 14
// Class : Secomp
// Division : A
// Mobile Number : 8109819810
// Blood Group : B+
// Total Marks : 445
// Percentage : 89 %
// 1. Press 1 To Add Students
// 2. Press 2 To Display List of Students
// 3. Press 3 To Delete Details of Students
// 4. Press 4 To Display List of Students After Deletion
// 5. Press 5 To Print Number of Students
// 6. Press 6 To Exit
// 3
// Enter The Roll No. of Student To delete
// 25
// 1. Press 1 To Add Students
// 2. Press 2 To Display List of Students
// 3. Press 3 To Delete Details of Students
// 4. Press 4 To Display List of Students After Deletion
// 5. Press 5 To Print Number of Students
// 6. Press 6 To Exit
// 4
// ****** Entered Details Of Student 1 ******
// Name : Ashish Patil
// Roll No : 24
// Class : Secomp
// Division : A
// Mobile Number : 7891829818
// Blood Group : A+
// Total Marks : 455
// Percentage : 91 %
// ****** Entered Details Of Student 2 ******
// Name : Mayur Patil
// Roll No : 14
// Class : Secomp
// Division : A
// Mobile Number : 8109819810
// Blood Group : B+
// Total Marks : 445
// Percentage : 89 %
// 1. Press 1 To Add Students
// 2. Press 2 To Display List of Students
// 3. Press 3 To Delete Details of Students
// 4. Press 4 To Display List of Students After Deletion
// 5. Press 5 To Print Number of Students
// 6. Press 6 To Exit
// 3
// Enter The Roll No. of Student To delete
// 14
// 1. Press 1 To Add Students
// 2. Press 2 To Display List of Students
// 3. Press 3 To Delete Details of Students
// 4. Press 4 To Display List of Students After Deletion
// 5. Press 5 To Print Number of Students
// 6. Press 6 To Exit
// 4
// ****** Entered Details Of Student 1 ******
// Name : Ashish Patil
// Roll No : 24
// Class : Secomp
// Division : A
// Mobile Number : 7891829818
// Blood Group : A+
// Total Marks : 455
// Percentage : 91 %
// 1. Press 1 To Add Students
// 2. Press 2 To Display List of Students
// 3. Press 3 To Delete Details of Students
// 4. Press 4 To Display List of Students After Deletion
// 5. Press 5 To Print Number of Students
// 6. Press 6 To Exit
// 5
// Total Students = 1
// 1. Press 1 To Add Students
// 2. Press 2 To Display List of Students
// 3. Press 3 To Delete Details of Students
// 4. Press 4 To Display List of Students After Deletion
// 5. Press 5 To Print Number of Students
// 6. Press 6 To Exit
// 6
Comments
Post a Comment