(C ++) Problem 1: The Figure shows a mass, m, on a frictionless surface. The mas
ID: 639456 • Letter: #
Question
(C ++)
Problem 1: The Figure shows a mass, m, on a frictionless surface. The mass is connected to two walls by springs, which have stiffness values K1 and K2. The natural period of the mass-spring system is given by:
Write a program that asks the user for the mass and the spring stiffness values so that you can calculate the period of movement, T. Use the following value of pi = 3.1416 in the program. Use your V_mass as the variable for mass. Test the program with the value of m = 50 kg, K1 =2 and K2=5. Show the output, T_period with 2 decimal places and also show the output, T_period, in scientific notation with 3 decimal places.
(General Preprocessing items #1: Use mnemonic variables of 3 characters or more. Use void main (void) or void main ( ) in your program. Use printf, scanf if needed. DO NOT USE COUT.
General Preprocessing items #2: Watch for instructions that specify a symbolic constant and assign that symbolic constant in all capital letters and using the #define.
The ?xxxxx? in a sample output will show locations that the computer program will transfer values. )
Sample Output :
Enter the mass in kg: xxxxx
Enter the stiffness value for the first spring: xxxxx
Enter the stiffness value for the second spring: xxxxx
**Results Section**
The period of movement (T) for the entered values = xxxxx
The period in scientific notation is: xxxxx
Press any key to continue
mmass K_spring, +K_springz T-period = 2 Ki K2Explanation / Answer
#include<iostream>
#include<cmath>
#include<cstdio>
#define PI 3.14
using namespace std;
int main()
{
double v_mass,k1,k2,T_period;
printf("Enter the mass in kg: ");
scanf("%lf",&v_mass);
printf(" Enter the stiffness value for the first spring: ");
scanf("%lf",&k1);
printf(" Enter the stiffness value for the second spring: ");
scanf("%lf",&k2);
T_period=2*PI*sqrt(v_mass/(k1+k2));
printf(" **Results Section** ");
printf(" The period of movement (T) for the entered values = %.2f",T_period);
printf(" The period in scientific notation is: %.3f",T_period);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.