NathanOliver 429 Veteran Poster Featured Poster

Can you post the code that you have now?

NathanOliver 429 Veteran Poster Featured Poster

you might want to look into the Sieve of Eratosthenes

NathanOliver 429 Veteran Poster Featured Poster

ShoeList will have a member that is a shoe array. Then when you want to load the ShoeList you would call load from the shoe list and pass it the file name or ask for the file name from the user.

class ShoeList
{
public:
    ShoeList() { shoes = NULL; }

    void Load()
    {
        int size;
        ifstream fin(some file name);
        fin >> size;

        shoes = new Shoe[size];

        // read in file here into the shoes array
    }

private:
    Shoe * shoes
};

// in main
ShoeList shoes;
shoes.Load();  
// ^ this will read the file and store all of the shoes in shoes.  
//   then all you need is to add access members to allow you to use the shoes.
NathanOliver 429 Veteran Poster Featured Poster

Yes in ShoeList you could have Shoe shoes[50];

NathanOliver 429 Veteran Poster Featured Poster

Ok. Can you then set a max on the number of shoe objects then like before?

No you would have to either use an array of fixed length or make your own vector.

Also loading the data from the file should that be done by overloading the stream extraction operator?

You can defenitly do that. That will make the syntax look much cleaner. You could also get the values from the file and use the setters to set the data to the shoe object. If I was coding it I would overide the stream operators. You could also change the file to a binary file and use serialization.

NathanOliver 429 Veteran Poster Featured Poster

Not really. you have two ways to inilizie class variables. you can do

Shoe() : name(""), shoeSize(0), number(0) {}

or you can do

Shoe()
{
    name = "";
    shoeSize = 0;
    number = 0;
}

Here is a nice little article on the matter

NathanOliver 429 Veteran Poster Featured Poster

I like a vector because it is scalable so you don’t need to know what the size is ahead of time. It really is a matter of preference but it also keeps with the OOP side of the code. Setters and getters are used to access the variables of the class. Since the variables should be private the programmer cannot access them directly so you need an in-between. This also allows for greater control of what goes on since you can add code to make sure the value being provided is valid.

NathanOliver 429 Veteran Poster Featured Poster

Something like this

// shoe should be a single object
class Shoe
{
public:
    Shoe() : name(""), shoeSize(0), number(0) {}
    Shoe(string _name, double _size, int _number) : name(_name), shoeSize(_size), number(_number) {}

    // getters
    string getName() const { return name; }
    double getSize() const { return shoeSize; }
    int getNumber() const { reutrn number; }

    //setters
    void setName(string _name) { name = _name; }
    void setSize(double _size) { shoeSize = _size; }
    void setNumber(int _number) { number = _number; }

private:
    string name;
    double shoeSize;
    int number;
};


// now we make a shoe list
class ShoeList
{
public:
    ShoeList()

    bool Load(string filename)  // use bool to signle if operation was succesful
    {
        // read in shoes and add them to the vector
    }
    void Display() const
    {
        for(int i = 0 i < shoes.size; i++)
            cout << shoes[i].display() << endl
    }
private:
    vector<Shoe> shoes
};

This way you have a ShoeList that manages all of the seperate shoes and the Shoe class just takes care of itself. You could also just do this with functions but if you are changing it to OOP then this should be the way you go.

NathanOliver 429 Veteran Poster Featured Poster

I dont think you are implementing this correctly. You are trying to use class functions to take the place of global functiuons you used to have. If you dont change anything then it is not going to work. Take load() for example. If you want to load an array a shoes from a file you should have that as a global function since one shoe should not be responsible for populating an array of other shoes.

NathanOliver 429 Veteran Poster Featured Poster

Can you post the relevent code?

NathanOliver 429 Veteran Poster Featured Poster

If you wont do your homework why should I? If it is do tomorrow then you should have plenty of time to rewrite 100 lines of code.

NathanOliver 429 Veteran Poster Featured Poster

So you want to go from c++ to c? I dont think someone is going to do that for you though. Do you know how to use printf() and scanf()? It shouldn't take you to long to do it.

NathanOliver 429 Veteran Poster Featured Poster

This is already in c++. What do you want to convert it to? There are a couple errors in this. Line 2 and line 70 are wrong.

NathanOliver 429 Veteran Poster Featured Poster

Well in the example Nick posted sort you use the functor(object with function operator ( operator () ) overloaded)

//inside sort
if(isless(first,second)) // first and second would be iterators
    // sort accordingly

You should also read this wiki article.

NathanOliver 429 Veteran Poster Featured Poster

In

return (key < str.key);

key belongs to the object being used and str.key is from the object passed to the function. You could also write it like this if it makes more sense to you:

return (this->key < str.key);
NathanOliver 429 Veteran Poster Featured Poster

main.cpp:6:19: conio.h: No such file or directory
----You dont have conio.h on you computer.
main.cpp: In function int main()': main.cpp:54: error:m' undeclared (first use this function)
----What is m on line 54?
main.cpp:54: error: (Each undeclared identifier is reported only once for each function it appears in.)
main.cpp:55: error: expected ;' before "x" main.cpp:56: error:x' undeclared (first use this function)
----What is x on line 55?
main.cpp:70: error: a function-definition is not allowed here before '{' token
----You are still inside main. you need another closing brace after line 68

Fix these first and see what you get.

NathanOliver 429 Veteran Poster Featured Poster

returnListOfAddresses() should look like this:

for(int t=0; t<(int)addressBook.size(); t++)
{        
    cout<<addressBook[t]->toString();
}
NathanOliver 429 Veteran Poster Featured Poster

Could you get away by just having a stringstream object in your tokenizer class? What other functionality does PushbackReader offer?

NathanOliver 429 Veteran Poster Featured Poster

It is a shame schools are teaching with 20 year old compilers.

NathanOliver 429 Veteran Poster Featured Poster

Take at look at this and see how it can help you out.

NathanOliver 429 Veteran Poster Featured Poster

Okay. So what do you have so far?

NathanOliver 429 Veteran Poster Featured Poster

What does the IRManager class look like? What is the code for the HangUp() function?

NathanOliver 429 Veteran Poster Featured Poster

Is mannager a member of Client or InnoVisitClient?

NathanOliver 429 Veteran Poster Featured Poster

Post the block of code where the manger is used in your main function and post the code where your manger is used in another function and it doesnt work.

NathanOliver 429 Veteran Poster Featured Poster

In your second for loop you are calling join(). join() blocks the current thread and waits for thread you called join on to complete. Im pretty sure this is where you are getting slowed down.

NathanOliver 429 Veteran Poster Featured Poster

I could be mistaken but if you have a quad core processor you should be able to run 4 threads at the same time. With the way you have your code written right now you start all 100 threads and then right after that you call each thread and wait for it to finish before you go to the next thread. If you have a lot of othere processes running in your system then this could effectivly keep everything running on a single core. You might be able to pull the threas using joinable() but that could also lead to problems.

NathanOliver 429 Veteran Poster Featured Poster

can you post the code that works and the code that doesnt?

NathanOliver 429 Veteran Poster Featured Poster

The string type is not a built in type. Strings are objects made from a class. The only native type that can hold a string is a char array. The standard for c++ says that main must look like one of these three options.

int main();

int main(int argc, char **argv);  // these are the same
int main(int argc, char *argv[]); // these are the same
NathanOliver 429 Veteran Poster Featured Poster
int arr[] = {1,2,3,4,5,6,7,8,9};  // array of numbers
list numberList(arr, arr + sizeof(arr) / sizeof(int))  load array into list with constructor
NathanOliver 429 Veteran Poster Featured Poster

What is the type of DESTINATION?

NathanOliver 429 Veteran Poster Featured Poster

What is the hangup? Change line 17 to std::multimap<std::string, PoiDetails> vName; and change line 34 to std::multimap<std::string, PoiDetails>::iterator it;. That should be all you need to do.

NathanOliver 429 Veteran Poster Featured Poster

Since the set holds a vector you need to add a second for loop inside your first for loop. In this second loop you need to print out each element of the vector since the vector does not overload the << operator.

NathanOliver 429 Veteran Poster Featured Poster

Since you have all of you lats and longs mulitiplied by pi/180 do you need that on lines 35 and 36?

NathanOliver 429 Veteran Poster Featured Poster

I had thought to tell him that but the problem states to print the numbers in the order they appear. If his compiler supports c++11 he could use an unordered map and use the value for the key.

NathanOliver 429 Veteran Poster Featured Poster

On line 38 you have

x= pow(cos(lat2)*sin(longz),2.0) + pow((cos(lat1)*sin(lat2))/*<--no exponent*/ - sin(lat1)*cos(lat2)*cos(longz),2.0); 

The second pow function has no exponent.

NathanOliver 429 Veteran Poster Featured Poster

you need to make sure you are in the bounds of the array before you call getOrganism(). You could also add some coe to you getOrganism() function and have it check to see if the posistion asked for is within the array. If it is not then it should return null and it it is then it should return what was at the location.

getOrganism(int x, int y)
{
    if(x < 0 || y < 0)
        return NULL;
    if (x > numberOfRows - 1 || y > numberOfCols - 1)
        return NULL;
    return grid[x][y];
}
NathanOliver 429 Veteran Poster Featured Poster

All mergre sorts I have seen that deal with recusrion use the split in the middle method. Is this a recursive merge sort or are the doing an iterative merge sort?

NathanOliver 429 Veteran Poster Featured Poster

What code do you have?

NathanOliver 429 Veteran Poster Featured Poster

I think if he tries to turn that code in his teacher will know it is not his.

NathanOliver 429 Veteran Poster Featured Poster

What do you have so far? We do not give out the answers to homework problems. You need to show effort before we help.

NathanOliver 429 Veteran Poster Featured Poster

Okay. What do you have so far?

NathanOliver 429 Veteran Poster Featured Poster

This is the line with your first error

cout << "Congrats! Your score is: \n" << getline(cin, x.score) << endl;

Right now you are trying to use getline to display a value which will not work. You are also getting the error about x not being declered here. x should be aPlayer. It should look like this

cout << "Congrats! Your score is: \n" << aPlayer.score << endl;

All of the other refferences to x errors you are getting are the same thing.

You are also taking in score the wrong way. You have score declared as a double but you are using getline() which is for strings. You can get the info from the file with getline if you store it in a string and then you can convert that string to a number to populate score.

NathanOliver 429 Veteran Poster Featured Poster

Well if you use getline() it will read in everything in the file until it reaches a newline. You can read about it here.

NathanOliver 429 Veteran Poster Featured Poster

The way you have your code now if either stream fails it will end the loop. The problem is you arent doing anything after that. I would do this a little differently. Look at how this works.

while(getline(firstFile, line1) && getline(secondFile, line2))
{
    thirdFile<< line1 << endl << line2 << endl;
}
if(firstFile.fail() && !secondFile.fail())  // if first file ended first
{
    while(getline(secondFile, line2))
    {
        thirdFile<< line2 << endl;
    }
}
if(!firstFile.fail() && secondFile.fail()) // if second file ended first
{
    while(getline(firstFile, line1))
    {
        thirdFile<< line1 << endl;
    }
}
NathanOliver 429 Veteran Poster Featured Poster

Line 5 is wrong. you do the initialization of the varibles in the constructor.

NathanOliver 429 Veteran Poster Featured Poster

You need a semi colon after the closing brace on line 25

NathanOliver 429 Veteran Poster Featured Poster

Did you move main outside of the class? If you have post the code you have know.

NathanOliver 429 Veteran Poster Featured Poster

Your main function needs to be outside of your class defenition

NathanOliver 429 Veteran Poster Featured Poster

Why are lines 15-17 inside your constructor? Your close bracket on line 18 should be on line 15.

phorce commented: Just noticed that! +6
NathanOliver 429 Veteran Poster Featured Poster

Well you could make a base class that has a generic function called getList() that would display the list. Then you could derive your differnt kinds of list from that base class. then the foo() function will get passed a pointer to the base class so it can except both sub list. In the foo() function you would then call the getList of the pointed to object

myk45 commented: thanks! +5