#include <cmath> #include <cstdlib> #include <iostream> using namespace std; //
ID: 3531247 • Letter: #
Question
#include <cmath>
#include <cstdlib>
#include <iostream>
using namespace std;
// FUNCTION PROTOTYPE FOR read_us_length
void read_us_length(int &,int &,int &);
// FUNCTION PROTOTYPE FOR convert2inches
int convert2inches(int yards,int feet,int inches);
// FUNCTION PROTOTYPE FOR convert2metric
void convert2metric(int total_inches,int meters,int centimeters);
// FUNCTION PROTOTYPE FOR write_metric_length
void write_metric_length(int meters,int centimeters);
int main()
{
int yards, feet, inches; // length in yards, feet and inches
int total_inches; // total length in inches
int meters, centimeters; // length in meters and centimeters
read_us_length(yards, feet, inches);
total_inches = convert2inches(yards, feet, inches);
convert2metric(total_inches, meters, centimeters);
write_metric_length(meters, centimeters);
return 0;
}
// DEFINE FUNCTION read_us_length HERE:
void read_us_length(int & yards,int & feet,int & inches)
{
cout<<"FOR READING LENGTHS: ";
cout<<"Enter yards: ";
cin>>yards;
cout<<"Enter feet: ";
cin>>feet;
cout<<"Enter inches: ";
cin>>inches;
if (yards<0)
{
cerr<<"Yards cannot be negative"<<endl;
}
else if (feet<0)
{
cerr<<"Feet cannot be negative"<<endl;
}
else if (inches<0)
{
cerr<<"Inches cannot be negative"<<endl;
return;
}
// DEFINE FUNCTION convert2inches HERE:
int convert2inches(int yards,int feet,int inches)
{
int total_inches;
total_inches=(yards * 36) + (feet * 12) + inches;
return total_inches;
}
// DEFINE FUNCTION convert2metric HERE
void convert2metric(int total_inches,int &meters,int ¢imeters)
{
centimeters = total_inches*2.54;
meters = centimeters/100;
return;
}
// DEFINE FUNCTION write_metric_length HERE:
void write_metric_length(int meters,int centimeters)
{
cout<<"Number of Centimeters: "<<centimeters<<endl;
cout<<"Number of Meters: "<<meters<<endl;
//cout<<"FOR centimeters (B): "<<convert2metric<<endl;
cout<<"FOR centimeters (B): "<<centimeters+(meters*100)<<endl;
return;
}
}
convert2metric.cpp: In function
Explanation / Answer
/* This program reads in a length yards, feet and inches, and converts to meters and centimeters. */ #include //#include //#include using namespace std; // FUNCTION PROTOTYPE FOR read_us_length void read_us_length(int &yards,int &feet,int &inches); // FUNCTION PROTOTYPE FOR convert2inches int convert2inches(int yards,int feet,int inches); // FUNCTION PROTOTYPE FOR convert2metric void convert2metric(int total_inches,int &meters,int ¢imeters); //changed to void // FUNCTION PROTOTYPE FOR write_metric_length void write_metric_length(int meters,int centimeters);//changed to void //------------------------------------------------------------------------------------MAIN CANNOT BE ALTERED--------------------------------------- int main() { int yards, feet, inches; // length in yards, feet and inches int total_inches; // total length in inches int meters, centimeters; // length in meters and centimeters read_us_length(yards, feet, inches); total_inches = convert2inches(yards, feet, inches); convert2metric(total_inches, meters, centimeters); write_metric_length(meters, centimeters); return 0; } // DEFINE FUNCTION read_us_length HERE: void read_us_length(int &yards,int &feet,int &inches) { //a misplaced } and returning wrong variable coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.