Witam,
mam do zrobienia programik który jest jakby kontynuacją tego w tym temacie.
Opis wygląda tak:
Ćwiczenie jest kontynuacją zadania z klasą Image. Proszę napisać abstrakcyjną klasę Shape
oraz pochodne od niej klasy Rectangle, Square oraz Circle. Hierarchia klas przedstawiona
jest poniżej:
Shape
^
/ \
/ \
Rectangle Circle
|
Square
Na ocenę 4:
Klasa Shape ma mieć czysto wirtualną funkcję składową draw oraz wirtualny destruktor.
Funkcja draw jako argumenty przyjmuje obraz na którym ma pracować oraz odcień szarości
jakim ma narysować daną figurę (możliwe są inne warianty rozwiązania):
void draw(Image& image, byte grayLevel)
Przykładowy efekt działania programu:
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . r r r r r r r r r r . . . . . . . . . . . . . . . . . .
. . r r r r r r r r r r . . . . . . c c c c c . . . . . . .
. . r r r r r r r r r r . . . . c c c c c c c c c . . . . .
. . r r r r r r r r r r . . c c c c c c c c c c c c c . . .
. . r r r r r r r r r r . . c c c c c c c c c c c c c . . .
. . . . . . . . . . . . . c c c c c c c c c c c c c c c . .
. . . . . . . . . . . . . c c c c c c c c c c c c c c c . .
. . . . . . . . . . . . c c c c c c c c c c c c c c c c c .
. . . . . . . . . . . . c c c c c c c c c c c c c c c c c .
. . s s s s s s s . . . c c c c c c c c c c c c c c c c c .
. . s s s s s s s . . . c c c c c c c c c c c c c c c c c .
. . s s s s s s s . . . c c c c c c c c c c c c c c c c c .
. . s s s s s s s . . . . c c c c c c c c c c c c c c c . .
. . s s s s s s s . . . . c c c c c c c c c c c c c c c . .
. . s s s s s s s . . . . . c c c c c c c c c c c c c . . .
. . s s s s s s s . . . . . c c c c c c c c c c c c c . . .
. . . . . . . . . . . . . . . . c c c c c c c c c . . . . .
. . . . . . . . . . . . . . . . . . c c c c c . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Shape
Rectangle Circle
Square
Na ocenę 5:
Klasa Shape ma mieć dodatkową wersję funkcji draw rysującą figurę oraz jej krawędź innymi
odcieniami szarości. Funkcja ta będzie więc pobierała dodatkowy argument – odcień szarości
krawędzi (możliwe są inne warianty rozwiązania):
void drawWithBorder(Image& image, byte grayLevel, byte
borderGrayLevel)
Przykładowy efekt działania programu:
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . * * * * * * * * * * . . . . . . . . . . . . . . . . . .
. . * r r r r r r r r * . . . . . . * * * * * . . . . . . .
. . * r r r r r r r r * . . . . * * c c c c c * * . . . . .
. . * r r r r r r r r * . . * * c c c c c c c c c * * . . .
. . * * * * * * * * * * . . * c c c c c c c c c c c * . . .
. . . . . . . . . . . . . * c c c c c c c c c c c c c * . .
. . . . . . . . . . . . . * c c c c c c c c c c c c c * . .
. . . . . . . . . . . . * c c c c c c c c c c c c c c c * .
. . . . . . . . . . . . * c c c c c c c c c c c c c c c * .
. . * * * * * * * . . . * c c c c c c c c c c c c c c c * .
. . * s s s s s * . . . * c c c c c c c c c c c c c c c * .
. . * s s s s s * . . . * c c c c c c c c c c c c c c c * .
. . * s s s s s * . . . . * c c c c c c c c c c c c c * . .
. . * s s s s s * . . . . * c c c c c c c c c c c c c * . .
. . * s s s s s * . . . . . * c c c c c c c c c c c * . . .
. . * * * * * * * . . . . . * * c c c c c c c c c * * . . .
. . . . . . . . . . . . . . . . * * c c c c c * * . . . . .
. . . . . . . . . . . . . . . . . . * * * * * . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Wskazówki:
- Przed narysowaniem figur geometrycznych należy zdefiniować parametry figury
niezbędne do jej narysowania (np. współrzędne położenia figury w obrazie, promień
koła czy szerokość boków prostokąta itp.). Parametry te można podać w konstruktorze
figury (możliwe są też inne warianty rozwiązania).
Trochę się porozjeżdżało ale jak sie skopiuje do notatnika to powinno być dobrze widać.
Napisałem taki szkielet i nie wiem czy dobrze.
Shape.h
#ifndef _Shape_hpp_
#define _Shape_hpp_
#include <iostream>
using namespace std;
typedef unsigned char byte;
class Shape
{
public:
void draw(Image& image, byte grayLevel) = 0;
virtual ~Shape();
void getX();
void getY();
protected:
byte x,y; // x,y - współrzędne
}
class Rectangle : public Shape
{
public:
void draw(Image& image, byte grayLevel);
private:
byte width;
byte height;
}
class Square : public Rectangle
{
public:
void draw(Image& image, byte grayLevel);
private:
byte width;
}
class Circle : public Shape
{
public:
void draw(Image& image, byte grayLevel);
private:
byte radius;
}
#endif /*_Shape_hpp_*/
Bardzo proszę o pomoc.