Question

#include <iostream> #include<string> #include<vector> using namespace std; struct patient { string name; char Gender; int d,m,y;...

#include <iostream>
#include<string>
#include<vector>
using namespace std;

struct patient
{
string name;
char Gender;
int d,m,y;
string nationality;
int civilID;
int phoneNumber;
string TypeOfInsurance;
};
Activities
I. Declare a variable from the struct Patient called pat.
II. Fill out the information of pat by reading them from the input.
III. Declare a pointer of type Patient called pat_ptr and assign the address of pat to it.
IV. Change the value of name field of pat by accessing it through pat_ptr.
V. Write all the information inside pat on the output by accessing the fields through pat_ptr.
VI. Declare a second variable from the struct Patient called pat2.
VII.
VIII. Declare a vector of type pointer to struct Patient called pat_ptr_vect IX. Add the address of pat and pat2 to this vector.
X. Print the content of pat_ptr_vect on the output with appropriate prompts.
XI. Include the final code and your outputs inside your workbook and reflect on them.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include<string>
#include<vector>
using namespace std;

struct patient
{
string name;
char Gender;
int d,m,y;
string nationality;
int civilID;
int phoneNumber;
string TypeOfInsurance;
};
int main()
{
//Declare a variable from the struct Patient called pat.
struct patient pat;
  
//Fill out the information of pat by reading them from the input.
cout<<"Enter name ---------> ";
cin>>pat.name;
cout<<"Enter Gender ---------> ";
cin>>pat.Gender;
cout<<"Enter DOB as d,m,y ---------> ";
cin>>pat.d>>pat.m>>pat.y;
cout<<"Enter nationality ---------> ";
cin>>pat.nationality;
cout<<"Enter civilID ---------> ";
cin>>pat.civilID;
cout<<"Enter phone Number ---------> ";
cin>>pat.phoneNumber;
cout<<"Enter Insurance type ---------> ";
cin>>pat.TypeOfInsurance;
  
// Declare a pointer of type Patient called pat_ptr and assign the address of pat to it.
struct patient* pat_ptr=&pat;
  
//Change the value of name field of pat by accessing it through pat_ptr
pat_ptr->name="Krishna";
cout<<endl;
  
// Write all the information inside pat on the output by accessing the fields through pat_ptr.
cout<<"The Detailed information is -----> "<<endl;
cout<<"Name ----------> "<<pat_ptr->name<<endl;
cout<<"Gender ----------> "<<pat_ptr->Gender<<endl;
cout<<"Date of birth ----------> "<<pat_ptr->d<<"-"<<pat_ptr->m<<"-"<<pat_ptr->y<<endl;
cout<<"nationality ----------> "<<pat_ptr->nationality<<endl;
cout<<"Civil Id ----------> "<<pat_ptr->civilID<<endl;
cout<<"Phone Number ----------> "<<pat_ptr->phoneNumber<<endl;
cout<<"Insurance Type ----------> "<<pat_ptr->TypeOfInsurance<<endl;
  
//Declare a second variable from the struct Patient called pat2
struct patient pat2;
  
//Declare a vector of type pointer to struct Patient called pat_ptr_vect
vector<struct patient*> pat_ptr_vect;
  
//Add the address of pat and pat2 to this vector.
pat_ptr_vect.push_back(&pat);
pat_ptr_vect.push_back(&pat2);
cout<<endl;
  
//Print the content of pat_ptr_vect on the output with appropriate prompts.
//Only 'pat' have data and 'pat2' is empty So, it shows the information of 'pat' only.
cout<<"The Content of vector is -----> "<<endl;
vector<struct patient*>::iterator it=pat_ptr_vect.begin(); //Pointing to beginning address
cout<<"Name ----------> "<<pat_ptr_vect[0]->name<<endl;
cout<<"Gender ----------> "<<pat_ptr_vect[0]->Gender<<endl;
cout<<"Date of birth ----------> "<<pat_ptr_vect[0]->d<<"-"<<pat_ptr_vect[0]->m<<"-"<<pat_ptr_vect[0]->y<<endl;
cout<<"nationality ----------> "<<pat_ptr_vect[0]->nationality<<endl;
cout<<"Civil Id ----------> "<<pat_ptr_vect[0]->civilID<<endl;
cout<<"Phone Number ----------> "<<pat_ptr_vect[0]->phoneNumber<<endl;
cout<<"Insurance Type ----------> "<<pat_ptr_vect[0]->TypeOfInsurance<<endl;
}


Add a comment
Know the answer?
Add Answer to:
#include <iostream> #include<string> #include<vector> using namespace std; struct patient { string name; char Gender; int d,m,y;...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT