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

Write the algorithm & the code Design a program that prompts a user to enter a n

ID: 3622205 • Letter: W

Question

Write the algorithm & the code

Design a program that prompts a user to enter a number representing a measurement and then identify whether it is pounds(enter a P) or yards (enter a Y). The program should convert the measument into either kilograms or meters and output the result as a number with two decimal places.

Use four user-defined functions with the following names that accomplish the following:

.getNumber- obtains from the user a number representing a measument.This function should use a loop to validate that the input is a number greater than zero.

.identifyInput- asks the user to identify the number input as pounds by entering a 'P' or yards by entering a 'Y'. This function should use a predefined function to convert the input to an uppercase letter and use a loop to validate that the input is a 'P' or a 'Y.'

.getKilos- convert pounds to kilograms by multiplying the pounds by 0.45359237 and returns the result.

.getMeters- convert yards to meters by multlpying the yeards by 0.9144 and ruturns the result.

                                                                                    

Explanation / Answer

please rate - thanks

#include <iostream>
#include<iomanip>
using namespace std;
int getnumber();
char identifyInput();
double getKilos(int);
double getMeters(int);
int main()
{int n;
char type;
n=getnumber();
type=identifyInput();
if(type=='P')
     cout<<n<<" pounds is "<<getKilos(n)<<" kilograms ";
else
     cout<<n<<" yards is "<<getMeters(n)<<" meters ";
system("pause");
return 0;
}
int getnumber()
{int n;
cout<<"Enter a number: ";
cin>>n;
while(n<=0)
   {cout<<"must be >0 ";
    cout<<"Enter a number: ";
    cin>>n;
    }
return n;
}
char identifyInput()
{char type;
cout<<"is this pounds(enter p) or yards(enter y)?";
cin>>type;
type=toupper(type);
while(type!='P'&&type !='Y')
    {cout<<"must enter P or Y ";
     cout<<"is this pounds(enter p) or yards(enter y)?";
     cin>>type;
     type=toupper(type);
     }
return type;
}
double getKilos(int n)
{return n*.45359237;
}
double getMeters(int n)
{return n*.9144;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote