Untitled
unknown
python
4 years ago
3.7 kB
6
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 withsuitable member functions. Make use of constructor, default constructor, copy constructor,destructor, static member functions, friend class, this pointer, inlinecode and dynamic memory allocation operators-new and delete as well as exception handling. */ #include<iostream> #include<string> using namespace std; class Data; class Student{ string name; int roll_no; string cls; string* division; string dob; string* bloodgroup; static int count; public: Student() // Default Constructor { name=""; roll_no=0; cls=""; division=new string; dob="dd/mm/yyyy"; bloodgroup=new string[4]; } ~Student() { delete division; delete[] bloodgroup; } static int getCount() { return count; } void getData(Data*); void dispData(Data*); }; class Data{ string caddress; long int* telno; long int* dlno; friend class Student; public: Data() //Default constructor { caddress=""; telno=new long; dlno=new long; } ~Data() { delete telno; delete dlno; } void getStudData() { cout<<"Enter Contact Address : "; cin.get(); getline(cin,caddress); cout<<"Enter Telephone Number : "; cin>>*telno; cout<<"Enter Driving License Number : "; cin>>*dlno; } void dispStudData() { cout<<"Contact Address : "<<caddress<<endl; cout<<"Telephone Number : "<<*telno<<endl; cout<<"Driving License Number : "<<*dlno<<endl; } }; inline void Student::getData(Data* st) { cout<<"Enter Student Name : "; getline(cin,name); cout<<"Enter Roll Number : "; cin>>roll_no; cout<<"Enter Class : "; cin.get(); getline(cin,cls); cout<<"Enter Division : "; cin>>division; cout<<"Enter Date of Birth : "; cin.get(); getline(cin,dob); cout<<"Enter Blood Group : "; cin>>bloodgroup; st->getStudData(); count++; } inline void Student::dispData(Data* 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]; Data* stud2[100]; int n=0; char ch; do { stud1[n]=new Student; stud2[n]=new Data; 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; for(int i=0;i<n;i++) { delete stud1[i]; delete stud2[i]; } return 0; }
Editor is loading...