Setting up the Programming Environment 1. At the Linux command line type mkdir l
ID: 3840984 • Letter: S
Question
Setting up the Programming Environment
1. At the Linux command line type mkdir lab1. This will create a new directory named
lab1. Work out of this directory. In order to do that, type cd lab1. This changes the
current working directory to the directory lab1.
2. If you have created the directory lab1, then just type cd lab1.
3. Copy the file fallMoon.exe in the directory /class/cse1222/5059/lab1 by
typing
cp /class/cse1222/5059/lab1/fallMoon.exe .
Be sure to include 5059 (this is your course section indicator) and the period, “.”.
4. Copy the file projectileDist.exe in the directory /class/cse1222/5059/lab1
by typing
cp /class/cse1222/5059/lab1/projectileDist.exe .
Be sure to include 5059 (this is your course section indicator) and the period, “.”.
Programming Assignment
1. Create a new file fallMoon.cpp which will contain a program to compute the falling
distance and velocity on the moon. The program should read in the time in seconds. The
formula for the velocity after t seconds is:
velocity = g * t
where g = 1.6 meters per second^2 and t is the time in seconds. The formula for the distance
after t seconds is:
distance = (1/2) * velocity * t
Explanation / Answer
Code:
// fallMoon.cpp - to calculate falling distance and velocity on the moon
#include <iostream>
using namespace std;
int main()
{
// declaraing variables
double time, velocity, distance;
// Taking time as input from user
cout << "Enter the time in seconds: ";
cin >> time;
// calculating velocity & distance
velocity = 1.6 * time;
distance = 0.5 * velocity * time;
// Displaying the results
cout << "Falling distance is: " << distance << endl;
cout << "Velocity on the moon is: " << velocity << endl;
return 0;
}
Execution and output:
Enter the time in seconds: 30
Falling distance is: 720
Velocity on the moon is: 48
Enter the time in seconds: 12.5
Falling distance is: 125
Velocity on the moon is: 20
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.