IC210

Class 2: Solving a problem with the RAPTOR Flowchart Interpreter.

Reading

None

 

Lecture

The folks at the Air Force Academy have developed a tool call RAPTOR that can be used to develop the algorithm to solve a problem without knowing any C++.  We are going to use this tool to solve the following problem.  You are encouraged to download RAPTOR and install it on your machine.  You will save a LOT of time if you use it to design and test your algorithm before you start writing code.

Problem to Solve (Part a)

Using RAPTOR, design a program that will print the displacement of an object, in a meaningful manner, when the user provides the acceleration, the time, and the velocity.  The necessary formula is: disp = (velocity * time) + (0.5 * accel * time2).  You may test your code by inputting an acceleration of 0.18 m/s^2, a velocity of 2.50 m/s, and a time of 2.37 s.  Your flowchart should then produce a displacement of 6.430521 m.Note that in order to test a solution, you must know, typically by computing by hand, the actual answer for disp that we are expecting (here, 6.430521) before we run the program so we know whether the program works correctly for the input data used.

When we open RAPTOR we see an empty Master Console window that is going to correspond to our output screen when we start writing C++ code.  We also see the following screen where we will design the algorithm for our problem using a flowchart.

 

All we have to do is figure out what to put between the Start and End symbols.  The first thing we need to do is get the acceleration, velocity and time from the user.  Since we have to get three things it will take three steps.  Since we are getting them from the user, we will click on the Input symbol and then click between the Start and End symbols.  That gives us the following

We could also have left-clicked on the line between the Start and End symbols and selected Insert Input.  Now we need to get the acceleration, so we will double click on the first Input symbol.  It will turn red and brings up the following dialog box.

First we will enter a sentence to prompt the user for the acceleration.  Since it is text, we make sure the text radio button is selected.  Then we enter a meaningful variable name to hold the number the user enters.  I chose the variable name accel and my dialog box now looks like

Click done and repeat the same thing to get the velocity and time.  My screen now looks like

Now, before we go any further, let's test it to see if it works.  By clicking on the right-pointing solid arrow on the tool bar, the flowchart will execute and ask for the acceleration, the velocity and the time.  Enter 0.18, 2.5 and 2.37 (do not enter the units) when prompted successfully executes and gives us

The reason we know it works is that the values we entered are listed beside the variable names in the Watch Window in the lower left hand pane.  If you click on the arrow with the | to the right of it, it will walk through the flowchart one step at a time.  Now we have to actually do the algebra.  Since we want displacement the first thing we have to do is solve the algebraic equation for displacement.  That gives us

disp = velocity * time + 0.5 * accel * time2

We now need to put that into the flowchart.  Since we are combining terms on the right-hand side and putting the answer into the left-hand side (disp), we will insert an Assignment symbol and double click on it.

Notice that I used time* time for time2.  If I test my flowchart again, my screen now looks like

I now have a value for the displacement of 6.430521 which is what I should get.  However, I am not done yet because if you look at the Master Console (which is all the user will see when you are executing C++) all we see is ----Run finished----.  That means I have done all the work to solve the problem but haven't told the user the answer.  So I need to print the answer to the Master Console and to do this I will insert an Output symbol.  Now I could just output the 6.430521 but the problem explicitly says the output must be meaningful (as will always be the case).  So it is really going to take two Output symbols, one for a descriptive sentence and one for the value of the displacement.  When I double click on the first output symbol, I get the following dialog box.

First notice, that since I want to print a sentence, I make sure the Output Text radio box is selected.  Then I put the sentence I want and I unclick End current line so my displacement value will occur on the same line as the sentence.  When I double-click on the second Output symbol I get the following dialog box.

Notice that this time I left the Output Expression radio box clicked because I want to print the value stored in the variable disp.  I also left the End current line selected.

My final screen looks like

Now I will execute the flowchart one last time and my Master Console window looks like

I have successfully designed the algorithm and tested it to make sure it works, but I haven't written a single line of C++ code yet.

Problem to Solve (Part b)

Now letís modify our design to check that the user entered a positive value for the time.If not, the program should print a message indicating that the time must be positive and then terminate. 

Since I want to perform the calculation if time is positive and print an error message if it isn't, I need to insert a Selection symbol.  Where should it go?  It needs to go after I have gotten the value for time but before I calculate the value of disp.  I now click on the diamond and get the following dialog box.

Notice that I put the test condition of time > 0 in the slot provided.  Now my screen looks like

However, if I execute the flowchart and provide a negative time, it still prints the displacement.  Notice that there is a Yes line and a No line coming out of the diamond.  I need to put anything that should be done when time > 0 (answer is Yes) on the Yes line and anything that should be done when time <= 0 (answer is No) of the No line.  So I left-click on the Assignment symbol and select Cut.  Then I left-click on the Yes line and select Paste.  Now I have to decide, do I also move the two Output symbols.  Well, I won't be calculating the displacement unless the time is positive and if I don't calculate it then I have nothing to print, so the answer is yes.  When I do the screen looks like

I still am not done because I have to print an error message if the time is not positive.  To print it I will use an Output symbol.  My dialog box looks like

Notice that I had to select the Output Text radio button.  Now it is time to test again.  When I use the same values from part a, I get a displacement of 6.430521 printed to the Master Console window.  But when I enter a time of -2.37 instead, the only thing that appears on the Master Console window is Error! The time must be positive.

Problem to Solve (Part c)

Modify your design so that it prints your name and alpha before it does any work.  To do this all I need do is enter an Output symbol and my final screen looks like

and my Master Console window either looks like

or for a negative time, looks like

 

Problem to Solve (Part d).

Later in this course, you will need to develop C++ source code.Note that partial C++ source code can be generated from the RAPTOR flowchart by selecting C++ from the Generate pull down menu.Selecting the C++ option brings up the default C++ compiler containing the following code.

Youíll need to provide data types for each ?? in the source code, and the source code will need to be modified a bit in order to conform to the required Style Guide as will be discussed in class in the coming lessons.You may find RAPTOR useful in your initial program design due to its code generation capabilities.However, RAPTOR is primarily a tool to aid in algorithm visualization.You will need to be able to produce source code without the aid of RATPOR, particularly on exams.

 


Last modified by LT M. Johnson 08/15/07 09:08 AM