Hi I need help to draw a circle using c++. I have never used any programming before and have to do computer science to become a Maths Teacher. My first task is to write a program to draw a circle with the user inputing two x,y coordinates and the centre coordinate as well as the diameter. Then draw the cirlce and calculate distance from the two coordinates, circumference and volume of the sphere. Doing this by correspondence and can't get an answer from the lecturer. Sorry if this is really basic.

Tyra,

Folks at this site are more than happy to help. Having said that I have to tell you that they expect an attempt at coding, no matter how basic before they will help.

This seems cool. :)

I'm interested about this as well. I have absolutely no clue where to even start to approach this task, but I'll do some looking around, maybe learn something in the process. :P


Edit: Found something in google:

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)

#include "Shape.h"
#include "Circle.h"
#include <iostream.h>

// 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;
}

Hope this helps you out, although I would like an experienced user come explain this code a little bit for us newbies. :)

The above code is a c++ class for a circle. The first part is the header. The functions and data members are declared here in a public or private area of the class declaration.

The second part is the implementation of the code. Functions are defined, and the data members are manipulated as the developer wishes in order to complete the intent

Sorry I should have said I have been sitting in front of the computer for two days and every time I try to compile what I have written I get a huge list of mistakes. I have searched the web but it still doesn't work.

Post what you have and we'll have a look

...and don't wait so long next time :)

sorry, duplicate post

I can't get it to copy from xemacs to anywhere else. Thanks anyway

Drawing it how? Is this a console application or a GUI application? You haven't posted any code, so it's hard top know how to help. I know next to nothing about xemacs but if you aren't sure how to work it, you can always switch editors and do a copy and paste into here. What operating system are you using?

This article has been dead for over six months. Start a new discussion instead.