lundi 2 mars 2015

How to use an accessor method that takes the user index and returns his/her first name.


3.) string getFirstName(int ind) const: An accessor method that takes the user index and returns his/her first name.


This is the problem im working on towards my program and as it says above im supposed to use an accessor method that takes the user index and returns his/ her first name???


Here is my code so far but im very confused how to go about using a accessor method



string RatingDB::getFirstName(int ind) const
{class getFirstName;

{
public:


return "";
}
}


For reference here is my program code so far



// TODO: implement all these method stubs!
void RatingDB::loadFile(string filename)
{
ifstream OpenFile;
OpenFile.open (filename);

// if this file does not exist then end the program
if (!OpenFile.is_open())
{
cout << "can't open this file!" << endl;
exit(EXIT_FAILURE);
}

int i = 0;


char c;
while(! OpenFile.eof())
{

do {
c=OpenFile.get();
if(c!= ' ')
m_firstNames[i].push_back(c);
} while(c!= ' ');

do {
c=OpenFile.get();
if(c!= ' ')
m_lastNames[i].push_back(c);
}while(c!= ' ');

do {
c=OpenFile.get();
if(c!= '/n' && OpenFile.eof())
m_Ratings[i].push_back(c);

} while(c!= '/n' && OpenFile.eof());
i++;
}










}

string RatingDB::getFirstName(int ind) const
{class getFirstName;

{
public:


return "";
}
}
string RatingDB::getLastName(int ind) const
{
return "";
}

vector<int> RatingDB::getRatingVector(int ind) const
{
return vector<int>();
}

int RatingDB::getNumberOfUsers() const
{
return -1;
}

void RatingDB::insertRating(string firstName, string lastName, string strRatings)
{

}

void RatingDB::displayRatings() const
{

}

int RatingDB::compareRatings(const vector<int>& RatingVector1, const vector<int>& RatingVector2) const
{
return -1;
}

void RatingDB::findSimUsers(const vector<int>& ratingVector, vector<int>& friendVector, vector<int>& scoreVector)
{

}

vector<int> RatingDB::parseVectorString(string strRatings)
{
return vector<int>(1);
}

//************************************************************************************************************************
void RatingDB::findTenBestMatches(const vector<int>& RatingVector, vector<int>& returnVector)
{
vector<int> sortVector(getNumberOfUsers()); //create a vector of integers representing each index in your vector of structures
bool swapped; //a boolean to indicate if any swaps have been made during this pass of the loop.

for(int i = 0; i < getNumberOfUsers(); i++) //initialize the array so that we have an integer indicating the location in
sortVector[i] = i; //your structure vector for every user that is read in.

do{ //keep doing the following if we swap at least once during the pass
swapped = false; //set the swapped variable for this pass
for(int i = 0; i < getNumberOfUsers() - 1; i++) //we are going to look at each element in the vector and see if it has a ranking lower
{ //than the next element. If so, the two need to be swapped.
if(compareRatings(RatingVector, getRatingVector(sortVector[i])) < compareRatings(RatingVector, getRatingVector(sortVector[i + 1])))
{ //we compare the two rankings and swap the two in the array if the first is lower than the second
//(we want the best rankings first)
int temp;
temp = sortVector[i]; //swap this one and the next one
sortVector[i] = sortVector[i + 1];
sortVector[i + 1] = temp;
swapped = true; //if we moved anything, then another pass is necessary
}
}
}while(swapped);

for(int i = 0; i < 10; i++) //copy the top ten indexes to the returnVector
if(i < getNumberOfUsers()) //if there are at least 10 users
returnVector.push_back(sortVector[i]); //copy the index
}



Aucun commentaire:

Enregistrer un commentaire