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

If someone could assist me with this question it would be greatly appreciated, I

ID: 3561334 • Letter: I

Question

If someone could assist me with this question it would be greatly appreciated, I am currently an over the road driver and it is getting harder to consentrate on coding, please help(Part B Implement a class person with the following fields: The nam A pointer to the persons best friend A popularity counter that indicates how many people have this person as their best friend Write a program that reads in a list of names, allocates a new Peron for every one of them, and places them in a vector. Next, request the name of each best friend for every Person objects. Find the object matching the friends name, and call a set_best_friend member function to update the pointer and counter. Lastly, print out every Person objects. Labeling the name, best friend, and popularity counter for all.)

Explanation / Answer


//ClientCode.cpp - First file with main function
#include "set_best_friend.h" //include header definition of class - best_friend
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;


//function main begins program execution

int main()
{

Person MyPerson[arrSize];

MyPerson.arrInit(); //initialize age array
MyPerson.arrInput(); //input the data from the keyboard
MyPerson.arrSort(); //sort the data in ascending order
MyPerson.arrOutput(); // output the data to the display


system("pause");
return (0);

}//end main


//set_best_friend.h - second HEADER file for class definition
//Created by
//Person class definition

#include <iostream>
#include <string>
#include <iomanip>
#pragma once
using namespace std;

class Person
{
public:
Person:: Person()
{
name = " ";
age = 0;
};
void arrInit();
void arrInput();
void arrSort();
void arrOutput();

private:
string name; //name of the person ??
int age; //age of the person ??
static const int arrSize = 100; //how many names
int arrAge[arrSize]; //age of the person - array
string arrName[arrSize]; //name of the person - array
};


//Person.cpp THIRD file for member functions
#include "set_best_friend.h"
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;


//constructor initializes data members
Person::Person()
{
name = " ";
age = 0;
};

void Person::arrInput()
{
for (int s=0; s < arrSize; s++)
{

cout << "Enter name (-1 to stop): ";
cin >> arrName[s];

//if (arrName[s] == -1)
//{
// break;
//}
cout << "Enter age of " << arrName[s] << ": ";
cin >> arrAge[s];
} //end for
}

void Person::arrOutput()
{
for (int j=0; j < arrSize; ++j)
{
cout << "Name: " << setw(15) << arrName[j] << "," << setw(5) << "age: " << arrAge[j] << endl;
}
}

//insertion sort - chapter 7 - swap positions
void Person::arrSort()
{
int insertNum = 0;
string insertName;

for (int m = 0; m < arrSize; ++m)
{
for (int k = 0; k < (arrSize-1); ++k)
{
insertNum = arrAge[k+1];
insertName = arrName[k+1];

if (insertNum < arrAge[k])
{
arrAge[k+1] = arrAge[k];
arrAge[k] = insertNum;
arrName[k+1] = arrName[k];
arrName[k] = insertName;
}//end if
}//end nested inner for
}//end outer for
}//end function

//initialize array of age
void Person::arrInit()
{
for (int i=0; i < arrSize; i++)
{
arrAge[i] = 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