Question #11726

the acceleration of a sleigh sliding down a hill is a=g sin (a), where a is the slope of the hill and the gravity acceleration g=9.8 m/s2.
a) write a c++ function that calculates the acceleration as a function of the slope a in degrees.
b)write a c++ program that reads the slope and length of the hill as inputs,and calculates how long time it takes to slide down the hill.

Expert's answer

a) write a c++ function that calculates the acceleration as a function of the slope a in degrees.

double acc(double a){

return 9.8*sin(a);

}

b)write a c++ program that reads the slope and length of the hill as inputs, and calculates how long time it takes to slide down the hill.

# include<iostream.h>

# include<conio.h>

# include<math.h>

double a, l;

double time(double a, double l){

return sqrt(2*l/a);

}

void main(){

cout<<"Enter the length of the hill (in meters): ";

cin>>l;

cout<<"Enter the slope of the hill (in degrees): ";

cin>>a;

cout<<"It takes "<<time(a, l)<< " seconds to slide down the hill.\r\n";

getch();

}

## Comments

## Leave a comment