Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The objective of this Exercise is to illustrate the use of formatted output for the irrational number pi (pi) and to demonstrate the difference in
The objective of this Exercise is to illustrate the use of formatted output for the irrational number pi (pi) and to demonstrate the difference in accuracy between float variables and double variables. Write a C++ computer program that does the following: 1. Declares a constant float variable for pi. For example: const float PIF = 3.1415926535 2. Prints PIF accurate to 2 decimal places 3. Prints PIF accurate to 4 decimal places 4. Prints PIf accurate to 10 decimal places 1. Declares a constant double variable for pi. For example: const double PId = 3.1415926535 2. Prints PId accurate to 2 decimal places 3. Prints PId accurate to 4 decimal places 4. Prints PId accurate to 10 decimal places Declare a character variable to print the symbol for pi The ascii code for pi is 227 Your output may look something like the following: Things to note: You should use the declarative for constant: const. Variables that do not change their value during the course of the program and or have defined constant values, such as the irrational numbers pi and e should be declared constant. You do not have to use the variable names PIf or PId. A good naming convention to follow is to always use capital letters for a variable name that is constant. Use setprecision to determine the number of decimal places to be printed. In reviewing the output window, note that even though the assigned value for PI is accurate to 10 decimal places in both cases, the printed values differ after 6 decimal places. Can you draw any conclusions
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started