![]() |
| ||
| need help for this code You are required to write a program which will: · Fetch inputs from the user · Ask the user how many words that he want to insert · Append the original inputs to the screen (and save to a file called as string.txt) · Append the scrambled inputs to the screen (and save to a file called as shuffle.txt) · Shuffled inputs contain the new modified sentence which all the words are randomly scattered. · The amount of reshuffled repeated are based from the user’s intention · Read/search on randomize ( rand(), srand() ) to help you on this. Refer page 150 and above in your textbook- Chapter 4. Also, find a function call within algorithm library which allow you to reshuffle arrays’ element-do Internet search! (which means you have to do #include<algorithm> as the processor directive. · Since you are dealing with words, use “string” data type. the example output See the example output in the screen below: Begin file creation Insert how many words 6 Please insert the words that you want to scramble I HAVE A CAT, BIG CAT! Original word.... I HAVE A CAT, BIG CAT! Scrambling character(s)... Iteration #1 I CAT! CAT, BIG HAVE A Reshuffle? Y Scrambling character(s)... Iteration #2 I HAVE A CAT! CAT, BIG Reshuffle? Y Scrambling character(s)... Iteration #3 I BIG CAT, HAVE CAT! A Reshuffle? Y Scrambling character(s)... Iteration #4 I A CAT! CAT, BIG HAVE Reshuffle? Y Scrambling character(s)... Iteration #5 I HAVE BIG CAT! A CAT, Reshuffle? N Stop at iteration #5 Thank you! Contents of string.txt I HAVE A CAT, BIG CAT! Contents of shuffle.txt I CAT! CAT, BIG HAVE A I HAVE A CAT! CAT, BIG I BIG CAT, HAVE CAT! A I A CAT! CAT, BIG HAVE I HAVE BIG CAT! A CAT, ok, i've done this code using dev-c++. the problem is, when the program random the word, the word that came out is unreadable and i can't store the output to shuffle.txt file. can somebody define the mistake of this code? this is the code: #include <iostream>my example how many word is '6' my example word is 'i have a cat, big cat!' i need a quick answer actually and thank u for helping. beside reply it here, you can reply it to my e-mail [snipped email] i really need the answer as fast as you can. sorry for trouble! |
| ||
| Re: need help for this code That code doesn't even compile so how you get an output file who knows? |
| ||
| Re: need help for this code u can't? is something wrong with code cos my compiler can compile it. the problem occurred when it comes to random the word and to save it to the shuffle.txt |
| ||
| Re: need help for this code >is something wrong with code cos my compiler can compile it This is a lie. Please don't lie to us. (I am using dev-cpp) Also, read your assignment, aren't you supposed to use random_shuffle from the header file #include <algorithm>or something I don't see you doing that. |
| ||
| Re: need help for this code so, my code is really wrong. i'm sorry coz i'm still new using this dev c++. but i really don't understand about the algorithm. i can't use this code at all? sorry for making trouble. can u tell me which part is wrong but this code can run right? |
| ||
| Re: need help for this code Firstly, you shouldn't lie to us. Don't pretend you are new to dev-cpp and you have compiled that code you posted and got an output, because clearly you haven't! Second I shall give you a few clues. -You need to use getline to read in a string. (you may be doing this already) -you need to separate the string into tokens, this is generally called tokenising your input, the whitespace will be your delimiter here. -now you can put your words into an array or vector, this depends on what you teacher is expecting. -Then you can shuffle the words about using the code: http://www.cplusplus.com/reference/a...m_shuffle.html Then write that to a file. Third, we don't do favours, it's only urgent to you and therefore you should have organised you time better. |
| ||
| Re: need help for this code 1 Attachment(s) thank you very much and sorry for troubling you but i really can run this code and i dun lie. it become like this: Attachment 7507 but anyway, thank u so much. |
| ||
| Re: need help for this code Well then the code you posted above is wrong, or you posted the wrong one by accident. |
| ||
| Re: need help for this code Quote:
nom. Copy and paste the code you posted verbatim and try compiling it again. |
| ||
| Re: need help for this code opss, its really my fault! sorry,sorry!this is the correct code: #include <iostream>so, i just follow what u write it before right? using that random_shuffle but which part did i have to put it? |
| All times are GMT -4. The time now is 1:09 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC