NathanOliver 429 Veteran Poster Featured Poster

you need another char array and after strcat( sn, ".txt") you would do strcat( filenameWithFolder, sn)

NathanOliver 429 Veteran Poster Featured Poster

You will want to use an array and a while loop to take in the input. to get the sum you would go through the array with a for loop and add all of the values.

NathanOliver 429 Veteran Poster Featured Poster

Look up the modulus operator. Using that will help you out.

NathanOliver 429 Veteran Poster Featured Poster

What do you have so far?

NathanOliver 429 Veteran Poster Featured Poster

Here is some pseduo code that might help

int counter = 0
original[] // array you get from user
nodup[] // array without duplicates.
char ch
nodup[0] = original[0]
loop i = 0 until size of original - 1
{
    ch = original[i]
    loop j = i + 1 until size of original - 1
    {
        if ch != original[j]
            nodup[++counter] = original[j]
    }
}
NathanOliver 429 Veteran Poster Featured Poster

You probolly can get away with changing line 24 to

&b = pb;
NathanOliver 429 Veteran Poster Featured Poster

line 22 tels the compiler to initialize an empty array. Line 28 does not make any sense to me. If you want to increase the element that you find you would use the post increment operator not the pre increment operator.

NathanOliver 429 Veteran Poster Featured Poster

@ rajat.sethi93 Void main is not standard. Please indent your code. You might want to get a compiler from this decade or at least something that is c++98 standard compliant. There are a number of free compilers/IDE's available. MSVC 2010 express and Code::blocks are a couple to check out.

NathanOliver 429 Veteran Poster Featured Poster

Line 17 needs to be inside your if statement in your for loop. The way you have it now it will only add the last factor that you find.

NathanOliver 429 Veteran Poster Featured Poster

If you want it to keep going then you would need to put lines 7 through 35 inside a loop.

NathanOliver 429 Veteran Poster Featured Poster

We wouldnt know where to start. Did you try printing out the values before you divide to see where you are dividing by 0 like WlatP suggested? Learning how to debug your code is an important part of becoming a programer.

NathanOliver 429 Veteran Poster Featured Poster

Well if you struct is called Student_info then you would use

typedef std::vector<Student_info> container_Student_info;

The syntax for this is

typedef std::vector<type_of_object_you_want_for_the_vector> name
NathanOliver 429 Veteran Poster Featured Poster

I have not seen a for loop used like for readin a file before. When I read from a file I use a while loop. Try doing something like this and see if it helps.

#include <string>
#include <fstream>
#include <iostream>

using namespace std;

int main()
{
    string input;
    ifstream fin("myfile.txt");
    int count = 0;

    while (getline(fin, input))  // use getline to control the loop.  once the read
    {                            // fails it will end the loop.
        cout << line << endl;
        count++;
        if (count % 24 == 0)
            cin.get();  // used to pause
    }

    cin.get();
    return 0;
}
NathanOliver 429 Veteran Poster Featured Poster

Well you never initialize k before you use it as your array subscript. you never want to use a variable before you initialize it. void main() is NOT standard. You have two mains in your program. You should use loops instead of goto statements. Your indentation could be cleaned up but thats more of a style thing. You might want to pick better variable names. I could go on but I'll leve it here for now.

NathanOliver 429 Veteran Poster Featured Poster

What you have right now is a sigle letter. If you want to use a c-style string you need to define wrd like char wrd[80] where 80 is the number of charactures max that it can hold. You can change 80 to be what every you want but you want to make sure it is large enough to fit what you want to put into it. you also want to make sure you have enough room at the end for the null terminator that gets automaiticly instered to the end of the input.

int main()
{
    char word[80];  // this will hold 79 letters
    cout << "Please enter a word: ";
    cin >> word;
}
NathanOliver 429 Veteran Poster Featured Poster

What happenes if you use an array instead of a vector?

Jsplinter commented: A simple, but good suggestion. Thank you! +0
NathanOliver 429 Veteran Poster Featured Poster
NathanOliver 429 Veteran Poster Featured Poster

If you want an unsigned 64 bit integer you can use unsigned long long foo;. Check this out to see the data types and their ranges. http://msdn.microsoft.com/en-us/library/s3f49ktz%28v=vs.80%29.aspx

NathanOliver 429 Veteran Poster Featured Poster

You can do that but I would ask why you want to do that. ZWhat are you trying to accomplish with this? A char is basically a 1 byte unsigned integer so if you use 'a' than it gets interperted to 97.

NathanOliver 429 Veteran Poster Featured Poster

If you are only setting the valuse of the array to one or zero based on if they are higher or lower than the average than you can just do that. You dont to use an array of all ones or zeros to do that.

NathanOliver 429 Veteran Poster Featured Poster

The pbroblem is that you are passing the arrays to the function wrong. If you want to pass the arrays it will look like this

cout << distance(x, y) << endl;

Since your function is set up to take an array you just pass the entier array by using the name. what you are doinW is passing the value one past the end of the array

NathanOliver 429 Veteran Poster Featured Poster

You might want to check and see if you are even opening the file. to do that you can use this

if(in.fail())
    cout << "The file could not be open;"

I would put that right after line 6 to make sure the file is open before you try to read from it.

NathanOliver 429 Veteran Poster Featured Poster

That’s not really true. A reference is basically a pointer that the complier takes care of dereferencing for you. References also have limitations as that once they are referenced to and object they will always point to that object. Pointers can be change to point at different things at any time. When I code the only time I deal with actual pointers is when I am dealing with arrays. Otherwise I use references for function parameters if i need to be able to modify the variable. If I don’t need to modify the variable and it is a POD (plain old data) type then I will pass by value. If I am dealing with a non-POD type and I don’t need to modify the variable I will pass it by constant reference.

NathanOliver 429 Veteran Poster Featured Poster

I leave that part up to you. You can use the code I provided and change it to do what you want and if you still are having problems then post what you have and ill try to help you out.

NathanOliver 429 Veteran Poster Featured Poster

Something like thisd might help you out

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main()
{
    fstream fin("textfile.txt");
    string userInput, fileLine, response,temp;
    cout << ": ";
    getline(cin, userInput);
    // read lines from file
    while (getline(fin, fileLine))
    {
        //if you find and i
        if(fileLine[0] == 'i')
        {
            // then search for a line begining with r
            while (getline(fin, fileLine))
            {
                if(fileLine[0] == 'r')
                {
                    response = fileLine;
                    break;
                }
            }
            // no guaranty there is a response
            if (!response.empty())
            {
                cout << response;
                break;
            }
            else
            {
                cout << "no match";
                break;
            }
        }
    }
    cin.get();
    return 0;
}

BTW anyone know how to format code in the correctly now? The code button doesnt highlight anything and I havent figured it out yet. The help on formatting the code doesnt help either.

NathanOliver 429 Veteran Poster Featured Poster

Could you post your alien class?

NathanOliver 429 Veteran Poster Featured Poster

The previous line from where? The previous line that matched from the file? Where are you getting the first letter from? Are you getting it from the user input or from the line you got from the file? Please elaborate a little more with what needs to be done.

NathanOliver 429 Veteran Poster Featured Poster

a char* is considered a c-style string. It is just an array of characters. A char ** is and array of char* which is to say it is an group of c-style strings. The string type is an ogject created from the class string. These are two different things. This is a good page for learning about char arrays http://www.cplusplus.com/doc/tutorial/ntcs/
this is a goo page to learn about the string class http://www.cplusplus.com/reference/string/string/

NathanOliver 429 Veteran Poster Featured Poster

Just make the void RepMatrix funtion a provate function of the class. That way no one can use except you.

NathanOliver 429 Veteran Poster Featured Poster

according to http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751%28v=vs.85%29.aspx the HANDLE type is a void *. If that is the case than in your copy constructor you should creat a new HANDLE and than asign the value of the copy from HANDLE to the copy to HANDLE. I cant be certian as I havent done any windows api programing though.

NathanOliver 429 Veteran Poster Featured Poster

You want to write your own copy constructor for any class that contains pointers. The reason for this is that the default one the compiler makes only performs a shallow copy. This means that the copy will be exactly the same as the original. With pointers this is bad because if the copy gets destroyed which happens a lot with copies the pointer gets deleted. Once this happens the pointer in your original class can no longer be used safely and you might even get an exception when you delete the original class since you would call delete on the pointer again. IMHO I write my own copy constructor unless the class I am writing contains only POD types or classes that take care of themselves like vectors or strings.

NathanOliver 429 Veteran Poster Featured Poster

The problem you are having is that you are using an unsigned integer type. When you underflow that type it wraps around to the largest number it can be. You have to be very careful when you get towards the min or max number that your type can hold because sometimes this will happen. One nice feature of this is that if you want the largest number that an unsigned type can hold you can always subtract one from 0 and you will get the max.

Unsigned int: 0 - 1 = 4294967295

Unsigned int: 4294967295 + 1 = 0

NathanOliver 429 Veteran Poster Featured Poster

You are calling delete on number in your destructor for your palindorme class. You shouldnt do that. All members of the base class should be taken care of in the base class destructor like you have on line 13.

grh1107 commented: Thanks so much! I didnt know the base class took care of it i figured it would get a memory leak +0
NathanOliver 429 Veteran Poster Featured Poster

if you are having a problem with file IO give this page a shot. http://www.cplusplus.com/reference/iostream/ifstream/

NathanOliver 429 Veteran Poster Featured Poster

It all depends on how you code your program. If you have mechanisms in place in your code to handle error than you could try recover from that error. If that is not possible, than you could end the program gracefully and tell the OS that the program did not end successfully. Look up Try … Catch blocks to see what I mean about error handling. One example I can think of for this is an installation program. The program that is installing the software is chugging along when it runs into a problem that it can’t recover from. Wouldn’t it be nice if the installer could tell the OS that hey I could do what I was supposed to do so your new software isn’t going to work? Well that is exactly what you can do with a return statement. In the part of the code that is handling the error can’t fix it than it can return EXIT_FAILURE to the OS so that it know something is wrong. Now the OS know that the software won’t work and will give you options accordingly.

NathanOliver 429 Veteran Poster Featured Poster

I know you already have a lot of code invested in this but it might be worth it to change what you are using for your arrays. I would suggest using a vector. You dont ned to worry about any memory managment or sizing issues. Why rewrite it if you dont have to.

NathanOliver 429 Veteran Poster Featured Poster

What error are you getting? To try and make finding the problem easier you should try to skim the code down to the smallest thing you can get that still produces the error. Try to fix that and then implement the fix into the larger code that you have. Seeing 800 lines of code with virtually no comments and no mention of what the error is wont get you very far.

NathanOliver 429 Veteran Poster Featured Poster

Do you know how to use arrays?

NathanOliver 429 Veteran Poster Featured Poster

Well if you want to parse a string the best way i can think of is to you a stringstream. You get the input from the user using getline like you have and then you would put the string into the stringstream. After that you would output all of the differnt parts into som sort of contianer. After that you just go through the continaer and handle accordinginly. Here is a little sample of how to do that.

// to break a up string
#include <vector> // for vector
#include <sstream> // for stringstream
#include <iostream>
#include <string>

int main()
{
    std::stringstring ss;
    std::string input, temp;
    std::vector<string> comand;
    std::cout << ">: ";
    std::getline(cin, input);
    ss << input;
    // brak up line and put each part into the vector
    while( ss >> temp)
    {
        comand.push_back(temp);
    }
    // display vector
    for(size_t i = 0; i < comand.size(); i++)
        std::cout << comand[i] << std::endl;
    std::cin.get(); // pause program
    return 0;
}
NathanOliver 429 Veteran Poster Featured Poster

Do you know how to use cin and cout? Have you heard of get() and/or getline()? Using those you can take anything in from the user you want in almost any way you want it. Generally what you should do is read in the entire line and then parse out the line into the comands and data that was provieded. Than you can go through the seperated data to find out what you should do.

NathanOliver 429 Veteran Poster Featured Poster

Since you are dealing with the string class what happenes if you change it from 1 and 0 to '1' and '0'

s += '1'
s += '0'
NathanOliver 429 Veteran Poster Featured Poster

Ever think about just including the cctype header in your project? If you dont want to do that then what you have looks good as long as CCTYPE is defined in the cctype header file. If you want to check if something is not defined then you would use #IFNDEF something

NathanOliver 429 Veteran Poster Featured Poster

You do not need a while loop in your function. Think about the steps you need to do to get a factorial. There should be a conditional statment in a secursive function to check if you have reached a base case. There should be a call to the function itself if you have not reached a base case. Generally you do not use a loop in a recursive function.

NathanOliver 429 Veteran Poster Featured Poster

Thanks firstPerson I forgot about the special casses.

NathanOliver 429 Veteran Poster Featured Poster

Yes you can Overide any operator you want. This can be done globally or at a specific level.

NathanOliver 429 Veteran Poster Featured Poster

After line 16 add cin.ignore(); . This is beacuse you are mixing inputs and this will clear the '/n' that is left in the buffer after the call to cin with >> . Not 100% sure how gets() works but this fixes the problem when trying to use getline()

NathanOliver 429 Veteran Poster Featured Poster

to declare variables in c++ you do it as

int x, y;

So with that to declare a structure with an x and y variable you would do

struct Point
{
    int x, y;
}

Finally if you want to constuct you struct with values when you make it you need to add a constuctor

struct Point
{
    int x, y;
    Point(int x_, int y_) : x(x_), y(y_) {}
}

int main()
{
    int x = 5, y = 6;
    Point point(x, y);
}
triumphost commented: EXACTLY WHAT I WANTED!!!!! +6
NathanOliver 429 Veteran Poster Featured Poster

I'm not sure what you are trying to do between lines 70-81. if you want to find the difference between the 2 times you do return total_min1 - total_min2; . If you want to get to the absolute difference between the two times than you can use the abs function provided in <cstdlib> like this.

return abs(total_mins1 - total_mins2);

Or you could do this.

return total_mins1 - total_mins2 > 0 ? total_mins1 - total_mins2 : -1 * total_mins1 - total_mins2;

// or to make it easier to read

int total_difference = total_mins1 - total_mins2;
return total_difference > 0 ? total_difference : -1 * total_difference;
NathanOliver 429 Veteran Poster Featured Poster

Line 31 should be b = int(a);

NathanOliver 429 Veteran Poster Featured Poster

You never put the function in the public part of your class so the entire function is private and can not be used by anything other than other member functions. So when you try to use it in your list class it will cause an error because the list is not part of the class.