Untitled
unknown
c_cpp
4 years ago
5.2 kB
4
Indexable
/* Experiment Number 2 : 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, Contactaddress, Telephone number, Driving license no. and other. Construct the database with suitable member functions. Make use of constructor, default constructor, copy constructor, destructor, static member functions, friend class, this pointer, inline code and dynamic memory allocation operators-new and delete as well as exception handling. */ #include <iostream> #include <string.h> using namespace std; class StudData; class Student { string name; int roll_no; string cls; char *division; string dob; string *bloodgroup; static int count; public: Student() // Default Constructor { name = ""; roll_no = 0; cls = ""; division = new char; dob = "dd/mm/yyyy"; bloodgroup = new string; } static int getCount() { return count; } ~Student(){ delete division; delete bloodgroup; count--;} void getData(StudData *); void dispData(StudData *); }; class StudData { string caddress; string *telno; string *dlno; friend class Student; public: StudData() { caddress = ""; telno = new string; dlno = new string; } ~StudData() { delete telno; delete dlno; } void getStudData() { cout << "Enter Contact Address : "; cin.get(); getline(cin, caddress); while (true) { cout << "Enter telephone number"; try { string z; cin >> z; if (z.length() != 10) { throw "Telephone number is not 10 characters long\n"; } for (char i : z) { if (!isdigit(i)) { throw "Telephone number entered must be a number\n"; break; } } *telno = z; break; } catch (const char *err) { cout << err; } } cout << "Enter Driving License Number : "; cin>>*this->dlno; } void dispStudData() { cout << "Contact Address : " << caddress << endl; cout << "Telephone Number : " << *telno << endl; cout << "Driving License Number : " << *dlno << endl; } }; inline void Student::getData(StudData *st) { cout << "Enter Student Name : "; getline(cin, name); cout << "Enter Roll Number : "; cin >> roll_no; cout << "Enter Class(FE/SE/TE/BE) : "; cin.get(); getline(cin, cls); cout << "Enter Division : "; cin >> division; cout << "Enter Date of Birth : "; cin.get(); getline(cin, dob); while (true) { cout << "Enter your blood group: "; try { cin >> *this->bloodgroup; if (*this->bloodgroup == "A+" || *this->bloodgroup == "A-" || *this->bloodgroup == "B+" || *this->bloodgroup == "B-" || *this->bloodgroup == "AB+" || *this->bloodgroup == "AB+" || *this->bloodgroup == "O+" || *this->bloodgroup == "O-") { break; } else { throw "Blood grp is not valid\n"; } } catch (const char *err) { cout << err; } } st->getStudData(); count++; } inline void Student::dispData(StudData *st1) { cout << "Student Name : " << name << endl; cout << "Roll Number : " << roll_no << endl; cout << "Class : " << cls << endl; cout << "Division : " << division << endl; cout << "Date of Birth : " << dob << endl; cout << "Blood Group : " <<*bloodgroup << endl; st1->dispStudData(); } int Student::count; int main() { Student *stud1[100]; StudData *stud2[100]; int n = 0; char ch; do { stud1[n] = new Student; stud2[n] = new StudData; stud1[n]->getData(stud2[n]); n++; cout << "Do you want to add another student (y/n) : "; cin >> ch; cin.get(); } while (ch == 'y' || ch == 'Y'); for (int i = 0; i < n; i++) { cout << "---------------------------------------------------------------" << endl; stud1[i]->dispData(stud2[i]); } cout << "---------------------------------------------------------------" << endl; cout << "Total Students : " << Student::getCount(); cout << endl << "---------------------------------------------------------------" << endl; return 0; }
Editor is loading...