Hi. I need help with this program that I don\'t even know how to write. This is
ID: 3724313 • Letter: H
Question
Hi. I need help with this program that I don't even know how to write. This is due tomorrow. The program requirements are right here..
Implement in another class such a program will prompt the user for kilograms and produce the calculated pouunds. The program will terminate only if the user types in a negative numbers for kilograms. The logic for the porgram is provided below. Use a while-loop for this program. Here is a sample of the execution:
Lab 7, Written by <Your Name>
-------------------------------------------
Enter the kilograms or a negative number to terminate: 2
Pounds = 4.4
Enter the kilograms or a negative number to terminate : -1
End of Program
**************************************
Algorithm:
Print Lab Heading
Prompt the user for kilograms
while (kilograms >= 0)
Calculate the converted pounds value
Print the converted results to the terminal
Prompt the user for kilograms
end-while
Print End of Progam Footer
Explanation / Answer
code has been done c++.
//created a class tthat converts kilos into pounds
Coding:
#include <cstdlib>
#include <iostream>
#include<iomanip>
using namespace std;
//create a class Calculate_Kilogram with the member Convert_Kilo_pound
class Calculate_Kilogram{
public:
//create the function to convert kilogram to pound and return a float value
float Convert_Kilo_pound(float k){
return(2.2*k);
}//end of function
};//end of class
//driver function
int main(int argc, char** argv) {
cout<<" Lab 7..."<<endl; //prints the heading
//declares the variable for storing kilogram and pound
float kilo, p;
//create an object for class
Calculate_Kilogram pd;
//prompt the user to enter the kilogram and store it in kilo
cout<<" Enter the Kilogram :";
cin>>kilo;
//preform the loop until the user enter negative number
while(kilo>=0)
{
//object pd calls the member function Convert_Kilo_pound with argument kilo
// and function returns the float value stored inthe variable p
p = pd.Convert_Kilo_pound(kilo);
//Disp1ays the result
cout<<" Pound : "<<setprecision(2)<<p;
//prompt the user for another input
cout<<" Enter the Kilogram :";
cin>>kilo;
}
return 0;
}
Sample output:
Lab 7...
Enter the Kilogram :2.45
Pound : 5.4
Enter the Kilogram :2
Pound : 4.4
Enter the Kilogram :-1
RUN SUCCESSFUL (total time: 13s)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.