Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Project 1: Pi Rather than putting all your code in main() , use functions to per

ID: 3782815 • Letter: P

Question

Project 1: Pi

Rather than putting all your code in main(), use functions to perform the calculation.  Embed your program in a loop so that the calculation can be repeated multiple times.

Project 2: Tailor

The purpose of this C++ program is to determine how much cloth in square inches is needed to make a certain type of garment. You should base your calculations on the following table:


Rather than putting all your code in main(), use functions to perform the calculation.  Embed your program in a loop so that the calculation can be repeated multiple times. Use constants to hold the literal values in the above table, for example:

const double PANTS_WAIST_FACTOR = 2 + 1.0/2;

Tailor Fabric Calculator:
Whaddya want? [P]ants or [S]hirts or shor[T]s: P
Gimme your waist size in inches: 30
Gimme your height size in inches: 72
Pleaded front? [Y/N]: Y
Baggy Look? [Y/N]: N
For your pants, you'll need 114 square inches of fabric!
Try again? [Y/N]: Y

Tailor Fabric Calculator:
Whaddya want? [P]ants or [S]hirts or shor[T]s: S
Gimme your waist size in inches: 32
Gimme your height size in inches: 50
Long sleeves? [Y/N]: Y
Gimme your arms length in inches: 25
For your shirts, you'll need 168.2222 square inches of fabric!
Try again? [Y/N]: Y

Tailor Fabric Calculator:
Whaddya want? [P]ants or [S]hirts or shor[T]s: T
Gimme your waist size in inches: 35
Gimme your height size in inches: 72
Pockets? [Y/N]: Y
For your shorts, you'll need 73.025 square inches of fabric!
Try again? [Y/N]: N

Pants Shirts Shorts 2 1/2 square inch per waist size inch of the person being fitted 2 3/8 square inch per waist size inch of the person being fitted 1 3/10 square inch per waist size inch of the person being fitted 1/2 square inch per height inch of the person being fitted 4/9 square inch per height inch of the person being fitted 1/4 square inch per height inch of the person being fitted 1/10 square inch per waist size inch of the person being fitted, if pleaded front is desired 2 4/5 square inch per arms length inch of the person being fitted, if long sleeves are desired If pockets are desired, add an extra 15% to the fabric amount calculated so far If baggy look is desired, add an extra 10% to the fabric amount calculated so far

Explanation / Answer

Project 1: PI

// Calculating Pi for specified Iterations

// Using Leibinz’s Formula

#include <iostream>

#include<cmath>

#include<stdio.h>

using namespace std;

// Function to calculate Pi using Leibinz Formula

double cal_pi_leibniz(int iter)

{

int j=0;

double sum=0;

for(j=0; j<=iter; j++)

{

sum+= -1/(double)(2*j+1);

sum*=-1;

}

return sum;

}

int main()

{

int no_of_iteration;

cout << “Enter number of iterations to calculate: “;

cin >> no_of_iteration;

cout << "The value of Pi after " << no_of_iteration << " iterations is approximately: " << cal_pi_leibniz(no_of_iteration) * 4 << endl;

}

return 0;

}