Hello World!

Fall 2013 CS 1400: Introduction to C++ – My very first programming class

This is included here for nostalgia purposes 🙂

An industrious USU freshman wishes to conduct an ad hoc experiment wherein a 0.065 Kg raw egg is to be launched over the top of Old Main Hall using a slingshot with ideal elastics and delivered to an otherwise preoccupied professor travelling across the quad.  

The mass of the egg, the elastic constant, and the gravitational constant are all known.   Given a value for D (the distance to the professor in meters) and the value for theta (the angle of elevation in degrees), what distance X (the draw length in meters) should be elastic be stretched to in order to correctly deliver the egg to the indicated destination?  

A hint is cleverly hidden somewhere in the diagram that may be helpful for you when calculating a solution for X.

For this assignment, you are to write a program to ask the user for two floats, D and theta (in that order), and then prints out the correct value for X.  An example of what the program might look like to the user is:

        Distance to professor (meters): 100
        Angle of elevation (theta, in degrees): 60
        You need to pull back 1.71528 meters

Don’t forget that the sin() function in the cmath library takes radians — not degrees.

What to turn in:  a single .cpp file with your code in it.  Include in the comments your name and section number.  We’ll run your programs in batch, so do not change the order in which the inputs are collected, or request any additional information.

For an additional extra credit point please answer: What is the air speed velocity of an unladen swallow?

// Austin Derbique
// A01967241
// CS 1400 9/3/13

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	double mass, gravity, elasticity, angle, theta, distance, x;

	mass = .065; //in Kg
	gravity = 9.8; //in m/s^2
	elasticity = 25; //in nm

	cout << "Distance to professor (meters):";
	cin >> distance;

	cout << "Angle of elevation (theta, in degrees):";
	cin >> angle;

	theta = angle * .0174532925; //conversion for 1 degree to radians
	x = sqrt((mass * gravity * distance)/(elasticity * (sin (2 * theta))));
	cout << "You need to pull back " << x << " meters." << endl;
	cout << "An unladen European Swallow is roughly 11 meters per second, or 24 miles an hour."; 
	return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.