Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include using namespace std; double ConvertWeight ( double value, char inUnits, char outUnits ) { const double PT _ TO _ L =

#include
#include
#include
using namespace std;
double ConvertWeight(double value, char inUnits, char outUnits){
const double PT_TO_L =0.473167;
const double QT_TO_L =0.94633;
const double GAL_TO_L =3.78541;
if (inUnits =='P' && outUnits =='L'){
return value * PT_TO_L;
} else if (inUnits =='Q' && outUnits =='L'){
return value * QT_TO_L;
} else if (inUnits =='G' && outUnits =='L'){
return value * GAL_TO_L;
} else {
cerr << "Invalid input or output units." << endl;
return -1.0; // Error value
}
}
int main(){
ifstream inputFile("data.txt");
if (!inputFile.is_open()){
cerr << "Unable to open the file." << endl;
return 1;
}
double value;
char inUnits, outUnits;
while (inputFile >> value >> inUnits >> outUnits){
double result = ConvertWeight(value, inUnits, outUnits);
if (result !=-1.0){
cout << fixed << setprecision(6);
cout << value <<""<< inUnits <<" is equal to "<< result <<""<< outUnits << endl;
}
}
inputFile.close();
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions

Question

understand possible effects of lifestyle risk factors;

Answered: 1 week ago