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

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

Expert Answer

answers

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!
Order Essay

If method 1 is selected, delete lines 35-43

If method 2 is selected, delete lines 21-33

Both methods give same result.

main.cpp E saved 1 #include <iostream> #include <string> 3 using namespace std; 4. 5 //This function takes an integer n and prints PI upto n decimal places 6 //For printing upto n decimal places, 7 I/ we can use pi as string and either print decimal characters iteratively (METHOD 1) 8 //or use substr function(METHOD 2) 9 void printPI(int n) 10 11 | İf(n<1 Il n>16) //check if input lies between 1 and 16 12 13 14 15 16 coutくぐInvalid return; input n; //store pi as a constant string. Store upto 18 decimal places //we use string to prevent rounding off const string pi3.141592653589793238; 18 19 20 21 22 //Choose either method 1 or method 2. Remove the other method 23 24 25 26 I/print decimal part upto n decimal places, starting from pi[2] 27 | //As pǐ[0] = 3 and pi [1ド 28 29 30 31 32 /METHOD 1 //print integer part cout<<Pi upto <<n<< decimal places -3.; for(int i=1;i<=n;i++) cout<<pi[1+i]; cout<<endl; -Method 1 END 35 //METHOD 2: 36 37 38 39 //pi.substr (a,b)returns substring of pi from index a 40 41//since we need to print 3. also, we add 2 to n and start from index 0 i.e (0,n+2) 42 43// cout<<Pi upto <<n<< decimal cout&pi. Substr(0,n+2)<<endl; places = // b represents length of substring -Method 2 END 46

UdizcsqFWakGKP_BPgsp3Igo3QkJtXLDVAy3BwqX

OUTPUT :

AyMl_01zO1iW3SVmedpWEEFyMXKs8lMOpeg9CzJy

rVncEW_OVr9WFv9dyOes8iBRR24-COrR5iYZe2y9

XPS7rQH16L7poxRKid9UjLGHhXAXSIKmaGSqdlnQ

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;

}

Top Grade Homework
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.

Professional and Experienced Academic Writers

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.

24/7 Customer Support

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?

Follow these simple steps to get your paper done

Place your order

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

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

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.

Essays

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.

Admissions

Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.

Reviews

Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.

Reviews

Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.

× Contact Live Agents