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
  • Find the problems with this program #include <iostream> using namespace std; struct Student { string name;...

    Find the problems with this program #include <iostream> using namespace std; struct Student { string name; int grade; } int main() { struct Student mary; Mary:name = "Mary"; Mary:grade = 100; cout << mary:name " got a " << mary:grade << endl;   return 0; }

  • #include "stdafx.h" #include <iostream> #include <vector> #include <cassert> using namespace std; // function prototypes int loadDisk(vector<int>...

    #include "stdafx.h" #include <iostream> #include <vector> #include <cassert> using namespace std; // function prototypes int loadDisk(vector<int> &firstPeg, int numDisks); void printPeg(vector<int> &peg); int hanoi(struct pegType &startPeg, struct pegType &swapPeg, struct pegType &endPeg, int numDisk); void moveDisk(struct pegType &startPeg, struct pegType &endPeg); struct pegType {    vector <int> diskStack;    int name; }; int main() {    int numDisk = 7;    int i;    pegType peg1, peg2, peg3;    peg1.name = 1;    peg2.name = 2;    peg3.name = 3;...

  • #include <iostream> #include <iomanip> #include <vector> #include <string> using namespace std; struct menuItemType { string menuItem;...

    #include <iostream> #include <iomanip> #include <vector> #include <string> using namespace std; struct menuItemType { string menuItem; double menuPrice; }; void getData(menuItemType menuList[]); void showMenu(menuItemType menuList[], int x); void printCheck(menuItemType menuList[], int menuOrder[], int x); int main() { const int menuItems = 8; menuItemType menuList[menuItems]; int menuOrder[menuItems] = {0}; int orderChoice = 0; bool ordering = true; int count = 0; getData(menuList); showMenu(menuList, menuItems); while(ordering) { cout << "Enter the number for the item you would\n" << "like to order, or...

  • CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer;...

    CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer; cout << "MENU" << endl; cout << "a - Add item to cart" << endl; cout << "d - Remove item from cart" << endl; cout << "c - Change item quantity" << endl; cout << "i - Output items' descriptions" << endl; cout << "o - Output shopping cart" << endl; cout << "q - Quit" << endl << endl; while (true) {...

  • USING THIS CODE: #include <iostream> #include <string> using namespace std; class Contact { //this class cannot...

    USING THIS CODE: #include <iostream> #include <string> using namespace std; class Contact { //this class cannot be viewed from outside of the private class. //only the class functions within the class can access private members. private: string name; string email; string phone; //the public class is accessible from anywhere outside of the class //however can only be within the program. public: string getName() const { return name; } void setName(string name) { this->name = name; } string getEmail() const {...

  • Example program #include <string> #include <iostream> #include <cmath> #include <vector> using namespace std; vector<int> factor(int n)...

    Example program #include <string> #include <iostream> #include <cmath> #include <vector> using namespace std; vector<int> factor(int n) {     vector <int> v1;     // Print the number of 2s that divide n     while (n%2 == 0)     {         printf("%d ", 2);         n = n/2;         v1.push_back(2);     }     // n must be odd at this point. So we can skip     // one element (Note i = i +2)     for (int i = 3; i <=...

  • #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; struct transition{ // transition structure...

    #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; struct transition{ // transition structure char start_state, to_state; char symbol_read; }; void read_DFA(struct transition *t, char *f, int &final_states, int &transitions){ int i, j, count = 0; ifstream dfa_file; string line; stringstream ss; dfa_file.open("dfa.txt"); getline(dfa_file, line); // reading final states for(i = 0; i < line.length(); i++){ if(line[i] >= '0' && line[i] <= '9') f[count++] = line[i]; } final_states = count; // total number of final states // reading...

  • #include <iostream> using namespace std; struct ListNode string data; ListNode *next; ); int main() { ListNode...

    #include <iostream> using namespace std; struct ListNode string data; ListNode *next; ); int main() { ListNode *ptr, "list; list - new ListNode; list->data - "Boston"; ptr - new ListNode; ptr)data - "New York"; ptr->next = nullptr; list->next = new ListNode; list->next->data - "Houston": list->next->next = ptr 17 new code goes here Which of the following code correctly inserts "Chicago" at beginning of the list when added at point of insertion indicated above None of these No answer text provided. list->data...

  • This program illustrates dynamic variables #include <iostream> using namespace std; int main () {    int...

    This program illustrates dynamic variables #include <iostream> using namespace std; int main () {    int *p1;    p1 = new int;             // Variables created using the new operator are called dynamic variables    cout << "Enter an integer \n";    cin >> *p1;    *p1 = *p1 + 7;    cout << << "Your input + 7 = " << *p1 << endl;    delete p1;                // Delete the dynamic variable p1 and return the memory occupied by p1 to...

  • #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str);...

    #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() {    char string[100];    char inputChoice, choice[2];    int vowelTotal, consonantTotal;    //Input a string    cout << "Enter a string: " << endl;    cin.getline(string, 100);       do    {        //Displays the Menu        cout << "   (A) Count the number of vowels in the string"<<endl;        cout << "   (B) Count...

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