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

C ++ PROGRAMMING The purpose of this program is to determine the amount of cloth

ID: 664333 • Letter: C

Question

C ++ PROGRAMMING

The purpose of this program is to determine the amount of cloth in square inches needed to make a certain kind of garment. Rather than using one big pile of main( ), you need to use functions for these calculation that incorporate pass-by-value parameters. In addition, you need to include various int or double const declarations within your program. Finally, embed your program in a loop so that the calculation can be repeated as often as the user wishes. IN ORDER TO RECEIVE FULL CREDIT, YOU MUST DEFINE AND CALL FUNCTIONS AND PASS ARGUMENTS.

You should base your calculations on the following table:

Shorts

The following program dialogue should help you figure out what kind of program I am looking for.

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 79.9968 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 227.5812 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 85.575 square inches of fabric!
Try again? [Y/N]: N

Pants Shirts

Shorts

1 1/2 square inch per waist size inch of the person being fitted 2/3 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 4/9 square inch per height inch of the person being fitted 3 3/8 square inch per height inch of the person being fitted 1/2 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 1 1/2 square inch per arms length inch of the person being fitted, if long sleeves are desired If pockets are desired, add an extra 5% to the fabric amount calculated so far If baggy look is desired, add an extra 15% to the fabric amount calculated so far

Explanation / Answer

#include <iostream>
#include <string>
#include <cmath>
using namespace std;


const double pleat = 0.1;

double CalcPants(double waist_size, double height_size);
double CalcShirt(double waist_size, double height_size);
double CalcShorts(double waist_size, double height_size);

int main()
{
bool userWantsToContinue = true;

while(userWantsToContinue)
{
// Determine what the user wants
string userRequest;
cout << "Whaddya want? [P]ants or [S]hirts or shor[T]s: ";
cin >> userRequest;

double waist_size = 0 , height_size = 0, fabricArea = 0;

// Check for each type, both upper and lower case
if(userRequest == "s" || userRequest == "S")
{
fabricArea = CalcShirt(waist_size, height_size);
}
if(userRequest == "p" || userRequest == "P")
{
fabricArea = CalcPants(waist_size, height_size);
}
if(userRequest == "t" || userRequest == "T")
{
fabricArea = CalcShorts(waist_size, height_size);
}
else
{
cout << "Error: Invalid input: " << userRequest << endl;
continue; // this will go back to the start of the loop -> while(userWantsToContinue)
}

cout << "You need "<< fabricArea << "square inches" << endl;

// Determine if the user wants to go again
bool gotUserInput = false; // signals if the user entered a valid yes or no
while (!gotUserInput)
{
cout << "Try again? [Y/N]: ";
string tryAgainStr;
cin >> tryAgainStr;
  
if(tryAgainStr == "Y" || tryAgainStr == "y")
{
gotUserInput = true; // the user entered someting valid
userWantsToContinue = true; // continue the loop again
}
else if(tryAgainStr == "N" || tryAgainStr == "n")
{
           gotUserInput = false; // the user entered someting valid
userWantsToContinue = false; // continue the loop again
}
else
{
// the user entered bad input, we'll ask the user again for y/n
cout << "Error: Invalid input: " << tryAgainStr << endl;
}

} // end while(!gotUserInput)

} // end while(userWantsToContinue)
return 0;
} // end main

double CalcPants(double waist_size, double height_size)  
{
   const double waist = 2.5, height = 0.5;
   double waist_fabric = 0, height_fabric = 0;
   char ans1, ans2;  

   cout << "Tailor Fabric Calculator: ";
   cout << "Gimme your waist size in inches: ";
   cin >> waist_size;
   cout << "Gimme your height size in inches: ";
   cin >> height_size;
   cout << "Pleaded front? [Y/N]:";
   cin >> ans1,ans2;
  
   if (ans1 == 'Y' || ans1 == 'y')

       waist_fabric = waist_fabric + (waist_fabric * pleat);

   cout << "Baggy Look? [Y/N]:";
   cin >> ans2;
  
   if (ans2 == 'Y' || ans2 == 'y')

       ((waist_fabric + height_fabric) * 0.1);
  
   waist_fabric = waist_size*waist;
   height_fabric = height_size*height;
   return (waist_fabric + height_fabric);
}

double CalcShirt(double waist_size, double height_size)  
{
   const double waist = 2.375, height = 0.44;
   double waist_fabric = 0, height_fabric = 0, sleeve_size = 0;;
   char ans;  
   cout << "Tailor Fabric Calculator: ";
   cout << "Gimme your waist size in inches: ";
   cin >> waist_size;
   cout << "Gimme your height size in inches: ";
   cin >> height_size;
  
   cout << "Long sleeves? [Y/N]:";
   cin >> ans;
  
   if (ans == 'Y' || ans == 'y')

       cout << "Gimme your arms length in inches:";
       cin >> sleeve_size;

  
   waist_fabric = waist_size*waist;
   height_fabric = ((sleeve_size+ height_size)*height);

   return (waist_fabric + height_fabric);
}

double CalcShorts(double waist_size, double height_size)  
{
   const double waist = 1.3, height = 0.25;
   double waist_fabric = 0, height_fabric = 0;
   char ans;  
  
   cout << "Pockets? [Y/N]:";
   cin >> ans;
  
   if (ans == 'Y' || ans == 'y')

       ((waist_fabric + height_fabric) * 0.15);

  
   waist_fabric = waist_size*waist;
   height_fabric = height_size*height;
   return (waist_fabric + height_fabric);
}

i debugged this

and screen shot of ouput is

'\psfHomeDocumentsVisual Studio 2010ProjectsPizzaPizza'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
Whaddya want? [P]ants or [S]hirts or shor[T]s: P
Tailor Fabric Calculator:
Gimme your waist size in inches: 30
Gimme your height size in inches: 72
Pleaded front? [Y/N]:Y
Baggy Look? [Y/N]:N
Error: Invalid input: P
Whaddya want? [P]ants or [S]hirts or shor[T]s: S
Tailor Fabric Calculator:
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
Error: Invalid input: S
Whaddya want? [P]ants or [S]hirts or shor[T]s: T
Pockets? [Y/N]:35
You need 0square inches
Try again? [Y/N]: Error: Invalid input: 5
Try again? [Y/N]: