The hectar number the instructor wants is not coming out right with this code: A
ID: 3812642 • Letter: T
Question
The hectar number the instructor wants is not coming out right with this code:
A building lot of 400 feet by 300 feet has 1.11 hectares.
A building lot of 125 feet by 200 feet has 0.23 hectares.
#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace std;
double getLength();
double getWidth();
double calcAcres(double length, double width);
double calcHectares(double length, double width);
void getLotSize();
void displayData(double length, double width, double area, double areainhec);
int main()
{
double length,
width,
area, areainhec;
width = getWidth();
length = getLength();
area = calcAcres(length, width);
areainhec = calcHectares(length, width);
displayData(length, width, area, areainhec);
return 0;
}
double getWidth()
{
cout << "------------------------------" << endl;
cout << "Building lot area calculator" << endl;
cout << "------------------------------" << endl;
cout << "Please enter the width in feet(example,100): ";
double width;
cin >> width;
return width;
}
double getLength()
{
cout << "Enter length in feet: ";
double length;
cin >> length;
return length;
}
double calcAcres(double length, double width)
{
// Converts square feet to acres
return ((length * width) / 43560);
}
double calcHectares(double length, double width)
{
// Converts square feet to hectars
return ((length * width) / 10000);
}
void getLotSize()
{
getLength();
getWidth();
}
void displayData(double length, double width, double area, double areainhec)
{
std::cout << std::fixed;
std::cout << std::setprecision(2);
cout << "A building lot of " << width << " feet by " << length << " feet has " << area << " acres." << endl;
cout << "A building lot of " << width << " feet by " << length << " feet has " << areainhec << " hectars." << endl;
}
Explanation / Answer
All are true;
Option A:
functionName(&var1,&var2); you can call function like this
Option B:
functionName(int var1,int var2) // these variable are local variable to functionName()
Option C:
Unless specified otherwise, all variables in C++ are passed by value.
functionName(var1,var2) // var1 and var2 are call passed by value
Option D:
Yes it can change the value in its method which will reflect to main method
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.