[try Beta version]
Not logged in

 
output

Mar 7, 2022 at 6:54am
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;
}
Mar 7, 2022 at 7:17am
That’s not a question.
Mar 7, 2022 at 8:19am
Indeed.

The class Shape; struct Shape; is an error. Two different types cannot have same identifier.
Mar 7, 2022 at 2:51pm
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 Mar 7, 2022 at 2:57pm
Mar 7, 2022 at 4:40pm
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.
Mar 8, 2022 at 3:06am
Thanks Seeplus, keskiverto. i am just looking for a correct way to output this code.
Last edited on Mar 8, 2022 at 3:06am
Mar 8, 2022 at 6:16am
What does "output code" mean?
Topic archived. No new replies allowed.