NathanOliver 429 Veteran Poster Featured Poster

Is line 16 printing nothing to the screen?

NathanOliver 429 Veteran Poster Featured Poster

if each number has a space after it you can just use the >> operator of the ifstream object your using inside of a loop.

NathanOliver 429 Veteran Poster Featured Poster

It has an error because AD didnt give you the complete code. He left part of it for you to complete. You do not need to include the string library you just need to implement the loop that AD did not put in.

NathanOliver 429 Veteran Poster Featured Poster

Can you post the code that is giving you the problem? It is hard to read your screen from here.

NathanOliver 429 Veteran Poster Featured Poster

The problem you are having is that on line 31 you set nodePtr to its next link which is null and then on line 33 instead of putting nodePtr = newNode you make next equal to newNode which breaks the link. I dont have a compiler on my machine but you can give this a shot and see if it will work for you or you can just fix the code you have.

template <class T>
TList<T>::TList(const TList<T>& old)
{
    ListNode<T> *newNode;
    ListNode<T> *oldNode;

    oldNode = old.head;

    if (oldNode)
    {
        //create a new head for the copy
        head = new ListNode<T>(oldNode->value);
        newNode = head;

        // loop through the list and copy into the new list
        while((oldNode = oldNode->next))
        {
            newNode->next = new ListNode<T>(oldNode->value);
            newNode = newNode->next;
        }
    }
}
NathanOliver 429 Veteran Poster Featured Poster

check out fstream

NathanOliver 429 Veteran Poster Featured Poster

If you are dealing with anything in your class that is not POD then you should create your own copy constructor and assignment operator. The default the compiler creates does a shallow copy and that is not what you want. You can consider stl types as POD since they take care of themselves.

NathanOliver 429 Veteran Poster Featured Poster

Are you saying that running this code will produce different outputs occasionally?

NathanOliver 429 Veteran Poster Featured Poster

I wouldnt install a compiler that is over 15 years old on my machine. That is why we are being critical about your code. We should be able to compile it on any compiler that is at least complient with c++98.

NathanOliver 429 Veteran Poster Featured Poster

The .h file will hold the definition of you class. The .cpp file holds the declaration of your class. According to the standard the function main has two valid signatures. int main() and int main(int argc, char * argv[])

NathanOliver 429 Veteran Poster Featured Poster

They really need to ban those compilers. I mean there is no <conio> header. Everything in the standard headers are in the std namespace which I dont see you using. main() returns and int and you dont even have the return type specified. global variables are a big no no. There is no reason in your code that the variables couldnt be defined inside main.

NathanOliver 429 Veteran Poster Featured Poster

What compiler are you using? All of you includes are depreciated. It is <iostream> not <iostream.h>. Also you are inlcuding a cpp file. You never want to do that. Your student class should be defined in two files. xxxx.h and xxxx.cpp. The .h file is what you should be including in any .cpp file that needs students. the .cpp file should then be added to the project that you are using it in. void main is not standard, main only returns an int.

NathanOliver 429 Veteran Poster Featured Poster

If you want to use sizeof in your for loop you need to do it like

for(int i = 0; i < sizeof(ia) / sizeof(ia[0]); i++)
NathanOliver 429 Veteran Poster Featured Poster

Do you have copy constructors built? I am not seeing any. Since your cd class has a list in it and it gets copied into the list in you main program you could be having the issue there. If the list inside the class are copied by value then when things go out of scope you will have pointers pointing to nothing. Also what are title and length on line 18-19? If they are members of the media class you constructor should look like this:

CD::CD() : Media("",""), Artist("") {}
NathanOliver 429 Veteran Poster Featured Poster

You either need to use a large number library to handle very large numbers or if you can get away with numbers less than 18,446,744,073,709,551,615 then you can use an unsigned long long

NathanOliver 429 Veteran Poster Featured Poster

He just want to know how to send a 5V signal?

NathanOliver 429 Veteran Poster Featured Poster

Can you post the code for the CD class? It could be that the copying of the cd into the list is where you are getting the error.

NathanOliver 429 Veteran Poster Featured Poster

trun UAC off then try to install

NathanOliver 429 Veteran Poster Featured Poster

Thanks deceptikon. Brilliant example.

NathanOliver 429 Veteran Poster Featured Poster

I Didn't know they had strtol(). I can still see cases where you have to validate the string though. If someone enters 'a' and you convert it to base 10 strtol() will return 0 since the conversion failed but you dont know if the conversion failed or if the user entered 0.

NathanOliver 429 Veteran Poster Featured Poster

Do you have a contructor for ListNode? if you do does it set the next pointer to NULL?

NathanOliver 429 Veteran Poster Featured Poster

Well if you cant use a stringstream you could always stor the line in a string and then manually parse the string yourself. The atoi() function will convert a char* into the int that it represents. To get the char* you can use substr() to get the number you want and then use c_str() on the sub string to get the char*.

ankit.4aug commented: thanks a lot +1
NathanOliver 429 Veteran Poster Featured Poster

You need to make the functions public not protected to use them.

NathanOliver 429 Veteran Poster Featured Poster

Thanks deceptikon. I cant believe I used a keyword for a varibale name. Shame on me :(

NathanOliver 429 Veteran Poster Featured Poster

So what do you have so far?

NathanOliver 429 Veteran Poster Featured Poster

you need a ; at the end of line 9. Also change continue ! = 0 on line 42 to continue != 0. As far as an algorithim for the fib series there are plenty of threads on this site that you can read to see how you would do it.

NathanOliver 429 Veteran Poster Featured Poster

So what do you have so far?

NathanOliver 429 Veteran Poster Featured Poster

You would want to wrap lines 10-33 in a do-while loop.

int continue = 0;
do
{
    //lines 10-33
    cout << "Do you want to go agian? << endl
    cout << "Enter 1 for yes 0 for no: ";
    cin >> continue;
} while (continue != 0) // doing this to allow all non 0 numbers to continue

This should get you started. You probably want to have some input verification so that you can have a more specific while condition.

NathanOliver 429 Veteran Poster Featured Poster

What do you have so far? This smells like homework and we do not Just give you the amswer for homework. We will help you if you have a problem but that is it.

NathanOliver 429 Veteran Poster Featured Poster

Do you have to use 3 parallel arrays or can you use a class/struct? If you have to use the parallel array then you need to sort all of them at the same time. It would look something like this

string firstNames[];
string lastNames[];
string birthDates[];
// load the array with data

// sorting loop
for(int i = 0; i < sizeOfArrays; i++)
{
    string temp;
    for(int j = i + 1; j < sizeOfArrays; j++)
    {
        if (firstNames[i] > firstNames[j])
        {
            temp = firstNames[i];
            firstNames[i] = firstNames[j];
            firstNames[j] = temp;

            temp = lastNames[i];
            lastNames[i] = lastNames[j];
            lastNames[j] = temp;

            temp = birthDates[i];
            birthDates[i] = birthDates[j];
            birthDates[j] = temp;
        }
    }
}
NathanOliver 429 Veteran Poster Featured Poster

Well if << is supposed to print oput the next record untill the end then restart then you can have a member variable in you class that keeps track of what record was printed last. Then in your << operator print the next record and increment the tracking variable. You will also need to check and see if you are at the end of the list and if you are then restart the tracking variable to 0. You will want to do this inside your << operator function.

NathanOliver 429 Veteran Poster Featured Poster

you are calling the print function on line 56 but you never defined it.

NathanOliver 429 Veteran Poster Featured Poster

Here is a simple program for you.

#include <iostream>

using std::cin;
using std::cout;

int main()
{
    cout << "Hello World!";
    cin.get();
    return 0;
}
NathanOliver 429 Veteran Poster Featured Poster

You either need to forward declare you min function or just move it to be above the class. C++ uses a single pass compiler unlike java that uses a dual pass.

NathanOliver 429 Veteran Poster Featured Poster

Yes and no. It really depends on what you are trying to accomplish. If you look at the STL string it has both.

Moschops commented: string is an excellent example to use; default constructor is an empty string ready to be used, or you can construct it with letters already in it. Both obviously useful in so many situations. +8
NathanOliver 429 Veteran Poster Featured Poster

cases 1, 2, 3, 4 and 5 need a break at the end of them before the start of the next case.

NathanOliver 429 Veteran Poster Featured Poster

No, and that is with a capital "N". Now if you want to contract someone to do it there is a section to do that.

NathanOliver 429 Veteran Poster Featured Poster

line 34 should be

int * people = new int[people];

see if that makes a difference. Also on line 51 put

delete [] people;
NathanOliver 429 Veteran Poster Featured Poster

What are x and y on line 2? You are not paaing them into the function and the are not private members.

NathanOliver 429 Veteran Poster Featured Poster

One takes a pointer and the other takes a reference. If you have a question you should start a new thread.

NathanOliver 429 Veteran Poster Featured Poster

Take the input in as a string.

#include <string> // to use the string class
#include <iostream>

using namespace std;

int main()
{
    string input;
    cout << "Enter number: ";
    getline(cin, input);
    cout << "You entered: " << input << endl;
    cin.get();  // pause program
    return 0;
}
NathanOliver 429 Veteran Poster Featured Poster

Mike thanks for the clarification. I thought that the set maintained the order that the elements were inserted in. I guess I need to read a further and not make assumptions. Sorry for the bad advice.

NathanOliver 429 Veteran Poster Featured Poster

Line 128 of your original code should be

if (*(people[j]) == *(people[k]))

Otherwise im not sure what the error is.

NathanOliver 429 Veteran Poster Featured Poster

Post the code that you have that is giving you the error.

NathanOliver 429 Veteran Poster Featured Poster

the words will be stored in the order they are added to the unordered set unlike a set where they are put in order of thier key value.

NathanOliver 429 Veteran Poster Featured Poster

Lets say you need to read in a text file and display a list of all of the unique words in the the file in the order they appeared. Using an unordered set you would be able to do that by reading in each word from the file and inserting it into the set. then all you have to do is print out the set from first to last.

nitin1 commented: nicely answered!! +2
NathanOliver 429 Veteran Poster Featured Poster

Check this out

NathanOliver 429 Veteran Poster Featured Poster

Well I cant tell anything from this. What line is causing the problem? I am not seeing a call to delete [] anywhere in this function for RO or IO.

NathanOliver 429 Veteran Poster Featured Poster

You can't have 2 main functions in one program. You either need to make 2 seperate programs or add the addition function to the first main function and get rid of the second one.

NathanOliver 429 Veteran Poster Featured Poster

This is how I would format your code.

void b_Physics::Collision(const s_Polygon& Obstruct)
{
    float Ntime = 0.0f;

    s_Polygon Polygon = this->Object.Polygon;

    switch(this->Object.Motion.HorizDir)
    {
        case s_Motion::LEFT: 
            Polygon.MinX = Polygon.MinX + this->Object.Motion.Xvel; 
            break;
        case s_Motion::RIGHT: 
            Polygon.MaxX = Polygon.MaxX + this->Object.Motion.Xvel; 
            break;
        default : break;
    }

    if(this->Object.Polygon.MinY < Obstruct.MaxY && this->Object.Polygon.MaxY > Obstruct.MinY)
    {
        if(this->Object.Motion.HorizDir == s_Motion::LEFT && Polygon.MinX < Obstruct.MaxX)
        {
            Ntime = this->Object.Polygon.MinX - Obstruct.MaxX / this->Object.Motion.Xvel;
            this->Object.Motion.Xvel = Obstruct.MaxX - this->Object.Polygon.MinX / Ntime;

        }
        else if(this->Object.Motion.HorizDir == s_Motion::RIGHT && Polygon.MaxX > Obstruct.MinX)
        {
            Ntime = Obstruct.MinX - this->Object.Polygon.MaxX / this->Object.Motion.Xvel;
            this->Object.Motion.Xvel = Obstruct.MinX - this->Object.Polygon.MaxX / Ntime;
        }
    }

    switch(this->Object.Motion.VerticDir)
    {
        case s_Motion::UP:
            Polygon.MinY = Polygon.MinY + this->Object.Motion.Yvel; 
            break;
        case s_Motion::DOWN: 
            Polygon.MaxY = Polygon.MaxY + this->Object.Motion.Yvel; 
            break;
        default : break;
    }

    if(this->Object.Polygon.MinX < Obstruct.MaxX && this->Object.Polygon.MaxX > Obstruct.MinX)
    {
        if(this->Object.Motion.VerticDir == s_Motion::UP && Polygon.MinY < Obstruct.MaxY)
        {
            Ntime = this->Object.Polygon.MinY - Obstruct.MaxY / this->Object.Motion.Yvel;
            this->Object.Motion.Yvel = Obstruct.MaxY - this->Object.Polygon.MinY / Ntime;

        }
        else if(this->Object.Motion.VerticDir == s_Motion::DOWN && Polygon.MaxY > Obstruct.MinY)
        {
            Ntime = Obstruct.MinY - this->Object.Polygon.MaxY / this->Object.Motion.Yvel;
            this->Object.Motion.Yvel = Obstruct.MaxY - this->Object.Polygon.MinY / Ntime;
        }
    }
}