Create a class: Doctor, with private data members: id, name, specialization and salary
with public member function: get_data () to take input for all data members, show_data
() to display the values of all data members and get specialization () to return
specialization. Write a program to write for detail of n doctors by allocating the
memory at run time only
#include <iostream>
using namespace std;
class Doctor{
int id, salary;
string name, specialization;
public:
Doctor(){}
Doctor(int id, int sal, string name, string special){
get_data(id, sal, name, special);
}
void get_data(int id, int sal, string name, string special){
this->id = id;
this->salary = sal;
this->name = name;
this->specialization = special;
}
void show_data(){
cout<<"Name: "<<this->name<<endl;
cout<<"ID: "<<this->id<<endl;
cout<<"Specialization: "<<get_specialization()<<endl;
cout<<"Salary: "<<this->salary<<endl;
}
string get_specialization(){
return this->specialization;
}
};
int main(){
Doctor *doctors[10];
string name, specialization;
int id, salary;
for(int i = 0; i < 10; i++){
cout<<"\nEnter name of Doctor "<<i + 1<<endl;
cin>>name;
cout<<"Enter id of Doctor "<<i + 1<<endl;
cin>>id;
cout<<"Enter salary of Doctor "<<i + 1<<endl;
cin>>salary;
cout<<"Enter specialization of Doctor "<<i + 1<<endl;
cin>>specialization;
doctors[i] = new Doctor(id, salary, name, specialization);
}
for(int i = 0; i < 10; i++){
cout<<"\nDoctor "<<i + 1<<endl;
doctors[i]->show_data();
}
return 0;
}
Comments
Leave a comment