Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: OOP w C++[problem ze skryptem]
Forum PHP.pl > Inne > Hydepark
matys
Napisałem skrypt w C++ oparty o OOP, który liczy pole prostokąta, którego długości boków z góry s ustalone.
Oto kod:
Kod
#include <iostream>

class Point       //klasa przechowująca współrzędne x i y

{

  public:

   void SetX(int x) {itsX=x;}

   void SetY(int y) {itsY=y;}

   int GetX() const {return itsX;}

   int GetY() const {return itsY;}

  private:

   int itsX;

   int itsY;

  };              //koniec klasy przechowujacej wspolrzedne

  

  class Rectangle    //klasa tworząca prostokąt

   {

    public:

     Rectangle(int top, int bottom, int left, int right);

     ~Rectangle(){}

    

     int GetTop() const {return itsTop;}

     int GetBottom() const {return itsBottom;}

     int GetRigth() const {return itsRight;}

     int GetLeft() const {return itsLeft;}

    

     Point GetUpperLeft() const {return itsUpperLeft;}

     Point GetLowerLeft() const {return itsLowerLeft;}

     Point GetUpperRight() const {return itsUpperRight;}

     Point GetLowerRight() const {return itsLowerRight;}

    

     void SetUpperLeft(Point Location) {itsUpperLeft=Location;}

     void SetLowerLeft(Point Location) {itsLowerLeft=Location;}

     void SetUpperRight(Point Location) {itsUpperRight=Location;}

     void SetLowerRight(Point Location) {itsLowerRight=Location;}

    

     void SetTop(int top) {itsTop=top;}

     void SetBottom(int bottom) {itsBottom=bottom;}

     void SetLeft(int left) {itsLeft=left;}

     void SetRight(int right) {itsRight=right;}

    

     int GetArea() const;

    

    private:

     int itsTop, itsBottom, itsLeft, itsRight;

     Point itsUpperLeft;

     Point itsLowerLeft;

     Point itsUpperRight;

     Point itsLowerRight;

    

    };

    //koniec naglowka



Rectangle::Rectangle(int top, int left, int bottom, int right)

{

  itsTop=top;

  itsBottom=bottom;

  itsLeft=left;

  itsRight=right;

  

  itsUpperLeft.SetX(left);

  itsUpperLeft.SetY(top);

  

  itsUpperRight.SetX(right);

  itsUpperRight.SetY(top);

  

  itsLowerLeft.SetX(left);

  itsLowerLeft.SetY(bottom);

  

  itsLowerRight.SetX(right);

  itsLowerRight.SetY(bottom);

}



//obliczanie pola prostokata

int Rectangle::GetArea() const

{

  int Width=itsRight-itsLeft;

  int Height=itsTop-itsBottom;

  return(Width*Height);

}



using namespace std;



int main()

{

  //lokalna zmienna typu Rectangle

  Rectangle MyRectangle(100, 20, 50, 80);

  int Area =MyRectangle.GetArea();

  cout << "Pole prostokąta wynosi: " << Area << "n";

  

  system("PAUSE");    

  return 0;

}

Jednak wyświetla mi błędy:
Kod
86 C:Documents and SettingsMateuszPulpitC++main.cpp

`Rectangle' undeclared (first use this function)

86 linijka:

Rectangle MyRectangle(100, 20, 50, 80);

Chciałem tu stworzyc zmienną typu Rectangle

i kolejny błąd:
Kod
87 C:Documents and SettingsMateuszPulpitC++main.cpp

`MyRectangle' undeclared (first use this function)

87 linijka:

int Area =MyRectangle.GetArea();
FiDO
Jakis dziwny kompilator masz.. u mnie to dziala.

edit:
gcc (GCC) 3.3.1 (mingw special 20030804-1) smile.gif
rachwal
Dokladnie, u mnie tez OK.
Kompilowalem na :
Cytat
gcc version 2.95.4 20011002 (Debian prerelease)
Jojo
Przykro mi to mówić ale sprawdziłem na Borland C++ Builder 6.0 oraz Microsoft Visual C++ 6.0 i wszystko kompiluje się i uruchamia bez problemów.
Napisz może jakiego kompilatora używasz.
matys
Ja uzywam Dev-C++4.9.8.0

Edit:
Visual C++ tez mam i oto komunikat z kompilacji:
Kod
Compiling...

mn.cpp

c:documents and settingsmateuszpulpitprogramowanie_w_c++_dla_windows'assdsdmn.cpp(1) : error C2501: 'Kod' : missing storage-class or type specifiers

c:documents and settingsmateuszpulpitprogramowanie_w_c++_dla_windows'assdsdmn.cpp(1) : error C2239: unexpected token ':' following declaration of 'Kod'

d:program filesmicrosoft visual studiovc98includeerrno.h(29) : error C2059: syntax error : 'extern '

Error executing cl.exe.



ssdsd.exe - 3 error(s), 0 warning(s)


EDIT:
[b]Jednak wszystko juz działawinksmiley.jpg
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.