<< Chapter < Page Chapter >> Page >

cout<<"The circumference of the circle is "

<<circumference<<endl;

return 0;

}

The output of the above program:

The circumference of the circle is 12.5664

Focus on problem solving

In this section, we present a programming problem to further illustrate both the use of cin statements to accept user input data and the use of library functions for performing calculations.

Problem: Approximating the Exponential Function

The exponential function e^x, where e is known as Euler’s number (and has the value 2.718281828459045…) appears many times in descriptions of natural phenomena. The value of e^x can be approximated using the following series:

1 + x/1 + x^2/2 + x^3/6 + x^4/24 + x^5/120 + x^6/720 + …

Using this polynomial as a base, assume you are given the following assignment: Write a program that approximates e raised to a user input value of x using the first four terms of this series. For each approximation, display the value calculated by C++’s exponential function, exp(), the approximate value, and the absolute difference between the two. Make sure to verify your program using a hand calculation. Once the verification is complete, use the program to approximate e^4.

Using the top-down development procedure, we perform the following steps.

Step 1: analyze the problem

The statement of the problem specifies that four approximations are to be made using one, two, three, and four terms of the approximating polynomial, respectively. For each approximation, three output values are required: the value of produced by the exponential function, the approximate value, and the absolute difference between the two values. The structure of the required output display is as below (in symbolic form).

Realizing the each line in the display can only be produced by executing a cout statement, it should be clear that four such statements must be executed. Additionally, since each output line contains three computed values, each cout statement will have three items in its expression list.

The only input to the program consists of the value of x. This will, of course, require a single prompt and a cin statement to input the necessary value.

Step 2: develop a solution

Before any output items can be calculated, the program needs to prompt the user for a value of x and then accept the entered value. The output display consists of two title lines followed by four lines of calculated data. The title lines can be produced using two cout statements. Now let’s see how the data being displayed are produced.

The first item on the first data output line illustrated in Table 3.4 can be obtained using the exp() function. The second item on this line, the approximation to ex , can be obtained by using the first term in the polynomial that was given in the program specification. Finally, the third item on the line can be calculated by using the abs() function on the difference between the first two lines. When all of these items are calculated, a single cout statement can be used to display the three results on the same line.

Questions & Answers

Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
Adin
why?
Adin
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
research.net
kanaga
sciencedirect big data base
Ernesto
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
Bharti
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
Daniel
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
Maciej
characteristics of micro business
Abigail
for teaching engĺish at school how nano technology help us
Anassong
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
NANO
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
s.
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
Tarell
what is the actual application of fullerenes nowadays?
Damian
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
Tarell
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
Virgil
is Bucky paper clear?
CYNTHIA
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
NANO
so some one know about replacing silicon atom with phosphorous in semiconductors device?
s. Reply
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Harper
Do you know which machine is used to that process?
s.
how to fabricate graphene ink ?
SUYASH Reply
for screen printed electrodes ?
SUYASH
What is lattice structure?
s. Reply
of graphene you mean?
Ebrahim
or in general
Ebrahim
in general
s.
Graphene has a hexagonal structure
tahir
On having this app for quite a bit time, Haven't realised there's a chat room in it.
Cied
what is biological synthesis of nanoparticles
Sanket Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





Source:  OpenStax, Programming fundamentals in c++. OpenStax CNX. Jul 29, 2009 Download for free at http://cnx.org/content/col10788/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Programming fundamentals in c++' conversation and receive update notifications?

Ask