Hi, I've been trying to catch up on my class and pointer code (both are weak areas for me at the moment). I tried researching as much of the code as possible and getting some in-class help, **Edit Changed program, no longer gives build error**.
This is designed to take in peoples' names and best friends and return each person's "popularity count." The class must include a string for name, pointer for the person's best friend, and an int for popularity.
The program must also take multiple "Person" variables into a vector.
Person.h:
#include <iostream>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <stdlib.h> // for srand ( ) and rand ( )
#include <time.h> // for time ( ) and time_t
#include <string>
#include <vector>
using std::rand;
using std::srand;
using std::fixed;
using std::setprecision;
using std::cin;
using std::cout;
using std::endl;
using std::string;
using namespace std;
class Person
{
public:
Person(int initialPopularity); // Declare Person class
double getPopularity(); // Declare getPopularity function
void setName(string myName); // Declare setName function
void favoritePerson(); // Declare favoritePerson function
void popularityTally();
void getBestFriend();
private:
string name; // declare the name of the person
Person *bestFriend;
int popularityCount;
string bestFriendQuery;
};
Person.cpp (functions)
#include <iostream>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <stdlib.h> // for srand ( ) and rand ( )
#include <time.h> // for time ( ) and time_t
#include <string>
#include <vector>
using std::rand;
using std::srand;
using std::fixed;
using std::setprecision;
using std::cin;
using std::cout;
using std::endl;
using std::string;
using namespace std;
#include "Person.h" // Include definition of class Account
int main()
{
vector<Person> names;
int count = 0;
string tempName = "";
int escape = 0;
cout << "Enter name (-1 to stop): ";
cin >> tempName;
if (tempName != "-1"){
names.push_back (1);
names[count].setName(tempName);
count++;
}
while (tempName != "-1"){
cout << "Enter name (-1 to stop): ";
cin >> tempName;
while (escape == 0){
escape = 1;
for (int i; i < count; i++){
if (tempName == names[i].name){
cout << "No duplicate names please." << endl;
cout << "Enter name (-1 to stop): ";
cin >> tempName;
escape = 0;
}
}
}
if (tempName != "-1"){
names.push_back (1);
names[count].setname(tempName);
count++;
}
}
for (int i; i < count; i++){
names[i].favoritePerson();
}
for (int i; i < count; i++){
for (int j; i < count; j++){
if (names[j].name == names[i].bestFriendQuery){
names[i].bestFriend = &names[j];
}
}
names[i].popularityTally();
}
for (int i; i < count; i++){
cout << "name: " << names[i] << endl;
cout << "best friend: " ;
names[i].getBestFriend();
cout << "" << endl;
cout << "popularity count: " << names[i].getPopularity << endl;
}
system("PAUSE"); //Prompt for enter.
return 0;
}
I'm thinking I called a function incorrectly or used a pointer wrong.