Checking Answers.

So i have an assignment. I would like it it someone could write code for the criteria of each question, shits got me so confused right now.

A. The kinetic energy of a moving object is found using the following equation: K=(1/2)(MV2)
Where: K is the kinetic energy in kgm/s
M is the mass in kilograms
V is the velocity, in meters per second
Write a complete program that accepts inputs of mass and velocity of an object from the user and determines the kinetic energy. Display the mass, velocity, and kinetic energy at the end of the program. To test your program, execute the program using m=200kg, v=3.7 m/s and then execute it again using m=925kg, v=8m/s.

B. Write a complete program that will calculate the equivalent resistance from two parallel resistances entered by the user. Use the following formula to calculate the equivalent resistance. Output the two parallel resistances and the equivalent resistance at the end of the program. Test your program by executing it using R1=67.27, R2=64.5.
Requiv = (R1 * R2)/(R1 + R2)

C. Write a program that lets the user enter the magnitude of the Resultant force (R) and the angle this force makes with the x axis (Θ). The program should then calculate the rectangular x and y components of this force using:
X component = RcosΘ and Ycomponent=RsinΘ
Test your program using these values;
a. R=2000N Angle=35 degrees
b. R=500N Angle=120 degrees

D. Write a program to ask the user to enter 6 values for X. Then evaluate the following equation for each value of X. Output each X value and its corresponding Y value. Here’s the equation: Y=(9/5)X2 – (1/2)X + 2
For the first run, use X values of 11,12,13,14,15,16
For the second run, use X values of -3.6, -3.1, -2.9, -2.4, -1.8, -1.7
Last edited on
Not too sure which parts you are confused? For what I see the 4 questions are about the same.

I shall give you an example for Question A. Hope this helps for the rest of the questions.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>

using namespace std;
int main()
{
	//Question A
	double mass;		//declare the variable for mass
	double velocity;	//declare the variable for velocity
	
	cout << "Enter the Mass(kg): "; //Output message for the user
	cin >> mass; //Get input from user
	cout << "Enter the Velocity(m/s): ";//Output message for the user
	cin >> velocity; //Get input from user
	cout << "=============" << endl; //Output message for the user
	cout << "Mass: " << mass << endl;//Output message for the user, and display the mass input by the user
	cout << "Velocity: " << velocity << endl;//Output message for the user, and display the velocity input by the user
	cout << "Kinetic Energy: " << mass*velocity*velocity*0.5 << endl;//Output message for the user, and display the calculation

	system("pause");
	return 0;
}


For Question C, you will need trigo function, to do this, refer to http://www.cplusplus.com/reference/cmath/cos/?kw=cos

If you have question, do post your code, we might able to help you from there :)
More confused with this entire programming stuff. Lol, thank you
Can anyone run through the others?
Looks like you need the solution, and not willingly to try out.
Let me be kind and help you...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <math.h>
#include <vector> 

using namespace std;
#define PI 3.14159265
int main()
{
	//============ Question A ============ //
	double mass;
	double velocity;
	cout <<"=======Question A =======" << endl;
	cout << "Enter the Mass(kg): ";
	cin >> mass;
	cout << "Enter the Velocity(m/s): ";
	cin >> velocity;
	cout << "-----------------" << endl; 
	cout << "Mass: " << mass << endl;
	cout << "Velocity: " << velocity << endl;
	cout << "Kinetic Energy: " << mass*velocity*velocity*0.5 << endl;
	cout << "\n";


	//============ Question B ============ //
	double resist1, resist2;
	cout <<"=======Question B =======" << endl;
	cout << "Enter the Resistances: ";
	cin >> resist1;
	cout << "Enter the Resistances: ";
	cin >> resist2;
	cout << "-----------------" << endl;
	cout << "Equivalent resistance: " << resist1*resist2 << endl;
	cout << "\n";


	//============ Question C ============ //
	double resultFore, angle;
	cout <<"=======Question C =======" << endl;
	cout << "Enter the  Resultant force: ";
	cin >> resultFore;
	cout << "Enter the Angle of the force: ";
	cin >> angle;
	cout << "-----------------" << endl;
	cout << "X component: " << resultFore*cos(angle*180/PI) << endl; 
	cout << "Y component: " << resultFore*sin(angle*180/PI) << endl;
	//Note: For the cosine and sine function, the angle is in radian. 
	//		So you will need to change to degree
	cout << "\n";


	//============ Question D ============ //
	cout <<"=======Question D =======" << endl;
	vector<double> x;
	vector<double> y;
	double valueX;

	for (int i = 0; i < 6; i++)
	{
		cout<<"Enter the value_" << i << ": "; 
		cin >> valueX;
		x.push_back(valueX);
	}
	for(int i = 0; i < 6; i++)
		cout<< "Corresponding Y: " << 9*pow(x.at(i),2)/5 - 0.5*x.at(i) + 2 << endl;
	cout << "\n";
	system("pause");
	return 0;
}
Last edited on
Thanks a lot, now I have an issue with decimals, for example

#include<iostream>
#include<math.h>
using namespace std;
float A;
float B;
float C;
float D;

int main()
{
int A;
int B;
int C;
int D;

cout<<"Enter a number for A";
cin>>A;
cout<<"Enter a number for B";
cin>>B;
cout<<"Enter a number for C";
cin>>C;
cout<<"Enter a number for D";
cin>>D;

cout<<"When your numbers are applied to the formula you get ";
cout<< A*(B+C)-pow(D,3)<<" ";
//spaces are to pretty it up
system("pause");
}
when i enter 7.3 for A it gives me an error
I think you post at the wrong place :)))

The reason there is an error is because you declare A, B, C and D as integer. inside the int main() .

Since you declare A, B, C and D outside as float, you can delete int A; int B; int C; int D; inside the the int main() .

Is float the command im looking for? because it works fine minus decimals prior to me inserting the float.
float works fine in this case. You will need to remove int and use float.
Topic archived. No new replies allowed.