NathanOliver 429 Veteran Poster Featured Poster

You are mixing input with getline() and cin. iIf you are going to do that then you need to flush the input stream after the call to getline() and before you call cin >>.

NathanOliver 429 Veteran Poster Featured Poster

Is the error reffering to line 85 in shoes.cpp? I am not seeing anything wrong with the code.

NathanOliver 429 Veteran Poster Featured Poster

trantran I just wanted to let you know that I use xrdp in linux in order to RDP into the machine. As for the problems you are experiancing I would have to try it on my own machine later but i can say i have never had a problem with this.

I also wanted to let you know that if you think that something that is open source and changing daily is a stable platform then you might need to rethink what you are using. Look at all of the SP's and patches microsft has to come up with and they are a multi billion dollar company. I have a server here at work that is linux and we are running VMWare on it for our virtual infrastructure. We last shut downt that server in october 2010. I would say that having an entier company running for 2+ year of solid uptime is pretty stable.

NathanOliver 429 Veteran Poster Featured Poster

@ vmanes Shouldnt line 10 of your snippet be

dest[index] = '\0';  // null terminate the destination string
NathanOliver 429 Veteran Poster Featured Poster

This

const Vector& operator=(const Vector &rhs);

Should be

const Vector<T>& operator=(const Vector<T> &rhs);

And then in you implementation this

Vector<T>:: const operator=(const Vector &rhs)

should be

const Vector<T>&::operator=(const Vector<T> &rhs)
NathanOliver 429 Veteran Poster Featured Poster

You can use malloc on an array that is in the stack.

NathanOliver 429 Veteran Poster Featured Poster

You have not overloaded the = operator. You need to do that as well when working with pointers. you should implement it like your copy constructor. What compiler/IDE are you using? I ask because the headers you have are not correct. Also have you thought about using the string class instead of char arrays?

NathanOliver 429 Veteran Poster Featured Poster

No I am sorry I cannot. This code is simply atrocious. First it needs to be formatted correctly. Second it uses compiler extensions that no longer exist. You might be better off recreating this from scratch in dev c++.

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

Actually i belive a teacher could give this out. Look at all of the people on here that ask for help that are using turbo c++ in their class. That compiler came out before c++98 was created. Its sad when they use 15+ year old code to teach with.

NathanOliver 429 Veteran Poster Featured Poster

So what have you done? If this is the code the teacher gave have you modified it at all? Also please repost it so it is not all on 2 lines. I am not sure if anyone is going to be willing to help you without properly formated code.

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

1) It is just the way I like to do it. It really doesnt make a difference. I have dual monitors so it makes the second monitor look more like it is its own computer. Like I said it's just my preference.

2) My host OS is windows 7 pro 64bit.

3) I have not used another OS for the host machine.

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

I am running Windows 7 and if I need another OS I use VMWare player to run the different OS. Once it is running I normally RDP into it for a cleaner look and feel

NathanOliver 429 Veteran Poster Featured Poster

So before you even find out if this is homework or not you just decide to do the assignment for them? What is that going to teach them?

As a question on your code why are you using system("pause")? Wouldnt cin.get() work just as well and be portable and safe?

NathanOliver 429 Veteran Poster Featured Poster

One word: WOW

NathanOliver 429 Veteran Poster Featured Poster

For this assignment your are to write a program, using strings (from the string class) that plays the popular game of Hangman.

Well you might want to switch over all of your char arrays to string like the instructions tell you to use. Might make the rest of the code a little easier.

NathanOliver 429 Veteran Poster Featured Poster

Okay. What do you have so far? Do you know how to use for loops? Do you know how to use a char vareiable?

NathanOliver 429 Veteran Poster Featured Poster

If you want to know the length of the string use the size() member function.

NathanOliver 429 Veteran Poster Featured Poster

To answer your second question a string is an oject it is not a pointer. it just happened to have a size of 4 when you checked.

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

Well give a round of applause to Microsoft for that. It has only been standard since 1998. I guess they havent found the time yet.

NathanOliver 429 Veteran Poster Featured Poster

Microsoft didnt warn about void main()?

NathanOliver 429 Veteran Poster Featured Poster

What seams to be the problem? if you need to know how to calculate the area of a trapezoid look at this.

NathanOliver 429 Veteran Poster Featured Poster

Do you have the == operator overloaded for the extPersonType? Remove needs to have that defined in order for it to work.

NathanOliver 429 Veteran Poster Featured Poster

Can you post the code that is causing this order?

NathanOliver 429 Veteran Poster Featured Poster

Here is some code that says it will do it in 3.9 seconds. You can take a look at at and see how it works. You Might want to do some goole searches as well for faster algo's. I know there a few really good post on this site that have some very nice algo's

NathanOliver 429 Veteran Poster Featured Poster

Why do you have 2 if's in your for loop on lines 63-69?

NathanOliver 429 Veteran Poster Featured Poster

We only give homework help to those that try. Do you have any code so far? Do you know how to use for loops?

NathanOliver 429 Veteran Poster Featured Poster

Is this homework? If it is you should read this post.

NathanOliver 429 Veteran Poster Featured Poster

Okay. Do you know how to use a for loop?

NathanOliver 429 Veteran Poster Featured Poster

Do you know if the char array is null terminated? If that is all the instructions say then based on what you posted I would say it is impossible. If the char array is null terminated then when you are going through the array your stop condition will be if where you are at is equal to '\0'

//...
int i = 0;
while(charArray[i++] != '\0')
{
    // check goes here
}
//...
NathanOliver 429 Veteran Poster Featured Poster

I think he copied the return statement and forgot to remove the semicolon after changing it to an if. Not sure why he would do that but hey.

NathanOliver 429 Veteran Poster Featured Poster

I would guess that the char array he is getting is a string and it is null terminated as well but that is just a guess. Without seeing the problem statement it's impossible to tell what is going on. Just like getting the size of an array from only a pointer to the begining ;)

NathanOliver 429 Veteran Poster Featured Poster

@ Suzie999 the OP also said this

However one of the functions doesn't have a length passed with the other parameters!
char arrayX(char a[], char v)
Where you are asked to find amount of times value (v) is in the array.

He is trying to write a function to deal with an array where he is not getting a size of the array. If there is not a sentinal value in the array to mark the end there is no posible way to find out the size of the array that is standard conforming and portable. All you get in the function is a pointer to the first value of the array.

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

what happenes if you change line 63 from

for (int a = 0; a < n - 1; a++)

to

for (int a = j; a < n - 1; a++)
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

Line 31 is not correct. If you are using a regular sieve you need to have all values from 2 to the highest number to check. on line 31 you only allocate enough space for n - m when you should allocate all the way to n.

NathanOliver 429 Veteran Poster Featured Poster

Do the requierments want the output to be to a file? I know with most online judges they want the output written to stdout. That could be what is giving you the error. Can you paste the instructions from the website to a post?

NathanOliver 429 Veteran Poster Featured Poster

Are you supposed to write the answers to a file?

NathanOliver 429 Veteran Poster Featured Poster

After reading that wiki link you provided I am not a big fan. In order for it to work the person using it will need to know the internals of the class to know what to pass. To me this harms encapsulation. I dont think I'll be using it unless like you said deceptikon,

iff it's widely adopted amongst C++ programmers and not just the elite.

NathanOliver 429 Veteran Poster Featured Poster

What do you have so far?

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

Yes you should always declare a parameter as const if you are not going to modify it and it is not being passed by value. Also you dont really need to pass the variables to the functions since they exist in your class. Any function in you class can access the member data of the class.

NathanOliver 429 Veteran Poster Featured Poster

Lines 85 and 86 need to switched in Shoes.cpp. Your txt file goes name, number, size and you are reading in name size, number.

NathanOliver 429 Veteran Poster Featured Poster

line 9 should be

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

You only need to call cout once.