This has really been frustrating me for hours. I have included useful comments in the program.
All the descent examples i've come across were using char instead of string.
:icon_cry:
#include <iostream>
#include <string>
using namespace std;
class Celeb
{
private:
string name; //Name of celebrity folowed by decade they were born in, E.g. Reba McEntire 50s, 2nd e.g. Gene Hackman 30s
public:
Celeb();
void setName(string);
/* bool foundDecade(string decade) //;
{
must use
string::npos
}*/
//a member function should retun sting::npos if it can't find user input in string
string getName() ;
};
Celeb::Celeb()
{
name = "No person";
}
void Celeb::setName(string celebName)
{
name = celebName;
}
string Celeb::getName() //;
{
return name;
}
void InputCelebs(Celeb * celbPtr, int size);
int main()
{
Celeb search;
string searchCelebs;
int numCelebs;
cout << "How many celebs do you want to enter: " ;
cin >> numCelebs;
Celeb * celebList;
celebList = new Celeb[numCelebs];
InputCelebs(celebList, numCelebs); //User will then proceed to enter
//list of cities and their coordinates
cout << "\nEnter last 2 number of decades you'd like to search for, ";
cout << "\n, and make sure its ends with an s, please: ";
cin >> searchCelebs;
//search.foundDecade(searchCelebs); --->>>> Call bool function
delete [] celebList;
celebList = 0;
system("pause");
return 0;
}
void InputCelebs(Celeb * celebPtr, int size)
{
string celeb_Name; //Name of of celeb followed by decade they were born on; e.g., Reba McEntire 50s
for (int index = 0; index < size; index++)
{
cout << endl;
cout << "Enter name of celebrity followed by decade they were,";
cout << "\nborn on ending with an s (like 80s, for 1980): ";
cin.ignore();
getline(cin, celeb_Name);
celebPtr[index].setName(celeb_Name);
cout << endl;
}
}