Answer to Question #185616 in C++ for Aditya Pandey

Question #185616

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


1
Expert's answer
2021-04-26T02:59:28-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS