8 Replies - 1795 Views - Last Post: 25 October 2006 - 01:26 AM Rate Topic: -----

#1 aznballerlee  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 61
  • Joined: 14-October 06

Functions Project: DDR

Posted 23 October 2006 - 03:12 PM

I just got my CS project today, and I read over it. It doesn't make sense to me.

We have acquired some Dance Dance Revolution software that will display on a screen the sequence of arrows for a dance. The software requires as input a string of characters; each character is an instruction for what to display for one beat of the song. The characters are:

	* l, d, u, or r, meaning to display an arrow indicating that the dancer should tap the left, down, up, or right arrow on the dance pad.
	* L, D, U, or R, meaning to display an symbol indicating that the dancer should freeze a foot on the left, down, up, or right arrow on the dance pad.
	* x, meaning to display nothing for this beat, indicating that the dancer is not required to step anywhere for this beat.

A well-formed dance is a sequence of zero or more beats. Here are some examples of well-formed dances:

	*		   zero beats
	* D/
	* u//D/3r///d/
	* 03u///10r//////////
	* ///	   three beats

____________________________-
[b]Your task[/b]

For this project, you will implement the following two functions, using the exact function names, parameters types, and return types shown in this specification. (The parameter names may be different if you wish.)

bool isDanceWellFormed(string dance)

This function returns true if its parameter is a well-formed dance, and false otherwise. 
int translateDance(string dance, string& instructions, int& badBeat)

If the parameter dance is translatable, the function sets instructions to the translation of the dance, leaves badBeat unchanged, and returns 0. In all other cases, the function leaves instructions unchanged. If dance is not well-formed, the function leaves badBeat unchanged and returns 1. If dance is well-formed but while a freeze is in effect, a beat not consisting of only a slash is present, badBeat is set to the number of that beat (where the first beat of the whole dance is number 1, etc.), and the function returns 2. If dance is well-formed but ends prematurely, badBeat is set to one more than the number of beats in the string, and the function returns 3. If dance is well-formed but a beat specifies a freeze of length less than 2, badBeat is set to the number of that beat, and the function returns 4. If the dance is well-formed but not translatable for more than one reason, report the leftmost occuring problem. (For example, if dance is 3r//u/0d//2u/, set badBeat to 3 and return 2.) 

These are the only two functions you are required to write. (Hint: translateDance may well call isDanceWellFormed.) Your solution may use functions in addition to these three. While we won't test those additional functions separately, their use may help you structure your program more readably. Of course, to test them, you'll want to write a main routine that calls your functions. During the course of developing your solution, you might change that main routine many times. As long as your main routine compiles correctly when you turn in your solution, it doesn't matter what it does, since we will rename it to something harmless and never call it (because we will supply our own main routine to throroughly test your functions).

Your functions must not use any global variables.

When you turn in your solution, neither of the two required functions, nor any functions they call, may write any output to cout. (Of course, during development, you may have them write whatever you like to help you debug.) If you want to print things out for debugging purposes, write to cerr instead of cout. cerr is the standard error destination; items written to it by default go to the screen. When we test your program, we will cause everything written to cerr to be discarded instead -- we will never see that output, so you may leave those debugging output statements in your program if you wish.






Okay so this was the assignment. I have no idea what it asks for. DO I come up wtih a code that has a return value for each of the condition?? Any help in simplifying this assignment would help.

Is This A Good Question/Topic? 0
  • +

Replies To: Functions Project: DDR

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Functions Project: DDR

Posted 23 October 2006 - 04:33 PM

Think of it in two parts...validation and translation. In the first part, you'll take a string entered by the user. You can then traverse that string, character by character, and make sure that each character is a valid one (you have the list above). If a character is not valid, generate an error.

The second part is essentailly the replacement of the valid characters with their corresponding symbols, along with some error checking. I'm not sure what a freeze is, or how one tells if a dance measure ends short, so I'd need more information before commenting.
Was This Post Helpful? 0
  • +
  • -

#3 aznballerlee  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 61
  • Joined: 14-October 06

Re: Functions Project: DDR

Posted 23 October 2006 - 05:44 PM

I left out these parts.


A full Dance Dance Revolution system has dances requiring a player to step on two different arrows at the same time (using both feet), and requiring several steps per beat (corresponding to eighth and sixteenth notes). For this project, we will assume something simpler: All dances require stepping on at most one arrow per beat. A step is either a tap, where the player steps on the arrow and then lifts the foot on the same beat, or a freeze, where the player steps on the arrow on one beat, and then keeps it there, lifting it off at a later beat.

Now for the bad news: The artists who design the dances are used to expressing them a different way. For them, a dance is expressed as a string like u//d/3r///d/, where a slash terminates every beat. This means "For the first beat, tap up. Nothing is required for the second beat. For the third beat, tap down. Starting on the fourth beat, freeze on the right arrow for three beats (the fourth, fifth, and sixth). For the seventh beat, tap down."




Thanks Amadeus for the overview. I still don't know how to start though. How do I validate the strings when I don't have them .. ? Or do I just do a bunch of if statements, testing each possibility or strings?
Was This Post Helpful? 0
  • +
  • -

#4 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Functions Project: DDR

Posted 23 October 2006 - 06:27 PM

You can use test strings...and build the function to check the string that will be provided as a parameter. As for checking the characters, you can use an if else if contruct, or use a switch statement, as you're checking characters, not a full string all at once. Since there is only a limited number of valid characters, it should not take that many statements.
Was This Post Helpful? 0
  • +
  • -

#5 aznballerlee  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 61
  • Joined: 14-October 06

Re: Functions Project: DDR

Posted 23 October 2006 - 07:23 PM

Yes, I understand more of the concepts in testing the strings.
THe problem is now, I do'nt know how to start.

I don't clearly understand building the function either.
My first guesses would be using boolean expressions
to see if dance is translatable, but I don't know how to do that.

Any suggestions to help me get a piece started at least?? I'm stuck
sitting in front of the computer right now and I've read the chapter in the
book like 5 times!
Was This Post Helpful? 0
  • +
  • -

#6 aznballerlee  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 61
  • Joined: 14-October 06

Re: Functions Project: DDR

Posted 23 October 2006 - 07:43 PM

Actually, let me clarify:

Would this be part 1?:
If the parameter dance is translatable, the function sets instructions to the translation of the dance, leaves badBeat unchanged, and returns 0. In all other cases, the function leaves instructions unchanged. If dance is not well-formed, the function leaves badBeat unchanged and returns 1. If dance is well-formed but while a freeze is in effect, a beat not consisting of only a slash is present, badBeat is set to the number of that beat (where the first beat of the whole dance is number 1, etc.), and the function returns 2. If dance is well-formed but ends prematurely, badBeat is set to one more than the number of beats in the string, and the function returns 3. If dance is well-formed but a beat specifies a freeze of length less than 2, badBeat is set to the number of that beat, and the function returns 4. If the dance is well-formed but not translatable for more than one reason, report the leftmost occuring problem. (For example, if dance is 3r//u/0d//2u/, set badBeat to 3 and return 2.)



Also, where would these codes fit into the function?
bool isDanceWellFormed(string dance)



and this
int translateDance(string dance, string& instructions, int& badBeat)


Was This Post Helpful? 0
  • +
  • -

#7 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Functions Project: DDR

Posted 23 October 2006 - 09:31 PM

Those are the function declarations that you will use for each of your functions. They tell you what value the function will return, the name of the function, and what parameters your function will take.
Was This Post Helpful? 0
  • +
  • -

#8 aznballerlee  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 61
  • Joined: 14-October 06

Re: Functions Project: DDR

Posted 24 October 2006 - 03:35 PM

What I have so far is this:

Code:

#include <iostream>
using namespace std;


int translateDance
// This is where I write a function for translateDance, but I don't know how.
I'm guessing I have to test the different possibilities in the order / structure
or the dance beats and freezes? (do if / else on those) and have it return
false if the semantics are wrong?


// I don't know what I did with the following lines.
I got help today and they showed me this.
But I don't really get it.

int main()
{	
	


int i;
for (i = 0, i =inputsize (); i++)
{
	if (input [i] >= '0' && input [i] <= '9')
	{ 
		int digit = input [i] - '0';
		for (j= i+2; j< i+2 + digit; j++)
		{
			if (input [j] != "/")
				cerr << "Error";
		}
	}


	
}




Any suggestions?
Was This Post Helpful? 0
  • +
  • -

#9 gregoryH  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 60
  • View blog
  • Posts: 656
  • Joined: 04-October 06

Re: Functions Project: DDR

Posted 25 October 2006 - 01:26 AM

View Postaznballerlee, on 24 Oct, 2006 - 03:35 PM, said:

What I have so far is this:


Code:

#include <iostream>
using namespace std;


int translateDance
// This is where I write a function for translateDance, but I don't know how.
//I'm guessing I have to test the different possibilities in the order / structure
//or the dance beats and freezes? (do if / else on those) and have it return
//false if the semantics are wrong?
//<<-- should be:
int translateDance(string dance, string& instructions, int& badBeat);


// I don't know what I did with the following lines.
I got help today and they showed me this.
But I don't really get it.

int main()
{	
	


int i;
for (i = 0, i =inputsize (); i++)
{
	if (input [i] >= '0' && input [i] <= '9')
	{ 
		int digit = input [i] - '0';
		for (j= i+2; j< i+2 + digit; j++)
		{
			if (input [j] != "/")
				cerr << "Error";
		}
	}


	
}



I can see you are having trouble with the concepts. If yuou try to see this all at once. you get muddled and confused.... some level of decomposition and planning will go a long way to clarify what you want to achieve. See here for some information to help with functional decomp.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1