Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 27th, 2006, 2:05 AM   #11
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 810
Rep Power: 4 The Dark is on a distinguished road
What error?
You need to post the actual error that the compiler gives you and also post your current code.
The Dark is offline   Reply With Quote
Old Oct 27th, 2006, 2:10 AM   #12
brad sue
Hobbyist Programmer
 
Join Date: Mar 2006
Posts: 115
Rep Power: 3 brad sue is on a distinguished road
the compiler error is:
In member function `void Rectangle::draw(Screen&)': 
`char Screen::pixels[20][30]' is private


I dont know how to get rid of it. I cannot make my pixels public member:It is imposed
here is the actual code:
class Rectangle;
    // class screen
   class Screen
   {
         private:
                 char pixels[20][30];
         public:
                //friend class Rectangle; 
                Screen(void);
                ~Screen(void);
                void setPoint(const Point&,char);
                void draw(void);
   };

// implementation of screen class

   Screen::Screen()
   {
         int i,j;
         for(i=0;i<20;i++){
             for(j=0;j<30;j++){
                 pixels[i][j]='.';}}
   }             
      
   Screen::~Screen(){}
   
   void Screen::setPoint(const Point & object, char c)
   {
        int i=object.getX();
        int j=object.getY();
        
        pixels[i][j]=c;
   }          
                 
   void Screen::draw()
   {
        for( int i=0;i<20;i++)
            {for( int j=0;j<30;j++)
                 {cout<<pixels[i][j];}
                 cout<<endl;
                 }
   }           
    
    
    class Rectangle{
         
          private:
                  int height;
                  int width;
                  Point upLeft;// upper left corner of a rectangle
                  char Paint;
          public:
                 friend class Screen;
                 Rectangle(void);
                 Rectangle(const Point&,int,int,char);
                 ~Rectangle();
                 void set(const Point&,int,int,char);//set values of existing rectangle
                 void setPaint(char);
                 void setPoint(const Point&);//sets upper left corner of rectangle
                 void setPoint(int, int);//sets upper left corner of rectangle
                 void setSize(int,int);//sets height and width
                 int getX(void)const;//Return upp left corners' x coordinate
                 int getY(void)const;//Return upp left corners' y coordinate
                 int getWidth(void)const;
                 int getHeight(void)const;
                 char getPaint(void)const;
                 void draw(Screen&);//prints contents of rectangle on screen
};
   // implementation class Rectangle
   
   Rectangle::Rectangle()
   {
          height=1;
          width=1;
          Paint='*';
   }
   Rectangle::~Rectangle()
{
}
   
  //paramerized constructor
   /*Rectangle::Rectangle(const Point& object,int h,int w,char c) : set(object, h, w, c) {}*/
   Rectangle::Rectangle(const Point& object,int h,int w,char c) : upLeft(object),height(h),width(w),Paint(c){}
   
   
   void Rectangle::set(const Point& object,int h,int w,char c)
   {
          
        upLeft=object;  
        height=h;
        width=w;
        Paint=c;
   }
   
   void Rectangle::setPaint(char e)
   {  
        Paint=e;
   }
   
   void Rectangle::setPoint(const Point& object)
   {  
        upLeft=object;
   }
   
    
     void Rectangle::setPoint(int x,int y)
   {  
       upLeft.setPoint(x,y);
   }
    
    
     int Rectangle::getX()const// to check
     {
         upLeft.getX();
     }
             
     int Rectangle::getY()const
     {
         upLeft.getY();
     }                


     int Rectangle::getWidth()const
     {
         return width;
     }
     
     int Rectangle::getHeight()const
     {
         return height;
     }
     
     char Rectangle::getPaint()const
     {
          return Paint;
     }
     
          
          
     void Rectangle::draw( Screen&  object//prints contents of rectangle on screen object
     {
          
          int x1=upLeft.getX();
          int y1=upLeft.getY();
          for(int i=x1;i<(x1+width);i++)
             for(int j=y1;j<(y1+height);j++)
                 object.pixels[x1][y1]; // you said it does not make sense
                
      }

Last edited by brad sue; Oct 27th, 2006 at 2:21 AM.
brad sue is offline   Reply With Quote
Old Oct 27th, 2006, 2:17 AM   #13
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 810
Rep Power: 4 The Dark is on a distinguished road
Oh well, if you edit your post, I'll edit mine.

You still have this in class Screen
//friend class Rectangle;
This need to be uncommented, it doesn't do anything while commented out.

With this code in Rectangle:draw:
                 object.pixels[x1][y1]; // you said it does not make sense
What do you want this line to do? It is not assigning anything, and it is not testing anything. I assume you want something like:
                 object.pixels[x1][y1] = 'x';

Last edited by The Dark; Oct 27th, 2006 at 2:29 AM. Reason: Parent Post Changed
The Dark is offline   Reply With Quote
Old Oct 27th, 2006, 2:25 AM   #14
brad sue
Hobbyist Programmer
 
Join Date: Mar 2006
Posts: 115
Rep Power: 3 brad sue is on a distinguished road
I am sorry for the misunderstanding. I made all the changes you suggested me in my last post. Now the only problem is the one I just posted above.
brad sue is offline   Reply With Quote
Old Oct 27th, 2006, 2:33 AM   #15
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 810
Rep Power: 4 The Dark is on a distinguished road
See my edit to my previous post.

You might find it better all round to use the Screen's public setPoint function, rather than mucking about making things friends. Then you just make Rectangle::draw something like:
     void Rectangle::draw( Screen&  object)//prints contents of rectangle on screen object
     {
          
          int x1=upLeft.getX();
          int y1=upLeft.getY();
          for(int i=x1;i<(x1+width);i++)
             for(int j=y1;j<(y1+height);j++)
             {
                 Point point(x1,y1);
                 object.setPoint(point, 'x');
             }                
      }
If you are doing this for a class, then I would imagine that is what they would want you to do.
The Dark is offline   Reply With Quote
Old Oct 27th, 2006, 2:39 AM   #16
brad sue
Hobbyist Programmer
 
Join Date: Mar 2006
Posts: 115
Rep Power: 3 brad sue is on a distinguished road
In the program, we have 2 draw function one in Rectangle and one inScreen.

We are are looking at the drwas in rectngle. It is supposed to "print the content ot the rectangle on the screen object"
The way I understand, I need to store the rectangle (filled with Paint)
in the pixels[x][y];

And the function draw in Screen will print the rectangle on the monitor.

after storing the rectangle the Sreen::draw() should display something like:

AAAAAAA
AAAAAAA
AAAAAAA
AAAAAAA

if 'A' is the paint of the rectangle.
brad sue is offline   Reply With Quote
Old Oct 27th, 2006, 2:48 AM   #17
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 810
Rep Power: 4 The Dark is on a distinguished road
Yes, thats the way it looks like it should work.
I think the setPoint function in Screen is the way the Rectangle::draw function should be changing the Screen object's "pixels" array values. See the previous post for the code (replace 'x' with paint)
The Dark is offline   Reply With Quote
Old Oct 27th, 2006, 2:49 AM   #18
brad sue
Hobbyist Programmer
 
Join Date: Mar 2006
Posts: 115
Rep Power: 3 brad sue is on a distinguished road
It compiles well (with Paint included). Now I need to see if it does what I need.
I will log out now I get some sleep.
Thank you indeed Dark.
brad sue is offline   Reply With Quote
Old Oct 27th, 2006, 2:50 AM   #19
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 810
Rep Power: 4 The Dark is on a distinguished road
Edit - oops pressed the save button twice.

Good job, hope it works for you.
The Dark is offline   Reply With Quote
Old Oct 27th, 2006, 5:39 PM   #20
brad sue
Hobbyist Programmer
 
Join Date: Mar 2006
Posts: 115
Rep Power: 3 brad sue is on a distinguished road
HI, I tested the functions with the following main:
int main()
{
    Screen ecran;
    Point p1(2,4);
    Rectangle rect0(p1,3,7,0);
    
    Point p2(7,7);
    Rectangle rect1(p2,3,7,1);
   
    Point p3(12,3);
    Rectangle rect3(p3,3,24,3);
    
    Point p4(2,18);
    Rectangle rect4(p4,16,5,4);
    
    rect0.draw(ecran);
    rect1.draw(ecran);
    rect3.draw(ecran);
    rect4.draw(ecran);

    ecran.draw();

    cin.get();
    return 0;
}

On the output, the program does not display the rectanles, but
marks the starting point (upper left corner) with totally random characters ( like heart or blank, diamond...)
It does not get the paint character.

the output should be like overlapped rectangle filled with numbers.
The function Rectangle::draw() seems fine to me.
Can you see what is wrong?
brad sue is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C# corruption!!! Kilo C++ 32 May 21st, 2006 8:44 PM
Masm rsnd Assembly 4 May 20th, 2006 9:05 PM
libraries matko C 1 Jan 22nd, 2006 2:12 PM
HELP please!!! hamacacolgante C 7 Nov 21st, 2005 5:36 AM
New to Java - Compiling Error Kiwwa Java 4 Jun 16th, 2005 10:25 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:38 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC