Question

In: Computer Science

I need assistance on this problem in Pseudocode and in C++ Program 1: Stay on the...

I need assistance on this problem in Pseudocode and in C++ Program

1: Stay on the Screen! Animation in video games is just like animation in movies – it’s drawn image by image (called “frames”). Before the game can draw a frame, it needs to update the position of the objects based on their velocities (among other things). To do that is relatively simple: add the velocity to the position of the object each frame. For this program, imagine we want to track an object and detect if it goes off the left or right side of the screen (that is, it’s X position is less than 0 and greater than the width of the screen, say, 100). Write a program that asks the user for the starting X and Y position of the object as well as the starting X and Y velocity, then prints out its position each frame until the object moves off of the screen. Design (pseudocode) and implement (source code) for this program.

Sample run 1:

Enter the starting X position: 50

Enter the starting Y position: 50

Enter the starting X velocity: 4.7

Enter the starting Y velocity: 2

X:50 Y:50

X:54.7 Y:52

X:59.4 Y:54

X:64.1 Y:56

X:68.8 Y:58

X:73.5 Y:60

X:78.2 Y:62

X:82.9 Y:64

X:87.6 Y:66

X:92.3 Y:68

X:97 Y:70

X:101.7 Y:72

Sample run 2:

Enter the starting X position: 20

Enter the starting Y position: 45

Enter the starting X velocity: -3.7

Enter the starting Y velocity:

11.2 X:20 Y:45

X:16.3 Y:56.2

X:12.6 Y:67.4

X:8.9 Y:78.6

X:5.2 Y:89

.8 X:1.5 Y:101

X:-2.2 Y:112.2

This assignment is about Repetition Structures.

For Pseudocode, here are key words to use

: · DO … WHILE – A loop that will always run at least once ·

FOR … ENDFOR – A loop that runs until certain criteria is met ·

WHILE … ENDWHILE – A loop that runs only while certain criteria is met ·

FOREACH … ENDFOREACH – A loop that runs over elements in a data structure · BREAK - "break out" of the current loop (or other structure) you're in and start immediately after the loop · CONTINUE - skip over the current iteration of the loop and move on to the next one

Solutions

Expert Solution

Below is the C++ code I hope that i have provided sufficient comments for your better understanding Note that I have done proper indentation but this code is automatically left alligned on this interface

#include<bits/stdc++.h>
using namespace std;
#define WIDTH 100 //Let width of screen be 100
using namespace std;

int main()
{
double x_pos, y_pos;
double x_vel, y_vel;

cout<<"Using do while loop"<<endl;
//Take users input
cout<<"Enter the starting X position: ";
cin>>x_pos;

cout<<"Enter the starting Y position: ";
cin>>y_pos;

cout<<"Enter the starting X velocity: ";
cin>>x_vel;

cout<<"Enter the starting Y velocity: ";
cin>>y_vel;

//using do while loop
do
{
cout<<"X:"<<x_pos<<" Y: "<<y_pos<<endl;
x_pos += x_vel;
y_pos += y_vel;
}while(x_pos>=0 && x_pos<=WIDTH); //Apply the specified condition
cout<<"X:"<<x_pos<<" Y: "<<y_pos<<endl;
cout<<endl;

cout<<"Using for loop"<<endl;
//Take users input
cout<<"Enter the starting X position: ";
cin>>x_pos;

cout<<"Enter the starting Y position: ";
cin>>y_pos;

cout<<"Enter the starting X velocity: ";
cin>>x_vel;

cout<<"Enter the starting Y velocity: ";
cin>>y_vel;
//using for loop
for( ;x_pos>=0&&x_pos<=WIDTH; ) //Apply the specified condition
{
cout<<"X:"<<x_pos<<" Y: "<<y_pos<<endl;
x_pos += x_vel;
y_pos += y_vel;
}
cout<<"X:"<<x_pos<<" Y: "<<y_pos<<endl;
cout<<endl;

cout<<"Using while loop"<<endl;
//Take users input
cout<<"Enter the starting X position: ";
cin>>x_pos;

cout<<"Enter the starting Y position: ";
cin>>y_pos;

cout<<"Enter the starting X velocity: ";
cin>>x_vel;

cout<<"Enter the starting Y velocity: ";
cin>>y_vel;
//using while loop
while(x_pos>=0&&x_pos<=WIDTH) //Apply the specified condition
{
cout<<"X:"<<x_pos<<" Y: "<<y_pos<<endl;
x_pos += x_vel;
y_pos += y_vel;
}
cout<<"X:"<<x_pos<<" Y: "<<y_pos<<endl;
cout<<endl;
}

Below is the screenshot of output

I have tried to explain it in very simple language and I hope that i have answered your question satisfactorily.Leave doubts in comment section if any.


Related Solutions

I need assistance on this problem in Pseudocode and in C++ Program Program 3: Give a...
I need assistance on this problem in Pseudocode and in C++ Program Program 3: Give a baby $5,000! Did you know that, over the last century, the stock market has returned an average of 10%? You may not care, but you’d better pay attention to this one. If you were to give a newborn baby $5000, put that money in the stock market and NOT add any additional money per year, that money would grow to over $2.9 million by...
Hello, I need some assistance on completing this program in Pseudocode and in C++ Program 2:...
Hello, I need some assistance on completing this program in Pseudocode and in C++ Program 2: Buh-RING IT! For this assignment, you’re going to simulate a text-based Role-Playing Game (RPG). Design (pseudocode) and implement (source) for a program that reads in 1) the hero’s Hit Points (HP – or health), 2) the maximum damage the hero does per attack, 3) the monster’s HP and 4) the maximum monster’s damage per attack. When the player attacks, it will pick a random...
IN PSEUDOCODE and C++ Program 1: Stay on the Screen! Animation in video games is just...
IN PSEUDOCODE and C++ Program 1: Stay on the Screen! Animation in video games is just like animation in movies – it’s drawn image by image (called “frames”). Before the game can draw a frame, it needs to update the position of the objects based on their velocities (among other things). To do that is relatively simple: add the velocity to the position of the object each frame. For this program, imagine we want to track an object and detect...
i need the pseudocode and python program for the following problem. Besides the user entering the...
i need the pseudocode and python program for the following problem. Besides the user entering the number of books purchased this order, they are asked for the number of points earned for the year before this order and the number of books ordered this year before this order. There are bonus points awarded based on the number of books previously ordered and number ordered now. These points should be added to the variable points: Current order: 0 Previous Orders >...
I need assistance translating a custom C++ program to MIPS. My C++ code is the following:...
I need assistance translating a custom C++ program to MIPS. My C++ code is the following: I have made numerous attempts on my own to no avail, any assistance is appreciated. Also, template code for this solution is provided below: #include int moveRobots(int *, int *, int, int ); int getNew(int, int); int main() { int x[4], y[4], i, j, myX = 25, myY = 25, move, status = 1; // initialize positions of four robots x[0] = 0; y[0]...
C Program and pseudocode for this problem. Write a C program that plays the game of...
C Program and pseudocode for this problem. Write a C program that plays the game of "Guess the number" as the following: Your program choose the number to be guessed by selecting an integer at random in the rang of 1 to 1000. The program then asks the use to guess the number. If the player's guess is incorrect, your program should loop until the player finally gets the number right. Your program keeps telling the player "Too High" or...
i need a pseudocode for a program in java that will convert dollars into euros and...
i need a pseudocode for a program in java that will convert dollars into euros and japanese yen using the print and prinln methods an if, if -else, statement a switch statement a while statement utilizes the file class uses the random class and random number generator and uses at least three methods other than main
This problem needs to be solved with source code. I need a C++ program that will...
This problem needs to be solved with source code. I need a C++ program that will help me solve this question. I need it in C++, please. Writing with comments so it maybe cleared. 1.2. We received the following ciphertext which was encoded with a shift cipher: xultpaajcxitltlxaarpjhtiwtgxktghidhipxciwtvgtpilpit ghlxiwiwtxgqadds. 1. Perform an attack against the cipher based on a letter frequency count: How many letters do you have to identify through a frequency count to recover the key? What is...
Need this in C# and also the Pseudocode. Program 4: In 1789, Benjamin Franklin is known...
Need this in C# and also the Pseudocode. Program 4: In 1789, Benjamin Franklin is known to have written “Our new Constitution is now established, and has an appearance that promises permanency; but in this world nothing can be said to be certain, except death and taxes.” Our federal tax system is a “graduated” tax system which is broken into seven segments. Essentially, the more you make, the higher your tax rate. For 2018, you can find the tax brackets...
I need a pseudocode and UML for this program. import java.util.Random; public class SortandSwapCount {   ...
I need a pseudocode and UML for this program. import java.util.Random; public class SortandSwapCount {    public static void main(String[] args) {        //Generate random array for test and copy that into 3 arrays        int[] arr1=new int[20];        int[] arr2=new int[20];        int[] arr3=new int[20];        int[] arr4=new int[20];        Random rand = new Random();        for (int i = 0; i < arr1.length; i++) {            //Generate random array...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT