output

Write your question here.

#include <iostream>
using namespace std;

class Shape {
public:
virtual Shape();
virtual void draw() const = 0;
virtual void rotate(int) = 0;
private:
short x_, y_;
};

class Circle : public Shape {
public:
void draw() const;
void rotate(int);
private:
int radius_;
};

void manipulation(Shape *sp) {
draw(sp);
rotate(sp, 12);
}

enum Type { CIRCLE, SQUARE, TRIANGLE, BLOB };

struct Shape {
Type type_;
short x_, y_;
};

void draw(Shape *);
void rotate(Shape *, int);

int main() {
output please;
}
That’s not a question.
Indeed.

The class Shape; struct Shape; is an error. Two different types cannot have same identifier.
PLEASE learn to use code tags, they make reading and commenting on source code MUCH easier.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

HINT: you can edit your post and add code tags.

Some formatting & indentation would not hurt either

I'm feeling generous, your code with code tags (and some formatting to make it easier to read):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
using namespace std;

class Shape
{
public:
   virtual Shape();
   virtual void draw() const = 0;
   virtual void rotate(int) = 0;
private:
   short x_, y_;
};

class Circle : public Shape
{
public:
   void draw() const;
   void rotate(int);
private:
   int radius_;
};

void manipulation(Shape* sp)
{
   draw(sp);
   rotate(sp, 12);
}

enum Type { CIRCLE, SQUARE, TRIANGLE, BLOB };

struct Shape
{
   Type type_;
   short x_, y_;
};

void draw(Shape*);
void rotate(Shape*, int);

int main()
{
   output please;
}

Constructors are never declared virtual. Ever. Your Shape ctor is declared wrong.

This isn't complete code, it shouldn't compile even when you fix the class/struct problem, there are missing function/class method definitions all over.

Just what are you trying to do in main?
Last edited on
Just what are you trying to do in main?


I'd guess the OP is trying to learn polymorphism and hasn't yet quite understood. I'd guess in main() they'd be some code like this:

1
2
3
4
5
6
7
8
9
int main() {
    Circle c (2);
    Square s (3);
    Triangle t (3, 4);

    draw(&c);
    draw(&s);
    draw(&t);
}


but for that, there's loads of stuff missing...

Usually, you'd see this sort of thing dealing with area and perimeter etc - rather than draw and rotate.
Thanks Seeplus, keskiverto. i am just looking for a correct way to output this code.
Last edited on
What does "output code" mean?
Topic archived. No new replies allowed.