Hey guys, so my assignment is making a program that takes 2 measure objects and multiplies them together and displays them in square feet.
What I'm trying to do is convert the feet into inches for both of the measure objects, then multiply the added inches together. Then I'm trying to reconvert the inches back to feet and inches so the output displays square feet and square inches. Problem is that's where I need guidance... If anybody knows of an easier method, I'm up for suggestions, but it has to remain as classes and functions though, that's what my professor wants.
These are the errors I get:
1: error C2664: 'Measure::Measure(const Measure &)' : cannot convert parameter 1 from 'int' to 'const Measure &' c:\users\michael\desktop\class folders\cs 1410\c ++ programs\measure\measure\measure.cpp 35 1 Measure
2: IntelliSense: no suitable constructor exists to convert from "int" to "Measure" c:\users\michael\desktop\class folders\cs 1410\c ++ programs\measure\measure\measure.cpp 35 9 Measure
#include <iostream>
using namespace std;
class Measure
{
private:
int feet;
int inches;
public:
Measure();
Measure (int f, int i) : feet(f), inches(i) { }
Measure convert(int i);
Measure area(Measure M2);
friend Measure read();
friend ostream& operator<<(ostream& out, Measure& m);
};
int main()
{
Measure M1 = read();
Measure M2 = read();
Measure M3 = M1.area(M2);
return 0;
}
Measure Measure::area(Measure M2)
{
int a1 = inches + (feet * 12);
int a2 = M2.inches + (M2.feet * 12);
return (a1 * a2);
}
Measure Measure::convert(int i)
{
Measure temp;
temp.inches = i / 144;
temp.feet = i %= 144;
return temp;
}
Measure read()
{
int feet;
int inches;
cout << "Enter the length's feet: ";
cin >> feet;
cout << "Enter the length's inches: ";
cin >> inches;
return Measure(feet, inches);
}