#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;
}
this is Circle Interface
1 2 3 4 5 6 7 8 9 10 11
class Circle: public Shape {
public:
Circle(int newx, int newy, int newradius);
int getRadius();
void setRadius(int newradius);
void draw();
private:
int radius;
};
this is Shape Class (Shape.h)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
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);
virtualvoid draw();
private:
int x;
int y;
};
and this is the final Shape Implementation (Shape.cpp)
You seem to be doing quite well. Did you post the whole question? Its just that the class Shape is not mentioned in the question, but you included it here.
Question wrote:
Define a class Circle that stores the center and radius of a circle, by keeping the numbers in a dynamically allocated array of doubles.
This is telling you specifically how to store the information in your circle. You have not done this.
In your example you are storing the centre of the circle in its parent class Shape. But that is not what the question asked you to do.
Also you are storing the radius as a member variable, not as part of the dynamic array.
So first of all this is what a "dynamically allocated array of doubles" looks like:
double* data = newdouble[3]; // [0] = x, [1] = y, [2] = r
So instead of using your base class Shape to store the x & y values I think they should go into your dynamic array. I don't think the question even asks for a Shape class (unless there is some part you didn't post).
Question wrote:
Supply the "big three" memory management functions. Use this class to demonstrate
(a) the difference between initialization
Circle s;
Circle t = s;
This is talking about what happens when the Circle is 'constructed'. This happens when you do these two things:
1 2
Circle s; // default constructor
Circle t = s; // Copy constructor
So you need to write TWO different constructors for your Circle. One with no parameters and another one taking another Circle as its parameter:
1 2 3 4 5 6 7 8 9 10
Circle::Circle() // default constructor
{
// allocate your dynamic array here
}
Circle::Circle(const Circle& c) // Copy constructor
{
// allocate your dynamic array here
// fill the array with the same values with the ones in c
}
class Circle: {
public:
Circle(int newx, int newy, int newradius);
void setRadius(int newradius);
void draw();
double* data = newdouble[3]
void setX(int newx);
void setY(int newy);
void moveTo(int newx, int newy);
void rMoveTo(int deltax, int deltay);
virtualvoid draw();
private:
int radius;
int x;
int y;
};
Nearly. But you are still using member variables in addition to your dynamic array:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
class Circle: {
public:
Circle(int newx, int newy, int newradius);
void setRadius(int newradius);
void draw();
double* data = newdouble[3] // This should be in the private section
void setX(int newx);
void setY(int newy);
void moveTo(int newx, int newy);
void rMoveTo(int deltax, int deltay);
virtualvoid draw();
private:
int radius; // do not use this, use the dynamic array instead
int x; // do not use this, use the dynamic array instead
int y; // do not use this, use the dynamic array instead
};
Also you have added a lot of functions that are not in the original question, like setX(), setY(),moveTo() etc...
To be honest the question is not too difficult if you have been taught all the elements required.
You, though, seem to be an absolute beginner to C++.
The question is clearly beyond an absolute beginner. I recommend you start learning C++ from the beginning and work your way up to the concepts this question requires.
I think we cannot allocate the memory to the data type in the deceleration of the class.
We can allocate the memory in the definition of the class.
please correct me if i am wrong.
The question is unclear. All equations with a circle are based on constants, its center, and its radius. In my opinion, it's stupid to hold the radius and center in an array of doubles, you would absolutely never do that and often people will doubt your code if they see something related to that.
1) It never said that he couldn't use extra functions.
2) double* data = newdouble[3] inside of a class declaration shouldn't work. You have to assign the variable at class construction. Even if it does, it's probably more formal to use an initialization list instead.
3) What is the point of giving instructions to do something you probably shouldn't get in the habit of? I see this all the time.
"To teach you the right thing, we're going to give you an unrealistic assignment that you'll never come across and tell you to complete the assignment in a horrible way that will make other programmers want to shank you with a USB stick. It's better for the long run."
I know that I am a beginner but for the first and last year it and learn it right on course work crashed and I can not make it if someone could help me :S I would be very grateful that my final deadline is 10,06,2010.
thanks in advance
I know that I am a beginner but for the first and last year it and learn it right on course work crashed and I can not make it if someone could help me :S I would be very grateful that my final deadline is 10,06,2010.
thanks in advance
I didn't understand everything you said here. But I think you are saying that something went wrong with your first year studies?
If that is true then you obviously have much catching up to do. But the thing is there is no point in one of us simply giving you the answer to give to your tutor.
If you are so far behind the others then, surely, your tutor needs to be aware of it? Then they can help you. But I don't see it doing anyone any good if your tutor thinks your are more advanced than you really are.
If I have misunderstood your situation, then I apologise. Your statement was not very clear.
sorry it's my mistake I mean that we study c++ only the first year and it doesn't have any connection with our spicialty we are forced to learn it for nothing and this last task is very dificult for every one of our class and for this I searched help here :)
Well, with all due respect, I don't think any learning is for nothing. If you have no genuine interest in C++ then I for one am unlikely to spend any more of my time helping you. I come here out of gratitude to the people who helped me to learn, we don't get paid for this.
So like I said I'm here to help people who want to learn. I am not here to pass someone else's coursework for them because they don't want to learn.
If you want to be able to answer the question you have been given then you are going to have to start learning C++ from the beginning. You need to get a good book and set aside enough time each week to progress. If you are going to do that then I am more than happy to help you.
And I would recommend explaining to your tutor how difficult the question is. They should be able to help you get up to speed. But you need to take a pro-active interest in this subject even if you don't feel its your vocation.
Programming is hard. Learning to program will give you invaluable skills in logic, deduction, reasoning, patience, mental acuity, mental stamina and general all round accuracy. To name but a few.
You can not fudge computer programming.
And having an appreciation of how computers actually work can't be a bad thing whatever subject you are learning in this day and age.