SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
Introduction To Computers And C++ Programming
Exercise:
Programming Projects
Question:9 | ISBN:9780321531346 | Edition: 7

Question

Write a program that allows the user to enter a time in seconds and then outputs how far an object would drop if it is in freefall for that length of time. Assume that the object starts at rest, there is no friction or resistance from air, and there is a constant acceleration of 32 feet per second due to gravity.

Use the equation:  

                    distance = \frac{acceleration\times time^{2}}{2}

You should first compute the product and then divide the result by 2 (The reason for this will be discussed later in the book).

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

#include<iostream>
using namespace std;

#define ACCELERATION 32

int main() 
{
  //Variables
  int time;
  double distance;

  //User input
  cout<<" Enter time(Seconds):";
  cin>>time;

  //Compute distance using the formula:
  //distance=(acceleration*time^2)/2
  distance = ((ACCELERATION * time *time)/2);

  //Print output
  cout<<"Traveled distance:" << distance <<"\n";
}

Output of code:

Enter time(Seconds):15
Traveled distance:3600
0 0

Discussions

Post the discussion to improve the above solution.