Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question#2: class patient { private: string Name; float age; int ID; string doct

ID: 3551193 • Letter: Q

Question

Question#2:


class patient


{


private:


string Name;


float age;


int ID;


string doctorName;


public:


. . . . . . . . ..


};


1- make these functions:


- Parameterized constructor.


- Set & get function for each data member.


(get functions should be read-only).


- Print function to display the information of patient.


(print function should be read-only).


2- In the main function, make three objects from class patient.


3- Each patient has unique ID which is generated automatically and the ID not


4- call function print for three objects.


change after that.

Explanation / Answer

#include<stdio.h>
#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;

class patient
{

private:
string Name;
float age;
static int currID;
string doctorName;
// automatic generation of ID
const int ID;

public:

// parametrized constructor
patient(string name_,float age_,string doc_name):
     Name(name_),
     age(age_),
     doctorName(doc_name),
     ID(currID++)
     {
     }
    
//get functions
string getName(void){
     return Name;
}

float getage(void){
     return age;
}

int getID(void){
     return ID;
}

string getdoc_Name(void){
     return doctorName;
}

//set functions
void setName(string nam){
     Name=nam;
}

void setage(float age_){
     age=age_;
}

void setdoc_Name(string doc_name){
     doctorName=doc_name;
}

};

void print_info(patient p){
     cout<<"Patient's name is "<<p.getName()<<endl;
     cout<<"Patient's age is "<<p.getage()<<endl;
     cout<<"Patient's ID is "<<p.getID()<<endl;
     cout<<"Patient's doctor's name is "<<p.getdoc_Name()<<endl<<endl;
}

//initialising the id for automatically genrating the patient_id

int patient::currID = 1;

int main(){
       
    //generating instances for 3 patients
    patient patient1("pat1",25,"doc1");
    patient patient2("pat2",28,"doc2");
    patient patient3("pat3",35,"doc3");
   

    // printing info of 3 patients
    print_info(patient1);
    print_info(patient2);
    print_info(patient3);
   
    return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote