Advertisement

07.29.2004 at 08:32AM PDT, ID: 21075774
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.4

Drawing Shapes

Asked by sytay in Miscellaneous Programming

Tags:

Hi,

I can run the program succefully but can't make it stop at the screen. It only pop out 1 second.
Please help !

#include<iostream.h>
#include<conio.h>
//#include<Shape.h>
//#include<Rectangle.h>
//#include<Circle.h>

//Shape Class (Shape.h)
class Shape {

public:
Shape(int newx, int newy);
int getX();
int getY();
void setX(int newx);
void setY(int newy);
void moveTo(int newx, int newy);
void rMoveTo(int deltax, int deltay);
virtual void draw();

private:
int x;
int y;
};
//Shape Implementation (Shape.cpp)


// constructor
Shape::Shape(int newx, int newy) {
moveTo(newx, newy);
}

// accessors for x & y
int Shape::getX() { return x; }
int Shape::getY() { return y; }
void Shape::setX(int newx) { x = newx; }
void Shape::setY(int newy) { y = newy; }

// move the shape position
void Shape::moveTo(int newx, int newy) {
setX(newx);
setY(newy);
}
void Shape::rMoveTo(int deltax, int deltay) {
moveTo(getX() + deltax, getY() + deltay);
}

// abstract draw method
void Shape::draw() {
}
//Rectangle Class (Rectangle.h)
class Rectangle: public Shape {

public:
Rectangle(int newx, int newy, int newwidth, int newheight);
int getWidth();
int getHeight();
void setWidth(int newwidth);
void setHeight(int newheight);
void draw();

private:
int width;
int height;
};
//Rectangle Implementation (Rectangle.cpp)

// constructor
Rectangle::Rectangle(int newx, int newy, int newwidth, int newheight): Shape(newx, newy) {
setWidth(newwidth);
setHeight(newheight);
}

// accessors for width and height
int Rectangle::getWidth() { return width; }
int Rectangle::getHeight() { return height; }
void Rectangle::setWidth(int newwidth) { width = newwidth; }
void Rectangle::setHeight(int newheight) { height = newheight; }

// draw the rectangle
void Rectangle::draw() {
cout << "Drawing a Rectangle at" << getX() << "," << getY() <<
"), width " << getWidth() << ", height " << getHeight() << endl;
}getch();

//Circle Interface (Circle.h)
class Circle: public Shape {

public:
Circle(int newx, int newy, int newradius);
int getRadius();
void setRadius(int newradius);
void draw();

private:
int radius;
};
//Circle Implementation (Circle.cpp)

// constructor
Circle::Circle(int newx, int newy, int newradius): Shape(newx, newy) {
setRadius(newradius);
}

// accessors for the radius
int Circle::getRadius() { return radius; }
void Circle::setRadius(int newradius) { radius = newradius; }

// draw the circle
void Circle::draw() {
cout << "Drawing a Circle at" << getX() << "," << getY() <<
"), radius " << getRadius() << endl;
}getch();
//Try shapes module (Polymorph.cpp)

int main(void) {
// set up array to the shapes
Shape *scribble[2];
scribble[0] = new Rectangle(10, 20, 5, 6);
scribble[1] = new Circle(15, 25, 10);

// iterate through the array and handle shapes polymorphically
for (int i = 0; i < 2; i++) {
scribble[i]->draw();
scribble[i]->rMoveTo(100, 100);
scribble[i]->draw();
}

// call a rectangle specific function
Rectangle *arec = new Rectangle(0, 0, 15, 15);
arec->setWidth(30);
arec->draw();
}

thanksStart Free Trial
[+][-]07.29.2004 at 09:57AM PDT, ID: 11668587

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.02.2004 at 12:35AM PDT, ID: 11691435

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Miscellaneous Programming
Tags: draw
Sign Up Now!
Solution Provided By: dkinjal
Participating Experts: 2
Solution Grade: B
 
 
[+][-]08.02.2004 at 03:57AM PDT, ID: 11692341

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-42