NathanOliver 429 Veteran Poster Featured Poster

add this after line 14 to see if your file is being opened.

if(!myfile)
    std::cout << "Unable to open file" << std::endl;
NathanOliver 429 Veteran Poster Featured Poster

Not to pick nit but shouldn't line 35 be delete [] p;, since the first level of p is in itself an array?

deceptikon commented: Thanks! +12
NathanOliver 429 Veteran Poster Featured Poster

Passing by reference or value should be pretty much the same for POD types. In this case your struct only contains POD types so passing the struct by value or passing all of the variables by reference should be the same. If you want to you can pass your struct by reference. It might give you a little bit of a boost.

void Returns(returns & returner)
{
}
NathanOliver 429 Veteran Poster Featured Poster

It is not the same thing

Sales::Sales()
{
    double sales[] = {0.0, 0.0, 0.0, 0.0};
}

The above code creates an double array called sales in the constructor which hides the sales array that is a member of the class. Once the constructor is done this local array that has all zeros is deleted.

Sales::Sales()
{
    for(int i =0 ; i < QUARTERS; i++)
    {
        sales[i]=0.0;
    }
}

This code uses a loop and sets each element of the sales array that is a member of Sales to 0.

NathanOliver 429 Veteran Poster Featured Poster

Are you sure it is opening the file? Put a cout statement between lines 112 and 113 and see if it prints the stament. This will let you now if the file was opened succesfully. It should work if the file is being opened. What does the file look like?

NathanOliver 429 Veteran Poster Featured Poster

This is a C++ program that reads as input a text file.

Where? I didnt see one.

NathanOliver 429 Veteran Poster Featured Poster

Yes. You need to figure out the size that you need o to be and then you use that size to allocate the memory you need with new.

NathanOliver 429 Veteran Poster Featured Poster

On line 4 you declare o as int *o=new int;. This ony gives you a single int pointer. So when you call line 16 you invalidate the pointer because you step out of the memory allocated to it. It looks to me like you need o to be an array. if you know what the size of o should be than make line 4 int *o=new int[size];, where size is the size of the array you need o to be. You are also incrementing c on line 17 but you never set c before you do that. You always want to set the value of a variable before you start using it.

NathanOliver 429 Veteran Poster Featured Poster

So what do you have so far?

NathanOliver 429 Veteran Poster Featured Poster

stoi() is overloaded to take a string or a wstring.

NathanOliver 429 Veteran Poster Featured Poster

What are the error messages you are getting?

Moschops commented: Needs saying so often. Well done. +8
NathanOliver 429 Veteran Poster Featured Poster

Where is the text file? If it is not the same location where you .cpp file is then you need to put the exact path to where the file is.

NathanOliver 429 Veteran Poster Featured Poster

Use this as an example:
base class

//base.h
#ifndef BASE_H
#define BASE_H

class Base
{
    int foo;

public:
    Base(int number) : foo(number) {}
};

#endif

derived class

//derived.h
#ifndef DERIVED_H  //<- inclusion gaurding
#define DERIVED_H

#include "base.h"  //<- this adds the code from base.h to derived.h

class Derived : public Base
{
    int foobar;
public:
    Derived(int num1, int num2) : Base(num1), foobar(num2) {}
};

#endif

This is how your headers would look. Then in the .cpp files you would just need to include the .h that the .cpp file is named after.

base class .cpp file

//base.cpp
#include "base.h"

// all the code for the base class would go here

derived class .cpp file

//derived.cpp
#include "derived.cpp"

// all the code for the derived class would go here.
NathanOliver 429 Veteran Poster Featured Poster

line 76 should be

b = abcd[1];

not

abcd[1]=b

Also the use of goto is a big no no for c++. With the loop options availible you should never need to use one. You also need to learn how to indent properly.

aVar++ commented: Indentation is very important. +2
NathanOliver 429 Veteran Poster Featured Poster

I would go the polymorphism route. That way if you need to add another standard latter on all you have to do is create a new derived class and add the option for the new standard.

NathanOliver 429 Veteran Poster Featured Poster

If you are mixing the >> operator and getline you need to use ignore() before calling getline. Give this a try

cin.ignore();  <-- added this
cout << "Enter the company name: ";
getline(cin, company_name);
NathanOliver 429 Veteran Poster Featured Poster

Line 24 needs to be nodeType* head_ptr;. That should fix some of the errors.

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

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

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

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 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

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

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

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

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

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;
        }
    }
}
NathanOliver 429 Veteran Poster Featured Poster

correct me if I am wrong and since I dont have my compiler in front of me I might be. If you have c = a * b, then can't you just do a check after the mulitplication for c / a == b? If c overflows it should break. The only case I can see in my head is if either a or b equals the maximum for the data type.

NathanOliver 429 Veteran Poster Featured Poster

@ luicaci Andrew to make your isPrime function a little faster you can do this

bool isPrime(int nr)
{    
    if (nr == 0 || nr == 1) 
        return false;
    if (nr % 2 == 0 && nr != 2) // check to see if its even
        return false
    for (int i=3; i * i <= nr; i += 2) // no need to check even numbers here
        if (nr % i == 0 ) return false;    
    return true;
}
Lucaci Andrew commented: That too. And also... it's Lucaci?!?!... :) +6
NathanOliver 429 Veteran Poster Featured Poster

The reason I use VMWare Player is that we use VMWare at work so I am more comfortable. When I said that I RDP into the virtual machine that means I do a remote desktop into the machine so it like I am just remotely accessing the machine instead of being in the player. I'm not sure what kind of challenges you have been facing but I haven’t had any issues starting a new virtual machine from an iso file to create the OS. I do have an i5 processor with 16GB of ram in my machine so I can run my main OS plus 2 virtual machines at the same time and have a pretty seamless experience.

With VMWare player all I do is tell the software what specs for the virtual machine I want and then the location of the iso file that has the OS installation on it. I tell it to create at and the player opens up a screen to the new machine. It will read from the iso file and install it just like if you put the disk into a brand new machine. After the OS installs it is good to go.

NathanOliver 429 Veteran Poster Featured Poster

Give this link a try to see what a string can do.

The string object even gives you a function enabling you to pretend it is just an array of char, in case you're stuck with a function that wants an array of char instead of a proper string object.

Imagine you have this function

int CountVowles(const char *)

Now since this function wants a const char * you cant just pass a string to it. Bummer hun. Well you are in luck. The string class has a member function called c_str() and it will return a const char * to the array that is inside the string object. Now all you have to do in your code to use the function with a string object is

//inside main
string sentence;  // string to hold a sentence
// put a sentence in the string sentence
int numberOfVowles = CountVowles(sentence.c_str());
//...

And now you can still use a function that wants a char array without having to use a char array in your program. As a note this will only work for functions that take a const char *. If the function wants a char * you will either have to copy the string into a char array or you could look for a different function. Chances are you if you have a function that takes a char * that does a standard thing like sort you can probably find what you need …

nitin1 commented: nice!! +2
NathanOliver 429 Veteran Poster Featured Poster

Are you trying to run the exe file and getting this error? You might need to have the dll in the folder the exe file is in.

NathanOliver 429 Veteran Poster Featured Poster

Hate to but in but to answer your question Suzie999 your first post neglected the fact that mapReader is a stream object and he is trying to put information from the stream into an uninitialized pointer array. Your second post wouldn’t work either since he is trying to read in an array of strings. Your suggestion is to put the file into one string which could cause problems and is not what the OP is trying to accomplish. I wouldn’t say that your advice was wrong but IMHO it wasn’t correct.

NathanOliver 429 Veteran Poster Featured Poster

Suzie if you have windows 7 go into the folder that holds the files for your project. Right click on a blank space and go to properties. in the properties page go to the previous version tab. It should have a list of different versions if you have volume shadow copy turned on.

NathanOliver 429 Veteran Poster Featured Poster

As far as i know there isnt a backup of the file. You might be able to get away with restoring the file windows if you have Shadow copy turned on? What OS are you using?

NathanOliver 429 Veteran Poster Featured Poster

To display it should look like this

std::map<std::string, double> milesto;

// load milesto

for(std::map<std::string, double>::iterator itr = milesto.begin(); itr != milesto.end(); ++itr)
{
    std::cout << itr->first << "\t" << itr->second << std::endl;
}

Also notice how I used ++itr instead of itr++. Using the preincrement operator will make the code slightly more efficent since it is not a built in type. Not a big deal but it is something to consider.

NathanOliver 429 Veteran Poster Featured Poster

line 9 should be

 std::cout << "You entered" << date;

You only need to call cout once.

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

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

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

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

Your main function needs to be outside of your class defenition