| | |
Help with recursion { recursive helper function }
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2008
Posts: 7
Reputation:
Solved Threads: 0
Can you please help me with the source code solving this task under C++/G++ (linux) or dev C++ (windows)
http://mail.dir.bg/~storage/cPlus_plus111.jpg
Below you can see a hint for solving Exercise P14.1 but I need to write the source for Exercise P14.1 Please help me
http://www.horstmann.com/bigcpp/solutions/ch14/ExP14_1.cpp
http://mail.dir.bg/~storage/cPlus_plus111.jpg
Below you can see a hint for solving Exercise P14.1 but I need to write the source for Exercise P14.1 Please help me
http://www.horstmann.com/bigcpp/solutions/ch14/ExP14_1.cpp
C++ Syntax (Toggle Plain Text)
#include <string> using namespace std; /** Reverse a sentence. */ class Sentence { public: /** Creates a Sentence object. @param aPhrase a sentence to reverse. */ Sentence(string aPhrase); /** Reverses this sentence. @return the reversed sentence */ string reverse(); private: string phrase; }; Sentence::Sentence(string aPhrase) { phrase = aPhrase; } string Sentence::reverse() { if (phrase != "") { string c = phrase.substr(0, 1); string rest = phrase.substr(1, phrase.length() - 1); Sentence tailSentence(rest); phrase = tailSentence.reverse() + c; } return phrase; } int main() { Sentence greeting("Hello!"); cout << greeting.reverse() << "\n"; return 0; }
•
•
Join Date: Nov 2008
Posts: 392
Reputation:
Solved Threads: 72
Mynameisor is incorrect about point 1. But this is clean code that you have copied from the answer book. With your current pathetic knowledge HOW do you think you are going to get away with submitting it??
Where is you EFFORT? Not immediately obvious, so my effort is suddenly lacking.
Where is you EFFORT? Not immediately obvious, so my effort is suddenly lacking.
experience is the most expensive way to learn anything
To help you out a bit more;
To use cout you need to have iostream included
#include <iostream>
Also, don't forget to use
system("pause");
because otherwise your console window will close immediatly and you won't be able to see your code running : - )
To use cout you need to have iostream included
#include <iostream>
Also, don't forget to use
system("pause");
because otherwise your console window will close immediatly and you won't be able to see your code running : - )
Last edited by brechtjah; Dec 8th, 2008 at 7:24 pm.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Populating a 3d vector array
- Next Thread: Can I recive some feedback with my c++ program?
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





