• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C++ Homework Help: Function Parameters and APstring

CaptainKahuna

Platinum Member

I'm learning C++ at the moment, and our teacher assigned this, and I have no idea how to do it. Can anyone help out? The assignment is below:
---------------------------------------------------------------
Write a program that generates the verse of a children's song shown below. Don't worry about the ungrammatical qualities inherent in the use of "goes" and "go" in your first attempt in writing the program. You should include a function with two parameters capable of generating any of the verses when the appropriate arguments are passed. Strive to make your program "elegant and succinct."
The wheel on the bus goes round round round,
round round round
round round round
The wheel on the bus goes round round round
All through the town

The wipers on the bus goes swish swish swish
swish swish swish
swish swish swish
The wipers on the bus goes swish swish swish
All through the town

The horn on the bus goes beep beep beep
beep beep beep
beep beep beep
The horn on the bus goes beep beep beep
All through the town

The money on the bus goes click click click
click click click
click click click
The money on the bus goes click click click
All through the town

Is it possible to generate a verse of the song based on the lines
The driver on the bus goes move on back
move on back
move on back

With small modifications? How many parameters would the Verse function of such a song have?
-----------------------------------------------------------
Thanks in advance for the help.
 
1) Analyze the patterns.
2) Create a list of words
3) Create a list of common phrases
4) Build strings of #2 and #3
5) Build a master array containing the indexs from #4 to create the song.
 
function verse($noun, $sound)
{
echo
"The $noun on the bus goes $sound $sound $sound,
$sound $sound $sound
$sound $sound $sound
The $noun on the bus $sound $sound $sound
All through the town";
}

That's PHP, though, I assume it's a wee bit more complicated in C++.
 
Actually not too complicated and looks similar, well to a point anyway 🙂

void DisplayVerse(const char* const Noun, const char* const Sound);

Probably a little easier to write if you also made some const char const * of other phrases.

You can leave out the const keyword if your class is not up to that level and the teacher will get suspicious.

const (if you don't know) just a helps in debuging by not allowing you to change stuff you declare as const. There are ways around it though with keyword casting or mutable for members in classes.


EJ

 
Back
Top