Hi, my professor told me to write this program in my Computer Science Programming Class but I have no idea on how to do this. Can someone give me tips or help me out on how to this?
You have some code to start with. Under The Procedures it is described how you should do it step by step. Start with (1). When have finished (1) do (2), etc.
The first thing to do is to writeout the requirements
and the 2nd thing is to put those requirements into a logical order.
The teacher has you well started already by providing a MAIN() function.
I would place the " infinite " LOOP in there - inside MAIN().
It'll run forever until the game is finished or the computer rusts.
Then place everything else into separate functions
Loop
disp msg n.e.w.s.-x to exit
get pos
update pos
calc Dist
disp dist
# 7. Decisions……………
"Your location is: ( x,y);
END OF LOOP
print num of steps
stop
Each of these steps or processes can be,
and should be separate function calls.
Loop {
DispDirMenu();
GetDirection();
UpdatePosition();
CalcDistance();
DisplayDistance();
CalcDecisions_and_PrintMsg(); // see item #7 for details
DispLocation(); // "Your location is: ( x,y);
} // end of loop
print num of steps();
} // end of main()
Remember to declare your global vars outside main
declare your local vars in main or in each func()
comment each step.
ps, using SWITCH statement is required (inside the "CalcDecisions_and_PrintMsg" functioin.
pss, keep your comments lined-up, cuz teachers hate it when they're not.
Procedures
1. You must use a LOOP
2. At the start of the loop, display the message "Please enter direction (n,s,e,w), or x to exit: ".
3. Now, get the position from the keyboard.
4. Update the Explorer’s coordinates
5. Calculate the distance from the explorer to the treasure:
Distance = sqrt(static_cast<double>((x-x1)*(x-x1)+(y-y1)*(y-y1)))
6. Display the distance from the Treasure (this information will clue the Explorer to either keep going in the same direction or switch directions).
7. Decisions……………
If the distance is greater than 8 then you display the message "you are too far from the treasure".
If the distance is greater than 4 and less or equal to 8 you display the message "you are far from the treasure".
If the distance is less or equal to 4 you display the message "you are getting closer to the treasure".
Also, check if you have reached the treasure (i.e., x=x1, and y=y1); and if so, Get out of the loop and display the message "congratulations, you have reached the treasure".
8. At the end of each loop display the message "Your location is: ( x,y); where x and y are the
Explorer’s coordinates
9. Make sure that you print out how many steps it took to reach the treasure