Computer Science 1620 - PowerPoint PPT Presentation

About This Presentation
Title:

Computer Science 1620

Description:

suppose that I invest $25000 into a mutual fund that returns 8% per year. ... ceil(x) Returns the closest whole number x. floor(x) Returns ex. exp(x) Returns log10 x ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 51
Provided by: Kev995
Category:
Tags: ceil | computer | science

less

Transcript and Presenter's Notes

Title: Computer Science 1620


1
Computer Science 1620
  • Math Library

2
  • 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

3
  • 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 ltiostreamgt using namespace std int
main() cout ltlt "Year 1 " ltlt 25000 1.08
ltlt endl cout ltlt "Year 2 " ltlt 25000 1.08
1.08 ltlt endl cout ltlt "Year 3 " ltlt 25000
1.08 1.08 1.08 ltlt endl return 0
4
  • 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 ltiostreamgt using namespace std int
main() double balance 25000.0 balance
balance 1.08 cout ltlt "Year 1 " ltlt
balance ltlt endl balance balance 1.08
cout ltlt "Year 2 " ltlt balance ltlt endl
balance balance 1.08 cout ltlt "Year 3 "
ltlt balance ltlt endl return 0
5
(No Transcript)
6
  • 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 ltiostreamgt include ltiomanipgt using
namespace std int main() cout ltlt fixed ltlt
showpoint ltlt setprecision(2) cout ltlt "Year 1
" ltlt 25000 1.08 ltlt endl cout ltlt "Year 2 "
ltlt 25000 1.08 1.08 ltlt endl cout ltlt "Year
3 " ltlt 25000 1.08 1.08 1.08 ltlt endl
return 0
7
  • 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 ltiostreamgt include ltiomanipgt using
namespace std int main() double balance
25000.0 cout ltlt fixed ltlt showpoint ltlt
setprecision(2) balance balance 1.08
cout ltlt "Year 1 " ltlt balance ltlt endl
balance balance 1.08 cout ltlt "Year 2 "
ltlt balance ltlt endl balance balance 1.08
cout ltlt "Year 3 " ltlt balance ltlt endl
return 0
8
(No Transcript)
9
  • 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

10
  • 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 ltiostreamgt include ltiomanipgt using
namespace std int main() cout ltlt fixed ltlt
showpoint ltlt setprecision(2) cout ltlt "Year 1
" ltlt 25000 1.08 ltlt endl cout ltlt "Year 2 "
ltlt 25000 1.08 1.08 ltlt endl cout ltlt "Year
3 " ltlt 25000 1.08 1.08 1.08 ltlt endl
return 0
11
  • 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 ltiostreamgt include ltiomanipgt using
namespace std int main() cout ltlt fixed ltlt
showpoint ltlt setprecision(2) cout ltlt "Year 1
" ltlt 25000 1.08 ltlt endl cout ltlt "Year 2 "
ltlt 25000 1.08 1.08 ltlt endl cout ltlt "Year
3 " ltlt 25000 1.08 1.08 1.08 ltlt endl
return 0
12
  • 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 ltiostreamgt include ltiomanipgt using
namespace std int main() cout ltlt fixed ltlt
showpoint ltlt setprecision(2) cout ltlt "Year 10
" ltlt 25000 1.08 1.08 1.08 1.08 1.08
1.08 1.08 1.08 1.08 1.08 ltlt endl cout
ltlt "Year 2 " ltlt 25000 1.08 1.08 ltlt endl
cout ltlt "Year 3 " ltlt 25000 1.08 1.08 1.08
ltlt endl return 0
13
  • 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 ltiostreamgt include ltiomanipgt using
namespace std int main() cout ltlt fixed ltlt
showpoint ltlt setprecision(2) cout ltlt "Year 10
" ltlt 25000 1.08 1.08 1.08 1.08 1.08
1.08 1.08 1.08 1.08 1.08 ltlt endl cout
ltlt "Year 20 " ltlt 25000 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 ltlt endl cout ltlt "Year 30
" ltlt 25000 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 ltlt endl return
0
14
  • 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 ltiostreamgt include ltiomanipgt using
namespace std int main() double balance
25000.0 cout ltlt fixed ltlt showpoint ltlt
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 ltlt "Year 10 " ltlt balance ltlt
endl balance balance 1.08 1.08 1.08
1.08 1.08 1.08 1.08 1.08 1.08 1.08
cout ltlt "Year 20 " ltlt balance ltlt endl
balance balance 1.08 1.08 1.08 1.08
1.08 1.08 1.08 1.08 1.08 1.08 cout
ltlt "Year 30 " ltlt balance ltlt endl return 0
15
(No Transcript)
16
  • The previous example worked, but
  • to calculate 1.0830 required that we manually
    type in thirty multiplications
  • suppose we had wanted to know the balance after
    100 years?

17
  • 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
18
  • Example

include ltiostreamgt include ltcmathgt using
namespace std int main() cout ltlt
pow(3.0, 3.0) ltlt endl cout ltlt pow(3, 4.0) ltlt
endl cout ltlt pow(4.0, 3) ltlt endl int x
5 double y 6.0 cout ltlt pow(x, y) ltlt
endl cout ltlt pow(x, y) pow(3.0, 3.0) ltlt
endl cout ltlt pow( pow(x, y), pow(3.0, 3.0)
) ltlt endl return 0
19
  • A note about pow
  • you cannot send it two integer expressions
  • cout ltlt pow(3, 4) ltlt 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

20
  • The cmath library

Function Description
abs(x) Returns the absolute value of x
pow(x, y) Returns xy
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 log10 x
exp(x) Returns ex
floor(x) Returns the closest whole number lt x
ceil(x) Returns the closest whole number gt x
21
  • 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

22
Expression Type
sqrt(2.0) double
sin(2.0f) float
cos(2) double
log(3 4.0f) float
exp(2) exp(2.0) double
abs(75) int
floor(3.5) double
23
  • A Note about the Trig Functions
  • the input expression is considered to be radians
  • hence, sin(30.0) -0.988032, not 0.5
  • to convert radians to degrees, multiply the value
    by (p / 180)

24
  • Example

include ltiostreamgt include ltcmathgt using
namespace std int main() const double PI
3.14159 cout ltlt sin(30) ltlt endl cout ltlt
sin(30 PI / 180) ltlt endl return 0
25
(No Transcript)
26
  • 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

27
  • 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 ltiostreamgt include ltiomanipgt using
namespace std int main() cout ltlt fixed ltlt
showpoint ltlt setprecision(2) cout ltlt "Year 10
" ltlt 25000 1.08 1.08 1.08 1.08 1.08
1.08 1.08 1.08 1.08 1.08 ltlt endl cout
ltlt "Year 20 " ltlt 25000 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 ltlt endl cout ltlt "Year 30
" ltlt 25000 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 ltlt endl return
0
28
  • 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 ltiostreamgt include ltcmathgt include
ltiomanipgt using namespace std int main()
cout ltlt fixed ltlt showpoint ltlt setprecision(2)
cout ltlt "Year 10 " ltlt 25000 pow(1.08, 10) ltlt
endl cout ltlt "Year 10 " ltlt 25000 pow(1.08,
20) ltlt endl cout ltlt "Year 10 " ltlt 25000
pow(1.08, 30) ltlt endl return 0
29
  • 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 ltiostreamgt include ltiomanipgt using
namespace std int main() double balance
25000.0 cout ltlt fixed ltlt showpoint ltlt
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 ltlt "Year 10 " ltlt balance ltlt
endl balance balance 1.08 1.08 1.08
1.08 1.08 1.08 1.08 1.08 1.08 1.08
cout ltlt "Year 20 " ltlt balance ltlt endl
balance balance 1.08 1.08 1.08 1.08
1.08 1.08 1.08 1.08 1.08 1.08 cout
ltlt "Year 30 " ltlt balance ltlt endl return 0
30
  • 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 ltiostreamgt include ltcmathgt include
ltiomanipgt using namespace std int main()
double balance 25000.0 cout ltlt fixed ltlt
showpoint ltlt setprecision(2) balance
balance pow(1.08, 10) cout ltlt "Year 10 "
ltlt balance ltlt endl balance balance
pow(1.08, 10) cout ltlt "Year 20 " ltlt balance
ltlt endl balance balance pow(1.08, 10)
cout ltlt "Year 30 " ltlt balance ltlt endl
return 0
31
  • 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 ltiostreamgt include ltcmathgt include
ltiomanipgt using namespace std int main()
double balance 25000.0 double increase
pow(1.08, 10) cout ltlt fixed ltlt showpoint ltlt
setprecision(2) balance balance
increase cout ltlt "Year 10 " ltlt balance ltlt
endl balance balance increase cout ltlt
"Year 20 " ltlt balance ltlt endl balance
balance increase cout ltlt "Year 30 " ltlt
balance ltlt endl return 0
32
  • 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

33
Arithmetic Data and Operators
  • Given a value ? and initial velocity v0, we can
    calculate the time that the ball stays in the
    air
  • and its maximum height
  • g is approximately -9.81 m/s at sea level

34
  • 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 ltiostreamgt include ltcmathgt include
ltiomanipgt using namespace std int main()
const double PI 3.14159 const double G
-9.81 double v0 cout ltlt "Initial velocity
(m/s) " cin gtgt v0 double theta cout
ltlt "Angle of trajectory (degrees) " cin gtgt
theta theta theta PI / 180.0
double time -2 v0 sin(theta) / G
double height -pow(v0 sin(theta), 2) / (2
G) cout ltlt fixed ltlt showpoint ltlt
setprecision(2) cout ltlt "Hangtime (s) " ltlt
time ltlt endl cout ltlt "Height (m) " ltlt
height ltlt endl return 0
35
  • 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 ltiostreamgt include ltcmathgt include
ltiomanipgt using namespace std int main()
const double PI 3.14159 const double G
-9.81 double v0 cout ltlt "Initial velocity
(m/s) " cin gtgt v0 double theta cout
ltlt "Angle of trajectory (degrees) " cin gtgt
theta theta theta PI / 180.0
double time -2 v0 sin(theta) / G
double height -pow(v0 sin(theta), 2) / (2
G) cout ltlt fixed ltlt showpoint ltlt
setprecision(2) cout ltlt "Hangtime (s) " ltlt
time ltlt endl cout ltlt "Height (m) " ltlt
height ltlt endl return 0
36
  • 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 ltiostreamgt include ltcmathgt include
ltiomanipgt using namespace std int main()
const double PI 3.14159 const double G
-9.81 double v0 cout ltlt "Initial velocity
(m/s) " cin gtgt v0 double theta cout
ltlt "Angle of trajectory (degrees) " cin gtgt
theta theta theta PI / 180.0
double time -2 v0 sin(theta) / G
double height -pow(v0 sin(theta), 2) / (2
G) cout ltlt fixed ltlt showpoint ltlt
setprecision(2) cout ltlt "Hangtime (s) " ltlt
time ltlt endl cout ltlt "Height (m) " ltlt
height ltlt endl return 0
37
  • 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 ltiostreamgt include ltcmathgt include
ltiomanipgt using namespace std int main()
const double PI 3.14159 const double G
-9.81 double v0 cout ltlt "Initial velocity
(m/s) " cin gtgt v0 double theta cout
ltlt "Angle of trajectory (degrees) " cin gtgt
theta theta theta PI / 180.0
double time -2 v0 sin(theta) / G
double height -pow(v0 sin(theta), 2) / (2
G) cout ltlt fixed ltlt showpoint ltlt
setprecision(2) cout ltlt "Hangtime (s) " ltlt
time ltlt endl cout ltlt "Height (m) " ltlt
height ltlt endl return 0
38
  • 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 ltiostreamgt include ltcmathgt include
ltiomanipgt using namespace std int main()
const double PI 3.14159 const double G
-9.81 double v0 cout ltlt "Initial velocity
(m/s) " cin gtgt v0 double theta cout
ltlt "Angle of trajectory (degrees) " cin gtgt
theta theta theta PI / 180.0
double time -2 v0 sin(theta) / G
double height -pow(v0 sin(theta), 2) / (2
G) cout ltlt fixed ltlt showpoint ltlt
setprecision(2) cout ltlt "Hangtime (s) " ltlt
time ltlt endl cout ltlt "Height (m) " ltlt
height ltlt endl return 0
39
  • 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 ltiostreamgt include ltcmathgt include
ltiomanipgt using namespace std int main()
const double PI 3.14159 const double G
-9.81 double v0 cout ltlt "Initial velocity
(m/s) " cin gtgt v0 double theta cout
ltlt "Angle of trajectory (degrees) " cin gtgt
theta theta theta PI / 180.0
double time -2 v0 sin(theta) / G
double height -pow(v0 sin(theta), 2) / (2
G) cout ltlt fixed ltlt showpoint ltlt
setprecision(2) cout ltlt "Hangtime (s) " ltlt
time ltlt endl cout ltlt "Height (m) " ltlt
height ltlt endl return 0
40
  • 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 ltiostreamgt include ltcmathgt include
ltiomanipgt using namespace std int main()
const double PI 3.14159 const double G
-9.81 double v0 cout ltlt "Initial velocity
(m/s) " cin gtgt v0 double theta cout
ltlt "Angle of trajectory (degrees) " cin gtgt
theta theta theta PI / 180.0
double time -2 v0 sin(theta) / -9.81
double height -pow(v0 sin(theta), 2) / (2
G) cout ltlt fixed ltlt showpoint ltlt
setprecision(2) cout ltlt "Hangtime (s) " ltlt
time ltlt endl cout ltlt "Height (m) " ltlt
height ltlt endl return 0
cmath call
41
  • 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 ltiostreamgt include ltcmathgt include
ltiomanipgt using namespace std int main()
const double PI 3.14159 const double G
-9.81 double v0 cout ltlt "Initial velocity
(m/s) " cin gtgt v0 double theta cout
ltlt "Angle of trajectory (degrees) " cin gtgt
theta theta theta PI / 180.0
double time -2 v0 sin(theta) / -9.81
double height -pow(v0 sin(theta), 2) / (2
G) cout ltlt fixed ltlt showpoint ltlt
setprecision(2) cout ltlt "Hangtime (s) " ltlt
time ltlt endl cout ltlt "Height (m) " ltlt
height ltlt endl return 0
Magic Number
42
  • 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 ltiostreamgt include ltcmathgt include
ltiomanipgt using namespace std int main()
const double PI 3.14159 const double G
-9.81 double v0 cout ltlt "Initial velocity
(m/s) " cin gtgt v0 double theta cout
ltlt "Angle of trajectory (degrees) " cin gtgt
theta theta theta PI / 180.0
double time -2 v0 sin(theta) / G
double height -pow(v0 sin(theta), 2) / (2
G) cout ltlt fixed ltlt showpoint ltlt
setprecision(2) cout ltlt "Hangtime (s) " ltlt
time ltlt endl cout ltlt "Height (m) " ltlt
height ltlt endl return 0
Expects radians
43
  • 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 ltiostreamgt include ltcmathgt include
ltiomanipgt using namespace std int main()
const double PI 3.14159 const double G
-9.81 double v0 cout ltlt "Initial velocity
(m/s) " cin gtgt v0 double theta cout
ltlt "Angle of trajectory (degrees) " cin gtgt
theta theta theta 3.14159 / 180.0
double time -2 v0 sin(theta) / G
double height -pow(v0 sin(theta), 2) / (2
G) cout ltlt fixed ltlt showpoint ltlt
setprecision(2) cout ltlt "Hangtime (s) " ltlt
time ltlt endl cout ltlt "Height (m) " ltlt
height ltlt endl return 0
Magic Number
44
  • 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 ltiostreamgt include ltcmathgt include
ltiomanipgt using namespace std int main()
const double PI 3.14159 const double G
-9.81 double v0 cout ltlt "Initial velocity
(m/s) " cin gtgt v0 double theta cout
ltlt "Angle of trajectory (degrees) " cin gtgt
theta theta theta PI / 180.0
double time -2 v0 sin(theta) / G
double height -pow(v0 sin(theta), 2) / (2
G) cout ltlt fixed ltlt showpoint ltlt
setprecision(2) cout ltlt "Hangtime (s) " ltlt
time ltlt endl cout ltlt "Height (m) " ltlt
height ltlt endl return 0
45
  • 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 ltiostreamgt include ltcmathgt include
ltiomanipgt using namespace std int main()
const double PI 3.14159 const double G
-9.81 double v0 cout ltlt "Initial velocity
(m/s) " cin gtgt v0 double theta cout
ltlt "Angle of trajectory (degrees) " cin gtgt
theta theta theta PI / 180.0
double time -2 v0 sin(theta) / G
double height -pow(v0 sin(theta), 2) / (2
G) cout ltlt fixed ltlt showpoint ltlt
setprecision(2) cout ltlt "Hangtime (s) " ltlt
time ltlt endl cout ltlt "Height (m) " ltlt
height ltlt endl return 0
46
  • 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 ltiostreamgt include ltcmathgt include
ltiomanipgt using namespace std int main()
const double PI 3.14159 const double G
-9.81 double v0 cout ltlt "Initial velocity
(m/s) " cin gtgt v0 double theta cout
ltlt "Angle of trajectory (degrees) " cin gtgt
theta theta theta PI / 180.0
double time -2 v0 sin(theta) / G
double height -pow(v0 sin(theta), 2) / (2
G) cout ltlt fixed ltlt showpoint ltlt
setprecision(2) cout ltlt "Hangtime (s) " ltlt
time ltlt endl cout ltlt "Height (m) " ltlt
height ltlt endl return 0
47
  • 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 ltiostreamgt include ltcmathgt include
ltiomanipgt using namespace std int main()
const double PI 3.14159 const double G
-9.81 double v0 cout ltlt "Initial velocity
(m/s) " cin gtgt v0 double theta cout
ltlt "Angle of trajectory (degrees) " cin gtgt
theta theta theta PI / 180.0
double time -2 v0 sin(theta) / G
double height -pow(v0 sin(theta), 2) / (2
G) cout ltlt fixed ltlt showpoint ltlt
setprecision(2) cout ltlt "Hangtime (s) " ltlt
time ltlt endl cout ltlt "Height (m) " ltlt
height ltlt endl return 0
48
  • 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 ltiostreamgt include ltcmathgt include
ltiomanipgt using namespace std int main()
const double PI 3.14159 const double G
-9.81 double v0 cout ltlt "Initial velocity
(m/s) " cin gtgt v0 double theta cout
ltlt "Angle of trajectory (degrees) " cin gtgt
theta theta theta PI / 180.0
double time -2 v0 sin(theta) / G
double height -pow(v0 sin(theta), 2) / (2
G) cout ltlt fixed ltlt showpoint ltlt
setprecision(2) cout ltlt "Hangtime (s) " ltlt
time ltlt endl cout ltlt "Height (m) " ltlt
height ltlt endl return 0
49
  • 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 ltiostreamgt include ltcmathgt include
ltiomanipgt using namespace std int main()
const double PI 3.14159 const double G
-9.81 double v0 cout ltlt "Initial velocity
(m/s) " cin gtgt v0 double theta cout
ltlt "Angle of trajectory (degrees) " cin gtgt
theta theta theta PI / 180.0
double time -2 v0 sin(theta) / G
double height -pow(v0 sin(theta), 2) / (2
G) cout ltlt fixed ltlt showpoint ltlt
setprecision(3) cout ltlt "Hangtime (s) " ltlt
time ltlt endl cout ltlt "Height (m) " ltlt
height ltlt endl return 0
50
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com