![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 810
Rep Power: 4
![]() |
What error?
You need to post the actual error that the compiler gives you and also post your current code. |
|
|
|
|
|
#12 |
|
Hobbyist Programmer
Join Date: Mar 2006
Posts: 115
Rep Power: 3
![]() |
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. |
|
|
|
|
|
#13 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 810
Rep Power: 4
![]() |
Oh well, if you edit your post, I'll edit mine.
You still have this in class Screen //friend class Rectangle; With this code in Rectangle:draw: object.pixels[x1][y1]; // you said it does not make sense object.pixels[x1][y1] = 'x'; Last edited by The Dark; Oct 27th, 2006 at 2:29 AM. Reason: Parent Post Changed |
|
|
|
|
|
#14 |
|
Hobbyist Programmer
Join Date: Mar 2006
Posts: 115
Rep Power: 3
![]() |
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.
|
|
|
|
|
|
#15 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 810
Rep Power: 4
![]() |
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');
}
} |
|
|
|
|
|
#16 |
|
Hobbyist Programmer
Join Date: Mar 2006
Posts: 115
Rep Power: 3
![]() |
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. |
|
|
|
|
|
#17 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 810
Rep Power: 4
![]() |
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) |
|
|
|
|
|
#18 |
|
Hobbyist Programmer
Join Date: Mar 2006
Posts: 115
Rep Power: 3
![]() |
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. |
|
|
|
|
|
#19 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 810
Rep Power: 4
![]() |
Edit - oops pressed the save button twice.
Good job, hope it works for you. |
|
|
|
|
|
#20 |
|
Hobbyist Programmer
Join Date: Mar 2006
Posts: 115
Rep Power: 3
![]() |
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? |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |