Question
The program first reads integer participantCount from input, representing the number of pairs of inputs to be read. Each pair has a string and an
The program first reads integer participantCount from input, representing the number of pairs of inputs to be read. Each pair has a string and an integer. One Participant object is created for each pair and added to vector participantList. Output "Average participant age: " followed by the average age of all the Participant objects.
Ex: If the input is:
5 Eli 89 Jan 57 Ari 68 Noa 72 Jen 11
then the output is:
Average participant age: 59.4
Note: The vector has at least one element.
#include
class Participant { public: void SetDetails(string newName, int newAge); int GetAge() const; private: string name; int age; };
void Participant::SetDetails(string newName, int newAge) { name = newName; age = newAge; }
int Participant::GetAge() const { return age; }
int main() { int participantCount; unsigned int i; vector
cin >> participantCount; for (i = 0; i < participantCount; ++i) { cin >> currName; cin >> currAge; currParticipant.SetDetails(currName, currAge); participantList.push_back(currParticipant); } sumAge = 0.0;
/* Your code goes here */
return 0; }
c++ and please please make it correct
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started