Can i get help write this program in C++ using modules (functions) that return a
ID: 664067 • Letter: C
Question
Can i get help write this program in C++ using modules (functions) that return a boolean and string module?
In physics, an object that is in motion is said to have kinetic energy. The following formula can be used to determine a moving object’s kinetic energy:
KE = 1/2 *mv^2
The variables in the formula are as follows: KE is the kinetic energy, m is the object’s mass in kilograms, and v is the object’s velocity, in meters per second.
Design a function named kineticEnergy that accepts an object’s mass (in kilograms) and velocity (in meters per second) as arguments. The function should return the amount of kinetic energy that the object has. Design a program that asks the user to enter values for mass and velocity, and then calls the kineticEnergy function to get the object’s kinetic energy.
Can i get help write this program in C++ using modules (functions) that return a boolean and string module? I tried to write the pseudocode below
Function Real KineticEnergy(Real mass, Real vel)
//Declare the variables
Declare Real KEnergy, velSquare
//Calculate square of velocity and store it to velSquare
set velSquare = pow(vel, 2)
//Calculate kinetic energy and store it to kEnergy
set kEnergy = (mass * velSquare) / 2
// Return kinetic energy of the moving object
Return kEnergy
End Function
Module main()
//Declare the variables
Declare Real m, v, ke
//Read the mass and velocity of the object and keep them in m and v respectively
Display "Please enter the value for mass."
input m
Display "Please enter the value of velocity."
input v
//Calculate kinetic energy by using function
//kineticEnergy and store the result in ke
Set ke = kineticEnergy(m,v)
//Display ke
Display "Kinetic energy of the object is ", ke, "."
End Module
Explanation / Answer
// Includes
#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;
// Prototypes
double kineticEnergy(double mass , double meters);
double getKE();
// Main Function
int main()
{
double mass , meters , KE , Energy;
cout << "This will calculate how much kinetic energy an object has. ";
cout.setf(ios_base::fixed , ios_base::floatfield);
cout.precision(2);
KE = getKE();
Energy = kineticEnergy(mass , meters);
cout << "The object with a mass weight and velocity of " << Energy << " kilograms and meters." << KE << endl;
_getch();
return 0;
}
// Get Kinetic Energy Function
double getKE()
{
double mass , meters;
cout << "Enter the objects weight in kilograms: ";
cin >> mass;
cout << "Enter the objects velocity in meters: ";
cin >> meters;
cout << " ";
return mass;
return meters;
}
// Kinetic Energy Function
double kineticEnergy(double mass , double meters)
{
return (1.0 / 2.0) * (mass * meters) * 2;
}