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);
}

sorry, the goal of the program is to:

multiply 2 measure objects and return a new Measure object to represent the area (144 square inches in a square foot).

Edited 6 Years Ago by rebellion346: n/a

this line Measure Measure::area(Measure M2) suggests that the area() function return a class Measure. But when you're saying:

{   
int a1 = inches + (feet * 12); 
int a2 = M2.inches + (M2.feet * 12);

return (a1 * a2);
}

You're actually returning an int. So if you change your function-prototype to int Measure::area(Measure M2), the problem should be fixed. The same goes for your convert() function.

Also, what is this line supposed to do: return Measure(feet, inches);?

Edited 3 Years Ago by pritaeas: Fixed formatting.

This article has been dead for over six months. Start a new discussion instead.