Question

In: Computer Science

Please answer in C++! Let me know if you have any questions about these. Program 1:...

Please answer in C++! Let me know if you have any questions about these.

Program 1:

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

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 number between 0 and up to the maximum damage the player does, and then subtract that from the monster. The same thing happens when the monster attacks the hero, but damage is to the hero. The program should display rounds and the HP of the hero and monster each round. If the hero or monster dies, it should print that this happened and should NOT continue (i.e. no extra text). To learn how to create random numbers, see the appendix.

Sample run 1:

Enter the hero's starting hit points: 50

Enter the damage the hero’s weapon does per strike: 20

Enter the monster's starting hit points: 40

Enter the monster's damage per strike: 15

====== ROUND 1 ======

Hero attacks for: 10

Monster has 30 HP left

Monster attacks you for: 1

You have 49 HP left

====== ROUND 2 ======

Hero attacks for: 18

Monster has 12 HP left

Monster attacks you for: 7

You have 42 HP left

====== ROUND 3 ======

Hero attacks for: 0

Monster has 12 HP left

Monster attacks you for: 14

You have 28 HP left

====== ROUND 4 ======

Hero attacks for: 18

Monster has -6 HP left

The monster dies and you earn 5 XP

Battle ends...

Program 3:

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 the time that baby is ready for retirement (67 years)! Don’t believe us? Check out the compound interest calculator from MoneyChimp and plug in the numbers! To keep things simple, we’ll calculate interest in a simple way. You take the original amount (called the principle) and add back in a percentage rate of growth (called the interest rate) at the end of the year. For example, if we had $1,000 as our principle and had a 10% rate of growth, the next year we would have $1,100. The year after that, we would have $1,210 (or $1,100 plus 10% of $1,100). However, we usually add in additional money each year which, for simplicity, is included before calculating the interest. Your task is to design (pseudocode) and implement (source) for a program that 1) reads in the principle, additional annual money, years to grow, and interest rate from the user, and 2) print out how much money they have each year. Task 3: think about when you earn the most money! Lesson learned: whether it’s your code or your money, save early and save often…

Sample run 1:

Enter the principle: 2000

Enter the annual addition: 300

Enter the number of years to grow: 10

Enter the interest rate as a percentage: 10

Year 0: $2000

Year 1: $2530

Year 2: $3113

Year 3: $3754.3

Year 4: $4459.73

Year 5: $5235.7

Year 6: $6089.27

Year 7: $7028.2

Year 8: $8061.02

Year 9: $9197.12

Year 10: $10446.8

Solutions

Expert Solution

Program1:-

#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
   float xpos,ypos,xvel,yvel; //decalring float varibles
   printf("Enter the starting X position: ");
   scanf("%f",&xpos); //taking values from user
   printf("Enter the starting Y position: ");
   scanf("%f",&ypos); //taking values from user
   printf("Enter the starting X velocity: ");
   scanf("%f",&xvel); //taking values from user
   printf("Enter the starting Y velocity: ");
   scanf("%f",&yvel); //taking values from user
   if(xpos>=50){ //if xpos is greaterthan 49
       while(xpos<100+xvel){ //loop until xpos is exceeded 100
           printf("\nX:%.1f Y:%.1f",xpos,ypos); //printing xpos,ypos
           xpos=xpos+xvel; //adding xvel to xpos
           ypos=ypos+yvel; //adding yvel to ypos
       }
   }
   else if(xpos<50){ //if xpos is less than
       while(xpos>-xvel){ //loop until xpos is less than 0
           printf("\nX:%.1f Y:%.1f",xpos,ypos); //printing xpos,ypos
           xpos=xpos-xvel; //deleting xvel from xpos
           ypos=ypos+yvel; //deleting yvel from ypos
       }
   }
}

Output:-

Program2:-

#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<time.h> //including libraries
using namespace std;
int main(){
   srand (time(NULL)); //srand to get different random number each time
   int herohp,heratt,monhp,monatt; //decalring varaibles
   cout<<"Enter the hero's starting hit points: ";
   cin>>herohp; //taking input from user
   cout<<"Enter the damage the hero’s weapon does per strike: ";
   cin>>heratt; //taking input from user
   cout<<"Enter the monster's starting hit points: ";
   cin>>monhp; //taking input from user
   cout<<"Enter the damage the monster’s weapon does per strike: ";
   cin>>monatt; //taking input from user
   int round=0;
   while(1){ //loop until it breaks
       cout<<"\n====== ROUND"<<round++<<" ======"<<endl;
       int heroattack=rand()%heratt+1; //generating random number in limit of heroatt
       int monsterattack=rand()%monatt+1; //generating random number in limit of monatt
       monhp=monhp-heroattack; //deleting heroattack from monhp
       cout<<"Hero attacks for: "<<heroattack<<endl;
       cout<<"Monster has "<< monhp<<" HP left"<<endl;
       if(monhp<=0){ //if monster health is less than 0
           cout<<"The monster dies and you earn 5 XP"<<endl<<"Battle ends...";
           break;
       }
       herohp=herohp-monsterattack;
       cout<<"Monster attacks for: "<<monsterattack<<endl;
       cout<<"Hero has "<< herohp<<" HP left"<<endl;
       if(herohp<=0){ //if hero health is less than 0
           cout<<"The Hero dies and Monster earn 5 XP"<<endl<<"Battle ends...";
           break;
       }
      
   }
}

Output:-

Program3:-

#include<stdio.h>
#include<iostream>//libraries
using namespace std;
int main(){
   float prin,annuadd,years,interest;
   cout<<"Enter the principle: ";
   cin>>prin; //taking input from user
   cout<<"Enter the annual addition: ";
   cin>>annuadd; //taking input from user
   cout<<"Enter the number of years to grow: ";
   cin>>years; //taking input from user
   cout<<"Enter the interest rate as a percentage: ";
   cin>>interest; //taking input from user
   int i;
   for(i=0;i<=years;i++){
       cout<<"Year "<<i<<":";
       cout<<prin<<endl;
       prin=prin+annuadd;
       prin=prin+((prin)/interest); //calculating value
      
   }
}

Output:-

#any doubts please comment

C:\Users\SATISH KOHLN Desktop\p1.exe 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.0 Y:50.0 X:54.7 Y:52.0 X:59.4 Y:54.0 X:64.1 Y:56.0 X:68.8 Y:58.0 X:73.5 Y:60.0 X:78.2 Y:62.0 K:82.9 Y:64.0 K:87.6 Y:66.0 X:92.3 Y:68.0 X:97.0 Y:70.0 K: 101.7 Y:72.0 Process exited after 3.95 seconds with return value o Press any key to continue ...

Enter the hero's starting hit points: 50 Enter the damage the heroes weapon does per strike: 20 Enter the monster's starting hit points: 40 Enter the damage the monsters weapon does per strike: 15 ====== ROUNDO ====== Hero attacks for: 13 Monster has 27 HP left Monster attacks for: 4 Hero has 46 HP left ====== ROUND1 ====== Hero attacks for: 20 Monster has 7 HP left Monster attacks for: 10 Hero has 36 HP left ====== ROUND2 ====== Hero attacks for: 8 Monster has -1 HP left The monster dies and you earn 5 XP Battle ends... Process exited after 4.214 seconds with return value o Press any key to continue ...

Enter the principle: 2000 Enter the annual addition: 300 Enter the number of years to grow: 10 Enter the interest rate as a percentage: 10 Year @:2000 Year 1:2530 Year 2:3113 Year 3:3754.3 Year 4:4459.73 Year 5:5235.7 Year 6:6089.27 Year 7:7028.2 Year 8:8061.02 Year 9:9197.12 Year 10:10446.8 Process exited after 3.157 seconds with return value o Press any key to continue ...


Related Solutions

I have tried to answer the following questions. Please let me know if I missed one...
I have tried to answer the following questions. Please let me know if I missed one and why. 1) A light car and a heavy car are headed toward each other from opposite directions at the same speed. The ground is level. Which of the two will be harder to stop? the heavier car 2) Instead of stopping the cars, you jump out of the way. The two cars crash head-on. After the crash what do you see? The two...
Can you please code in C the Lagrangian function. If you have any questions please let...
Can you please code in C the Lagrangian function. If you have any questions please let me know.
Use the article to answer these questions. Let me know if you need more information. What...
Use the article to answer these questions. Let me know if you need more information. What question was asked? Summarize the main points of the article—what is the primary goal or aim of the described study? How was the question asked? Summarize the main methods used in the study. What did the authors find? Summarize the major results of the study. How does this article provide background information for quorum sensing in gingivitis? Some possible questions you could address…How does...
Hello! Please let me know, thank you! You have a credit card with a balance of...
Hello! Please let me know, thank you! You have a credit card with a balance of $13,600 and an APR of 18 percent compounded monthly. You have been making monthly payments of $260 per month, but you have received a substantial raise and will increase your monthly payments to $335 per month. How many months quicker will you be able to pay off the account? 37.39 Months 36.05 Months 40.06 Months 11.71 Months 34.33 Months Thank you!
Below is the only information I received for these questions. Please let me know if there...
Below is the only information I received for these questions. Please let me know if there is any additional info you may need. Any questions will help Federal Taxation I Module 8: Comprehensive Tax Return Project Jared and Ashley have come to you for help filing their 2018 tax return. They are married on December 31, 2018 and are both age 40. They live with their three qualifying children, Nick, Betty, and Roger, who are 12, 14, and 17 years...
Please answer questions based on global issues and trends in healthcare. 1. Do you know any...
Please answer questions based on global issues and trends in healthcare. 1. Do you know any children who have died from pneumonia, diarrhea, malaria, measles, or undernutrition? What does your answer or classmates’ answers indicate about global health inequalities? 2. What educational and other resources are available for children in your community who have special needs? Do you have any suggestions for improvement? 3. A growing number of American women what to give birth at home instead of at a...
Please answer questions based on global issues and trends in healthcare. 1. Do you know any...
Please answer questions based on global issues and trends in healthcare. 1. Do you know any children who have died from pneumonia, diarrhea, malaria, measles, or undernutrition? What does your answer or classmates’ answers indicate about global health inequalities? 2. What educational and other resources are available for children in your community who have special needs? Do you have any suggestions for improvement? 3. A growing number of American women what to give birth at home instead of at a...
Please let me know about the material structure and properties of Solar energy devices.
Please let me know about the material structure and properties of Solar energy devices.
Please give me a right answer please if you cant answer it let someone else solve...
Please give me a right answer please if you cant answer it let someone else solve it Margin of Safety a. If Canace Company, with a break-even point at $608,000 of sales, has actual sales of $800,000, what is the margin of safety expressed (1) in dollars and (2) as a percentage of sales? Round the percentage to the nearest whole number. 1. $ 2.   % b. If the margin of safety for Canace Company was 30%, fixed costs were...
Can someone answer these questions for me please? 1- You are tasked with teaching a child...
Can someone answer these questions for me please? 1- You are tasked with teaching a child to stop hitting other children. Using the principles of operant conditioning, devise a strategy that uses both reinforcement and punishment to prevent the child from misbehaving. What might be the possible reasons that the child learned this aggressive behaviour? What could be done to prevent it in the future?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT