I have a homework problem that i am stuck on. I have to create a triangle (using classes) that a user inputs the height and width. It then translates 3 times and prints the coordinates each time it translates.

This is what i have so far but am stuck.

#include <iostream>
using namespace std;

class rectangle
{
      public:
             rectangle(int x, int y, int height, int width);

};

int main()
{
    cout << "Enter two numbers for width and height"
         << " for your rectangle: \n";

         void print();
         void trans.right();
         void trans.down();
         void trans.left();

}

void rectangle :: print()
{
     cout << "The width is " << width <<endl;
     cout << " And the height is " << height <<endl;
     cout << "The origional coordinates are (0,0)";
}

void rect :: trans.right()
{
     x = x + width
     y = y + height
     cout << "The corrdinates are (" << y <<"," << x << ").\n"
          << "After the translation right.";
}

What are you stuck on? It looks like you've given up for the most part - I don't see a function definition for trans.left() or trans.down(). Also, where are you cin >> statements to bring in the data?

Well, I know they don't want us to give you a working program,
Sooooo... this should give you something to think about...
I hope it helps.

class rectangle
{
private:
int height;
int width;

public:

Rectangle();
~Rectangle();

int calculatea();
int calculatep();
};

Rectangle::Rectangle()
{
width=50;
height=85;
}
Rectangle::~calculatea()
{
return (***Your formula);
}

int Rectangle::claculatep()
{
return (***Your formula);
}

int main()
{

};

(Note: No.. It doesn't work. That's the point! Just want to get you thinking in a direction that will work...)

#include <iostream>
using namespace std;


class rectangle
{
public:
rectangle(int x, int y, int height, int width);


private:
int height;
int width;
};


int main()
{
cout << "Enter two numbers for width and height"
<< " for your rectangle: \n";
cin >> width
>> height;


void print();
void trans.right();
void trans.down();
void trans.left();


return 0;
}


void rectangle :: print()
{
cout << "The width is " << width <<endl;
cout << " And the height is " << height <<endl;
cout << "The origional coordinates are (0,0)";
}


void rectangle :: trans.right()
{
x = x + width
cout << "The corrdinates are (0 , " << x <<" ).\n"
<< "After the translation right.";
}


void rectangle :: trans.down()
{
y = y - height
cout <<"The coordinates are (" << x << "," << y <<")\n";
}


void rectangle :: trans.left()
{
cout <<"The coordinates are now ( 0 , " << y <<")\n";
}

this is what i have now and it wont compile.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.