5 Functions 5. Falling Distance to When an object is falling because of gravity,
ID: 3678321 • Letter: 5
Question
5 Functions 5. Falling Distance to When an object is falling because of gravity, the following formula can be use determine the distance the object falls in a specific time period: 2gt t The variables in the formula are as follows: d is the distance in meters, g is 9.8, and is the amount of time, in seconds, that the object has been falling. (in Write a function named fallingDistance that falling that the seconds) as an argument. The function should return the distance, in meters, the object has fallen during that time interval. Write a program that demonstrates and function by calling it in a loop passes the values 1 through 10 as arguments displays the return valueExplanation / Answer
#include<iostream>
using namespace std;
int fallingDistance(int time)
{
float g=9.8;
//calculating distance in meters using d=1/2gt2 formula
float d=1/2*g*(time*time)
return d;
cout<<d;
}
int main()
{
int i;
i=1;
while(i<=10)
{
fallingDistance(i);
i++;
}
return 0;
}
2)
#include<iostream>;
using namespace std;
//function asks number of employees and return the value
int numOfEmp()
{
int n1;
cout<<"Enter Number of the employees";
cin>>n1;
return n1;
}//method
/*function take number of emp as parameter and count total number of holidays of all employees and return the value*/
int empHolidays(int h)
{
int i,h1,total;
total=0;
for(i=1;i<=h;i++)
{
cout<<"Enter Employee"<<h<<"Holidays";
cin>>h1;
//calculating total number of holidays
total=total+h1;
}
return total;
}
/*avgHolidays is function takes two parameters as number of employess e and t total holidays of e employees and calculate average using t/e*/
double avgHolidays(int e,int t)
{
double avg1=t/e;
return avg1;
}
int main()
{
int n,d;
double avg;
n = numOfEmp();
d= empHolidays(n);
avg= avgHolidays(n,d);
cout<< "The average of employee number of days absent"<<avg;
return 0;
}//main
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.