Computer Science 1620 Math Library. Remember this program? suppose that I invest $25000 into a mutual fund that returns 8% per year. Write a program to.

Slides:



Advertisements
Similar presentations
Lecture Computer Science I - Martin Hardwick Recursion rA recursive function must have at least two parts l A part that solves a simple case of the.
Advertisements

Lecture Computer Science I - Martin Hardwick Strings #include using namespace std; int main () { string word; cout
For(int i = 1; i
CPSC 441 TUTORIAL – JANUARY 16, 2012 TA: MARYAM ELAHI INTRODUCTION TO C.
PHYS707: Special Topics C++ Lectures Lecture 3. Summary of Today’s lecture: 1.Functions (call-by-referencing) 2.Arrays 3.Pointers 4.More Arrays! 5.More.
Pass by Value. COMP104 Pass by Value / Slide 2 Passing Parameters by Value * A function returns a single result (assuming the function is not a void function)
Chapter 16 Exception Handling. What is Exception Handling? A method of handling errors that informs the user of the problem and prevents the program from.
Vectors, lists and queues
Computer Science 1620 Function Overloading. Review Question: suppose I have the following function: can I call this function with an integer? yes – compiler.
1 Lecture 16:User-Definded function I Introduction to Computer Science Spring 2006.
Chapter 6 Advanced Function Features Pass by Value Pass by Reference Const parameters Overloaded functions.
Functions Prototypes, parameter passing, return values, activation frams.
Problem You require an algorithm that will receive the length of the hypotenuse and one of the sides of a right triangle, and calculate the length of the.
ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne
Derived data types Dealing with data –Where the information is stored –What value is kept there –What kind of information is stored Address operator Pointers.
Exercise 2.
Data Structures (Second Part) Lecture 2 : Pointers Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 102 Computer Programming II (Lab:
第三次小考. #include using namespace std; int aaa(int *ib,int a1,int a2) { int u,v; int m=(a1+a2)/2; if(a1==a2)return ib[a1]; u=aaa(ib,a1,m); cout
Tinaliah, S. Kom.. * * * * * * * * * * * * * * * * * #include using namespace std; void main () { for (int i = 1; i
Triana Elizabeth, S.Kom. #include using namespace std; void main () { for (int i = 1; i
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 3.
Computer Science 1620 Default Parameter Values. Default Parameters If a projectile is launched vertically with velocity v 0, the maximum height it will.
Computer Science 1620 Variables and Memory. Review Examples: write a program that calculates and displays the average of the numbers 45, 69, and 106.
Computer Science 1620 Arithmetic. C++ Math we have seen how to use numbers in our program to represent data however, we can also manipulate this data.
Writing and Testing Programs Drivers and Stubs Supplement to text.
1 Lab Session-IV CSIT121 Fall 2000 Some Questions Scope of Variables Top Down Design Problem The Solution Lab Exercises Lab Exercise for Demo.
Computer Science 1620 Accumulators. Recall the solution to our financial program: #include using namespace std; int main() { double balance = ;
Computer Science 1620 Function Scope & Global Variables.
Computer Science 1620 Programming & Problem Solving.
1 Lecture 14:User-Definded function I Introduction to Computer Science Spring 2006.
1 CS150 Introduction to Computer Science 1 Exponents & Output page & Section 3.8.
1 9/26/07CS150 Introduction to Computer Science 1 Exponents & Output page & Section 3.8.
Computer Science 1620 Selection Structures. Write a program that accepts the speed of a vehicle, and determines whether that person is speeding assume.
Programming is instructing a computer to perform a task for you with the help of a programming language.
Functions Pass by Reference Alina Solovyova-Vincent Department of Computer Science & Engineering University of Nevada, Reno Fall 2005.
COMPUTER PROGRAMMING. Functions What is a function? A function is a group of statements that is executed when it is called from some point of the program.
Current Assignments Homework 3 is due tonight. Iteration and basic functions. Exam 1 on Monday.
First steps Jordi Cortadella Department of Computer Science.
Computer Science 1620 boolean. Types so far: Integer char, short, int, long Floating Point float, double, long double String sequence of chars.
111/15/2015CS150 Introduction to Computer Science 1 Summary  Exam: Friday, October 17,  Assignment: Wednesday, October 15, 2003  We have completed.
Tracing through E01, question 9 – step 1 // p02.cc P. Conrad, for CISC181 07S // Exam question for E01 #include using namespace std; void mysteryFunction(int.
1 Original Source : and Problem and Problem Solving.ppt.
1 10/18/04CS150 Introduction to Computer Science 1 Functions Divide and Conquer.
Exceptions in C++. Exceptions  Exceptions provide a way to handle the errors generated by our programs by transferring control to functions called handlers.
Functions Jordi Cortadella Department of Computer Science.
Intro. to Computer Programming Eng. Nehal A. Mohamed Spring Semester-2016.
General Computer Science for Engineers CISC 106 Lecture 27 Dr. John Cavazos Computer and Information Sciences 04/27/2009.
1 09/10/04CS150 Introduction to Computer Science 1 What Actions Do We Have Part 2.
Learning and remembering.
LESSON 5 Loop Control Structure. Loop Control Structure  Operation made over and over again.  Iterate statement.
#define #include<iostream> using namespace std; #define GO
Expected Returns The market and Stock S have the following probability distributions Probability Km Ks % 20% % 5% % 12% Calculate.
Introduction to C++ Programming Language
Intro to Programming Week # 6 Repetition Structure Lecture # 10
Object Oriented Programming Mansoor Ahmed Bughio
Calculation of Present Value
Random Number Generation
Starting Out with C++: From Control Structures through Objects
Pointers & Functions.
Code::Block vs Visual C++
Functions Divide and Conquer
Unit 3 Review (Calculator)
Arithmetic Operations
Pointers & Functions.
Functions Divide and Conquer
Programming Strings.
Calculate 9 x 81 = x 3 3 x 3 x 3 x 3 3 x 3 x 3 x 3 x 3 x 3 x =
Reading from and Writing to Files Part 2
Introduction to Algorithms and Programming COMP151
Presentation transcript:

Computer Science 1620 Math Library

Remember this program? suppose that I invest $25000 into a mutual fund that returns 8% per year. Write a program to calculate how much the fund will be worth after a) one year, b) two years c) three years

Suppose that I invest $25000 into a mutual fund that returns 8% per year. Write a program to calculate how much the fund will be worth after a) one year, b) two years c) three years #include using namespace std; int main() { cout << "Year 1: $" << * 1.08 << endl; cout << "Year 2: $" << * 1.08 * 1.08 << endl; cout << "Year 3: $" << * 1.08 * 1.08 * 1.08 << endl; return 0; }

Suppose that I invest $25000 into a mutual fund that returns 8% per year. Write a program to calculate how much the fund will be worth after a) one year, b) two years c) three years #include using namespace std; int main() { double balance = ; balance = balance * 1.08; cout << "Year 1: $" << balance << endl; balance = balance * 1.08; cout << "Year 2: $" << balance << endl; balance = balance * 1.08; cout << "Year 3: $" << balance << endl; return 0; }

Suppose that I invest $25000 into a mutual fund that returns 8% per year. Write a program to calculate how much the fund will be worth after a) one year, b) two years c) three years #include using namespace std; int main() { cout << fixed << showpoint << setprecision(2); cout << "Year 1: $" << * 1.08 << endl; cout << "Year 2: $" << * 1.08 * 1.08 << endl; cout << "Year 3: $" << * 1.08 * 1.08 * 1.08 << endl; return 0; }

Suppose that I invest $25000 into a mutual fund that returns 8% per year. Write a program to calculate how much the fund will be worth after a) one year, b) two years c) three years #include using namespace std; int main() { double balance = ; cout << fixed << showpoint << setprecision(2); balance = balance * 1.08; cout << "Year 1: $" << balance << endl; balance = balance * 1.08; cout << "Year 2: $" << balance << endl; balance = balance * 1.08; cout << "Year 3: $" << balance << endl; return 0; }

Suppose we alter the program? suppose that I invest $25000 into a mutual fund that returns 8% per year. Write a program to calculate how much the fund will be worth after a) ten years, b) twenty years c) thirty years

Suppose that I invest $25000 into a mutual fund that returns 8% per year. Write a program to calculate how much the fund will be worth after a) ten years, b) twenty years c) thirty years #include using namespace std; int main() { cout << fixed << showpoint << setprecision(2); cout << "Year 1: $" << * 1.08 << endl; cout << "Year 2: $" << * 1.08 * 1.08 << endl; cout << "Year 3: $" << * 1.08 * 1.08 * 1.08 << endl; return 0; }

Suppose that I invest $25000 into a mutual fund that returns 8% per year. Write a program to calculate how much the fund will be worth after a) ten years, b) twenty years c) thirty years #include using namespace std; int main() { cout << fixed << showpoint << setprecision(2); cout << "Year 1: $" << * 1.08 << endl; cout << "Year 2: $" << * 1.08 * 1.08 << endl; cout << "Year 3: $" << * 1.08 * 1.08 * 1.08 << endl; return 0; }

Suppose that I invest $25000 into a mutual fund that returns 8% per year. Write a program to calculate how much the fund will be worth after a) ten years, b) twenty years c) thirty years #include using namespace std; int main() { cout << fixed << showpoint << setprecision(2); cout << "Year 10: $" << * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 << endl; cout << "Year 2: $" << * 1.08 * 1.08 << endl; cout << "Year 3: $" << * 1.08 * 1.08 * 1.08 << endl; return 0; }

Suppose that I invest $25000 into a mutual fund that returns 8% per year. Write a program to calculate how much the fund will be worth after a) ten years, b) twenty years c) thirty years #include using namespace std; int main() { cout << fixed << showpoint << setprecision(2); cout << "Year 10: $" << * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 << endl; cout << "Year 20: $" << * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 << endl; cout << "Year 30: $" << * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 << endl; return 0; }

Suppose that I invest $25000 into a mutual fund that returns 8% per year. Write a program to calculate how much the fund will be worth after a) ten years, b) twenty years c) thirty years #include using namespace std; int main() { double balance = ; cout << fixed << showpoint << setprecision(2); balance = balance * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08; cout << "Year 10: $" << balance << endl; balance = balance * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08; cout << "Year 20: $" << balance << endl; balance = balance * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08; cout << "Year 30: $" << balance << endl; return 0; }

The previous example worked, but … to calculate required that we manually type in thirty multiplications suppose we had wanted to know the balance after 100 years?

pow(b,e) to compute b raised to the power of e, one can use the pow function syntax: the pow statement itself is an expression value: the first expression raised to the power of the second expression pow(, ) numeric expression numeric expression

Example: #include using namespace std; int main() { cout << pow(3.0, 3.0) << endl; cout << pow(3, 4.0) << endl; cout << pow(4.0, 3) << endl; int x = 5; double y = 6.0; cout << pow(x, y) << endl; cout << pow(x, y) + pow(3.0, 3.0) << endl; cout << pow( pow(x, y), pow(3.0, 3.0) ) << endl; return 0; }

A note about pow you cannot send it two integer expressions cout << pow(3, 4) << endl; // compiler error this has to do with function overloading we will examine functions later for now, just know that one expression has to be a floating point type

The cmath library FunctionDescription abs(x)Returns the absolute value of x pow(x, y)Returns x y sqrt(x)Returns the square root of x sin(x)Returns the sine of x cos(x)Returns the cosine of x tan(x)Returns the tangent of x log(x)Returns the natural logarithm of x ln x log10(x)Returns log 10 x exp(x)Returns e x floor(x)Returns the closest whole number < x ceil(x)Returns the closest whole number > x

A Note about Types when using a math function (from previous slide), the type of the expression is the same as the type of the input expression, with some exceptions: an integer expression is converted to a double for the pow function, the type of the expression is the largest of the base and exponent expressions for abs integers are not converted to doubles shorts and chars are converted to ints

ExpressionType sqrt(2.0)double sin(2.0f)float cos(2)double log( f)float exp(2) + exp(2.0)double abs(75);int floor(3.5);double

A Note about the Trig Functions the input expression is considered to be radians hence, sin(30.0) = , not 0.5 to convert radians to degrees, multiply the value by (π / 180)

Example: #include using namespace std; int main() { const double PI = ; cout << sin(30) << endl; cout << sin(30 * PI / 180) << endl; return 0; }

Back to our previous example suppose that I invest $25000 into a mutual fund that returns 8% per year. Write a program to calculate how much the fund will be worth after a) ten years, b) twenty years c) thirty years

Suppose that I invest $25000 into a mutual fund that returns 8% per year. Write a program to calculate how much the fund will be worth after a) ten years, b) twenty years c) thirty years #include using namespace std; int main() { cout << fixed << showpoint << setprecision(2); cout << "Year 10: $" << * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 << endl; cout << "Year 20: $" << * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 << endl; cout << "Year 30: $" << * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 << endl; return 0; }

Suppose that I invest $25000 into a mutual fund that returns 8% per year. Write a program to calculate how much the fund will be worth after a) ten years, b) twenty years c) thirty years #include using namespace std; int main() { cout << fixed << showpoint << setprecision(2); cout << "Year 10: $" << * pow(1.08, 10) << endl; cout << "Year 10: $" << * pow(1.08, 20) << endl; cout << "Year 10: $" << * pow(1.08, 30) << endl; return 0; }

Suppose that I invest $25000 into a mutual fund that returns 8% per year. Write a program to calculate how much the fund will be worth after a) ten years, b) twenty years c) thirty years #include using namespace std; int main() { double balance = ; cout << fixed << showpoint << setprecision(2); balance = balance * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08; cout << "Year 10: $" << balance << endl; balance = balance * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08; cout << "Year 20: $" << balance << endl; balance = balance * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08 * 1.08; cout << "Year 30: $" << balance << endl; return 0; }

Suppose that I invest $25000 into a mutual fund that returns 8% per year. Write a program to calculate how much the fund will be worth after a) ten years, b) twenty years c) thirty years #include using namespace std; int main() { double balance = ; cout << fixed << showpoint << setprecision(2); balance = balance * pow(1.08, 10); cout << "Year 10: $" << balance << endl; balance = balance * pow(1.08, 10); cout << "Year 20: $" << balance << endl; balance = balance * pow(1.08, 10); cout << "Year 30: $" << balance << endl; return 0; }

Suppose that I invest $25000 into a mutual fund that returns 8% per year. Write a program to calculate how much the fund will be worth after a) ten years, b) twenty years c) thirty years #include using namespace std; int main() { double balance = ; double increase = pow(1.08, 10); cout << fixed << showpoint << setprecision(2); balance = balance * increase; cout << "Year 10: $" << balance << endl; balance = balance * increase; cout << "Year 20: $" << balance << endl; balance = balance * increase; cout << "Year 30: $" << balance << endl; return 0; }

Example 2: Suppose you have a cannon. Given an initial velocity of a cannonball and the angle of the cannon θ, output (1) the time that the ball remains in the air and (2) the maximum height of its trajectory

Arithmetic Data and Operators Given a value θ and initial velocity v 0, we can calculate the time that the ball stays in the air: and its maximum height: g is approximately m/s at sea level

Write a program that accepts an initial velocity and the angle of trajectory, and computes the hangtime and the maximum height of the cannonball. Output to three decimal places. #include using namespace std; int main() { const double PI = ; const double G = -9.81; double v0; cout << "Initial velocity (m/s): "; cin >> v0; double theta; cout << "Angle of trajectory (degrees): "; cin >> theta; theta = theta * PI / 180.0; double time = -2 * v0 * sin(theta) / G; double height = -pow(v0 * sin(theta), 2) / (2 * G); cout << fixed << showpoint << setprecision(2); cout << "Hangtime (s): " << time << endl; cout << "Height (m): " << height << endl; return 0; }

Write a program that accepts an initial velocity and the angle of trajectory, and computes the hangtime and the maximum height of the cannonball. Output to three decimal places. #include using namespace std; int main() { const double PI = ; const double G = -9.81; double v0; cout << "Initial velocity (m/s): "; cin >> v0; double theta; cout << "Angle of trajectory (degrees): "; cin >> theta; theta = theta * PI / 180.0; double time = -2 * v0 * sin(theta) / G; double height = -pow(v0 * sin(theta), 2) / (2 * G); cout << fixed << showpoint << setprecision(2); cout << "Hangtime (s): " << time << endl; cout << "Height (m): " << height << endl; return 0; }

Write a program that accepts an initial velocity and the angle of trajectory, and computes the hangtime and the maximum height of the cannonball. Output to three decimal places. #include using namespace std; int main() { const double PI = ; const double G = -9.81; double v0; cout << "Initial velocity (m/s): "; cin >> v0; double theta; cout << "Angle of trajectory (degrees): "; cin >> theta; theta = theta * PI / 180.0; double time = -2 * v0 * sin(theta) / G; double height = -pow(v0 * sin(theta), 2) / (2 * G); cout << fixed << showpoint << setprecision(2); cout << "Hangtime (s): " << time << endl; cout << "Height (m): " << height << endl; return 0; }

Write a program that accepts an initial velocity and the angle of trajectory, and computes the hangtime and the maximum height of the cannonball. Output to three decimal places. #include using namespace std; int main() { const double PI = ; const double G = -9.81; double v0; cout << "Initial velocity (m/s): "; cin >> v0; double theta; cout << "Angle of trajectory (degrees): "; cin >> theta; theta = theta * PI / 180.0; double time = -2 * v0 * sin(theta) / G; double height = -pow(v0 * sin(theta), 2) / (2 * G); cout << fixed << showpoint << setprecision(2); cout << "Hangtime (s): " << time << endl; cout << "Height (m): " << height << endl; return 0; }

Write a program that accepts an initial velocity and the angle of trajectory, and computes the hangtime and the maximum height of the cannonball. Output to three decimal places. #include using namespace std; int main() { const double PI = ; const double G = -9.81; double v0; cout << "Initial velocity (m/s): "; cin >> v0; double theta; cout << "Angle of trajectory (degrees): "; cin >> theta; theta = theta * PI / 180.0; double time = -2 * v0 * sin(theta) / G; double height = -pow(v0 * sin(theta), 2) / (2 * G); cout << fixed << showpoint << setprecision(2); cout << "Hangtime (s): " << time << endl; cout << "Height (m): " << height << endl; return 0; }

Write a program that accepts an initial velocity and the angle of trajectory, and computes the hangtime and the maximum height of the cannonball. Output to three decimal places. #include using namespace std; int main() { const double PI = ; const double G = -9.81; double v0; cout << "Initial velocity (m/s): "; cin >> v0; double theta; cout << "Angle of trajectory (degrees): "; cin >> theta; theta = theta * PI / 180.0; double time = -2 * v0 * sin(theta) / G; double height = -pow(v0 * sin(theta), 2) / (2 * G); cout << fixed << showpoint << setprecision(2); cout << "Hangtime (s): " << time << endl; cout << "Height (m): " << height << endl; return 0; }

Write a program that accepts an initial velocity and the angle of trajectory, and computes the hangtime and the maximum height of the cannonball. Output to three decimal places. #include using namespace std; int main() { const double PI = ; const double G = -9.81; double v0; cout << "Initial velocity (m/s): "; cin >> v0; double theta; cout << "Angle of trajectory (degrees): "; cin >> theta; theta = theta * PI / 180.0; double time = -2 * v0 * sin(theta) / -9.81; double height = -pow(v0 * sin(theta), 2) / (2 * G); cout << fixed << showpoint << setprecision(2); cout << "Hangtime (s): " << time << endl; cout << "Height (m): " << height << endl; return 0; } cmath call

Write a program that accepts an initial velocity and the angle of trajectory, and computes the hangtime and the maximum height of the cannonball. Output to three decimal places. #include using namespace std; int main() { const double PI = ; const double G = -9.81; double v0; cout << "Initial velocity (m/s): "; cin >> v0; double theta; cout << "Angle of trajectory (degrees): "; cin >> theta; theta = theta * PI / 180.0; double time = -2 * v0 * sin(theta) / -9.81; double height = -pow(v0 * sin(theta), 2) / (2 * G); cout << fixed << showpoint << setprecision(2); cout << "Hangtime (s): " << time << endl; cout << "Height (m): " << height << endl; return 0; } Magic Number

Write a program that accepts an initial velocity and the angle of trajectory, and computes the hangtime and the maximum height of the cannonball. Output to three decimal places. #include using namespace std; int main() { const double PI = ; const double G = -9.81; double v0; cout << "Initial velocity (m/s): "; cin >> v0; double theta; cout << "Angle of trajectory (degrees): "; cin >> theta; theta = theta * PI / 180.0; double time = -2 * v0 * sin(theta) / G; double height = -pow(v0 * sin(theta), 2) / (2 * G); cout << fixed << showpoint << setprecision(2); cout << "Hangtime (s): " << time << endl; cout << "Height (m): " << height << endl; return 0; } Expects radians

Write a program that accepts an initial velocity and the angle of trajectory, and computes the hangtime and the maximum height of the cannonball. Output to three decimal places. #include using namespace std; int main() { const double PI = ; const double G = -9.81; double v0; cout << "Initial velocity (m/s): "; cin >> v0; double theta; cout << "Angle of trajectory (degrees): "; cin >> theta; theta = theta * / 180.0; double time = -2 * v0 * sin(theta) / G; double height = -pow(v0 * sin(theta), 2) / (2 * G); cout << fixed << showpoint << setprecision(2); cout << "Hangtime (s): " << time << endl; cout << "Height (m): " << height << endl; return 0; } Magic Number

Write a program that accepts an initial velocity and the angle of trajectory, and computes the hangtime and the maximum height of the cannonball. Output to three decimal places. #include using namespace std; int main() { const double PI = ; const double G = -9.81; double v0; cout << "Initial velocity (m/s): "; cin >> v0; double theta; cout << "Angle of trajectory (degrees): "; cin >> theta; theta = theta * PI / 180.0; double time = -2 * v0 * sin(theta) / G; double height = -pow(v0 * sin(theta), 2) / (2 * G); cout << fixed << showpoint << setprecision(2); cout << "Hangtime (s): " << time << endl; cout << "Height (m): " << height << endl; return 0; }

Write a program that accepts an initial velocity and the angle of trajectory, and computes the hangtime and the maximum height of the cannonball. Output to three decimal places. #include using namespace std; int main() { const double PI = ; const double G = -9.81; double v0; cout << "Initial velocity (m/s): "; cin >> v0; double theta; cout << "Angle of trajectory (degrees): "; cin >> theta; theta = theta * PI / 180.0; double time = -2 * v0 * sin(theta) / G; double height = -pow(v0 * sin(theta), 2) / (2 * G); cout << fixed << showpoint << setprecision(2); cout << "Hangtime (s): " << time << endl; cout << "Height (m): " << height << endl; return 0; }

Write a program that accepts an initial velocity and the angle of trajectory, and computes the hangtime and the maximum height of the cannonball. Output to three decimal places. #include using namespace std; int main() { const double PI = ; const double G = -9.81; double v0; cout << "Initial velocity (m/s): "; cin >> v0; double theta; cout << "Angle of trajectory (degrees): "; cin >> theta; theta = theta * PI / 180.0; double time = -2 * v0 * sin(theta) / G; double height = -pow(v0 * sin(theta), 2) / (2 * G); cout << fixed << showpoint << setprecision(2); cout << "Hangtime (s): " << time << endl; cout << "Height (m): " << height << endl; return 0; }

Write a program that accepts an initial velocity and the angle of trajectory, and computes the hangtime and the maximum height of the cannonball. Output to three decimal places. #include using namespace std; int main() { const double PI = ; const double G = -9.81; double v0; cout << "Initial velocity (m/s): "; cin >> v0; double theta; cout << "Angle of trajectory (degrees): "; cin >> theta; theta = theta * PI / 180.0; double time = -2 * v0 * sin(theta) / G; double height = -pow(v0 * sin(theta), 2) / (2 * G); cout << fixed << showpoint << setprecision(2); cout << "Hangtime (s): " << time << endl; cout << "Height (m): " << height << endl; return 0; }

Write a program that accepts an initial velocity and the angle of trajectory, and computes the hangtime and the maximum height of the cannonball. Output to three decimal places. #include using namespace std; int main() { const double PI = ; const double G = -9.81; double v0; cout << "Initial velocity (m/s): "; cin >> v0; double theta; cout << "Angle of trajectory (degrees): "; cin >> theta; theta = theta * PI / 180.0; double time = -2 * v0 * sin(theta) / G; double height = -pow(v0 * sin(theta), 2) / (2 * G); cout << fixed << showpoint << setprecision(2); cout << "Hangtime (s): " << time << endl; cout << "Height (m): " << height << endl; return 0; }

Write a program that accepts an initial velocity and the angle of trajectory, and computes the hangtime and the maximum height of the cannonball. Output to three decimal places. #include using namespace std; int main() { const double PI = ; const double G = -9.81; double v0; cout << "Initial velocity (m/s): "; cin >> v0; double theta; cout << "Angle of trajectory (degrees): "; cin >> theta; theta = theta * PI / 180.0; double time = -2 * v0 * sin(theta) / G; double height = -pow(v0 * sin(theta), 2) / (2 * G); cout << fixed << showpoint << setprecision(3); cout << "Hangtime (s): " << time << endl; cout << "Height (m): " << height << endl; return 0; }