Question: #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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!