# Question: Assignment 05 Write a C++ program (named Assignment05.cpp) that generate Pl to a user defined dec……

Assignment 05 Write a C++ program (named Assignment05.cpp) that generate Pl to a user defined decimal places (No rounding). (Pl is estimated as: 3.141592653589793) When you run/execute the program: as: 3.1415925358979fined 1. The user will be prompted to enter a number between 1 and 16, anything else the program exit displaying message stating not valid input 2. If the input is valid, the program will display the exact decimal places the user entered, for example: If the user entered 5 decimal places the output should be: 3.14159 not 3-14169 Also If the user entered 4 decimal places the output should be: 3.1415 not 34416 Notes 1. 2. Make sure you use proper variable and constant declaration. If the program is not outputting the correct result no credit will be given

Choose either method 1 or method 2.

Don't use plagiarized sources. Get Your Custom Essay on
Question: Assignment 05 Write a C++ program (named Assignment05.cpp) that generate Pl to a user defined dec……
Get an essay WRITTEN FOR YOU, Plagiarism free, and by an EXPERT!

If method 1 is selected, delete lines 35-43

If method 2 is selected, delete lines 21-33

Both methods give same result.

OUTPUT :

CODE ;

#include <iostream>

#include <string>

using namespace std;

//This function takes an integer n and prints PI upto n decimal places

//For printing upto n decimal places,

// we can use pi as string and either print decimal characters iteratively(METHOD 1)

//or use substr function(METHOD 2)

void printPI(int n)

{

if(n<1 || n>16) //check if input lies between 1 and 16

{

cout<<“Invalid input n”;

return;

}

//store pi as a constant string. Store upto 18 decimal places

//we use string to prevent rounding off

const string pi = “3.141592653589793238”;

//METHOD 1:

//Choose either method 1 or method 2. Remove the other method

//print integer part

cout<<“Pi upto “<<n<<” decimal places = 3.”;

//print decimal part upto n decimal places, starting from pi[2]

//As pi[0] = ‘3’ and pi[1]=’.’

for(int i=1;i<=n;i++)

cout<<pi[1+i];

cout<<endl;

//===============Method 1 END=================

//METHOD 2 :

cout<<“Pi upto “<<n<<” decimal places = “;

cout<<pi.substr(0,n+2)<<endl;

//pi.substr(a,b) = returns substring of pi from index a .

// b represents length of substring

//since we need to print “3.” also, we add 2 to n and start from index 0 i.e (0,n+2)

//===============Method 2 END=================

}

int main()

{

int n;

cout << “Enter no. of decimal places : 1 to 16 : n”;

cin>>n;

printPI(n);

return 0;

}

Order NOW For a 10% Discount!
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

## Calculate the price of your order

Total price:
\$0.00

How it works?

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

## Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.