Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3. Create a Program From Pseudocode This exercise will be to use pseudocode (in the form of comments) to write a program that simulates a

3. Create a Program From Pseudocode

This exercise will be to use pseudocode (in the form of comments) to write a program that simulates a one-sided snowball fight. You select the row and column you want the snowball to hit; if the target is at that location, you get a point; otherwise, you get the distance (but not the direction) of the target from the snowball hit point. The distance is calculated by taking the absolute value of the difference between the x position of the target and the snowball hit and the y position and the snowball hit. Report the larger of the two if they are different.

After each throw of the snowball, the target moves using the following algorithm.

Generate a random number (02). The target doesnt move if the random number is 0. If the random number is 1, the target changes its x position. If the random number is 2, it changes its y position. Randomly choose whether to increment by one or decrement by one. If the target is on the boundary of the grid, move away from the boundary by one.

The grid size should be 5.

The number of turns should be 10.

Here is the pseudocode.

// Week 3 Assignment-3

// Description: Snowball fight - version 1

//----------------------------------

//**begin #include files************

#include // provides access to cin and cout

//--end of #include files-----------

//----------------------------------

using namespace std;

//----------------------------------

//**begin global constants**********

// define a struct of the target

// -- xPos is the x position (the column)

// -- yPos is the y position (the row)

// -- xHit is x position of the hit(the column)

// -- yHit is y position of the hit(the row)

// -- distance between target and snowball hit

// -- hits is how many times the target has been hit

// const grid size (i.e. 5x5 grid constant is 5)

// const number of turns

//--end of global constants---------

//----------------------------------

//**begin main program**************

int main()

{

// initialization

// seed the random number generator

// create the target struct

// set target at random location

// set hits to zero

// loop for the specified number of turns

// get x and y position for the snowball from player

// compare to the target's position

// report hit, or distance of miss (see instructions for details)

// target moves (see instruction for details)

// end of loop

// report score (number of hits vs turns)

// Wait for user input to close program when debugging.

cin.get();

return 0;

}

//--end of main program-------------

//----------------------------------

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

4. Does cultural aptitude impact ones emotional intelligence?

Answered: 1 week ago

Question

7. Do the organizations social activities reflect diversity?

Answered: 1 week ago