Answer to Question #264365 in C++ for |=0|_||2

Question #264365

Modify the program by creating an array of n objects using

pointers. Show the details of n items by using pointers to object concept.


1
Expert's answer
2021-11-14T09:21:32-0500
#include<iostream>
#include<string>
using namespace std;

struct Person
{
	string Name;
	int age;
	Person(string _name, int _age):Name(_name), age(_age){}
};

int main()
{
	const int N = 4;
	Person a("Jack", 25);
	Person b("Jane", 27);
	Person c("Mike", 30);
	Person d("Ann", 23);
	Person membs[N]= { a,b,c,d };
	Person *arr = membs;
	for (Person* i = &arr[0]; i != &arr[N]; i++)
	{
		cout << "Person " << i->Name << "\tage " << i->age << endl;
	}
}

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