Saturday, May 22, 2010

Plz make this c++ program for me...ive tried but cant...?

make a C++ Program which will take the string as input during run time and will display the different arrangements of string on Console.User can enter spaces and enters while entering string during run time.String can have alphabets, numbers and special characters and spaces and enter characters.Your program will do the following


1. Will display the user entered string in the same order as the user entered, without spaces and enter characters


2. Will display the string in a reverse order printing from end to start without spaces and enter characters


3. Will display the string with spaces and enter characters in it, in the order as user entered.


4. Program will display the string with spaces and enter characters in it in the reverse order as users entered.


5. User can enter any number of characters even more than 2000 characters.

Plz make this c++ program for me...ive tried but cant...?
Honey, the program isn't that complicated, but it will take awhile and frankly I don't feel like doing your homework for you. (Although it's an interesting problem...)





Some suggestions, most of which you should already know:





1) Plan the thing out BEFORE you get near a keyboard. A major mistake newbie programmers often make is to just start typing. That way lies the kludge.





2) How are you going to have the user input the string? Since the problem specifically says that the enter keys should be recorded as well as spaces and the like, and most of the built-in streams delimit on enter, you're going to have to find another way to do it. How about a loop, reading one key at a time? You'll have to find a way for the user to let the program know that you're done entering data - perhaps pressing the Escape key will do it. Testing for that should be easy. I would suggest a post-test while. However, using a loop like this will make other problems of yours - specifically, storing the characters in an array without spaces and keeping track of spaces and enters - much easier.





3) How are you going to structure the array for spaces and enters? You'll have to have some way for the program to know where to re-insert them in the original string, as well as a way to differentiate between them. My first thought would be a two-dimensional array, with the first element of each row being the location of the "object" and the second being a code to indicate which "object" it is.





4) Once you have those, item 3 will solve itself. Just a loop starting at the beginning and interpreting the data in the two arrays.





5) Item 4 isn't much harder - the same loop as the other but starting at the end of the array and decrementing as you go.





6) That bit about "any number of characters" indicates that you're either going to need to reserve a huge array to hold them or you're going to need a dynamic array. If those last two words ("dynamic array") don't make any sense to you, you probably aren't expected to be able to do that.





7) Once you have your algorithm planned out COMPLETELY, do a desk check on it before you start coding. A lot of newbies skip this step, too, and it costs them. You want to know your program is going to work before you spend time and effort in coding it. Once again, the word "kludge" rears its ugly head.





I know this is tough, but trust me - the skills you're learning here will help you more than you can imagine later on when you're writing the programs you want to write.


No comments:

Post a Comment