I wonder if you can clear and help me out on this matters:
Basically I need to create class scale and translate where these two classes are inheritance from transition class.
In the scale class contain e.g
Public:
scale();
~scale draw();
operator >>;
same as translate.
And the transition class contains:
protected:
vector3D vec;
Here is what I have done but does not seem right:
file: Transition.h
#define Transition_h
#include "Drawable.h"
#include "Painter.h"
class Transition : public Drawable, public Painter, public Drawable {
protected:
null vector3D vec;;
};
file:Transition.cpp
#include "Transition.h"
File:scale.h
#define Scale_h
#include "Transition.h"
class Scale : public Transition {
public:
virtual void scale();
virtual void ~scale();
virtual void draw();
virtual void operator >>;
};
File.scale.cpp
#include "Scale.h"
void Scale::scale()
{
}
void Scale::~scale()
{
}
void Scale::draw()
{
}
void Scale::operator >>
{
}
file:Translate.h
#define Translate_h
#include "Transition.h"
class Translate : public Transition {
public:
virtual void translate ();
virtual void ~translate ();
virtual void draw ();
virtual void operator >>;
};
file:Translate.cpp
#include "Translate.h"
void Translate::translate ()
{
}
void Translate::~translate ()
{
}
void Translate::draw ()
{
}
void Translate::operator >>
{
}
How can I create these classes ? Can you please assist me on this? Thanks.
Sam HobbsPosted Dec 9, 2011, 7:49 PM
You have a good start at creating an object-oriented program. I assume that most of your design is from a class and at least the class is trying to teach you how to write a good object-oriented program.You do seem to be confused about the details and I hope I can help you so that you are more able to figure it out yourself in the future.
In Transition.h, I do not know what you are trying to do with "null vector3D vec;;".
In Scale.h you are using "Scale" and "scale". Please fix the inconsistency. Also, instead of "virtual void operator >>;" you need something like "ret-type operator>>(arg-typearg);" but I do not know what ret-type and arg-type that you need. The Scale.cpp file needs corresponding modifications and the Translate.h and Translate.cpp files need similar fixes.So fix those first.
siabanie baniePosted Dec 12, 2011, 9:13 AM
But the link and page about incrementing and decrementing did not give me an output of the example? It did give me some example code and description but there is not output showing. It would be good if it tells us what the output of:
Sam HobbsPosted Dec 12, 2011, 8:45 AM
Yes!
The case matters to C++ and C#. Spelling something with a capital letter makes a different name from the name without a capital. Note that the IDE underlines "Protected" with a squigly red underline; change that to "protected" and the squigly red underline goes away. You can quickly find many errors that way.
Yes, there is a difference between the Postfix Increment and Decrement Operators: ++ and -- and the Prefix Increment and Decrement Operators: ++ and --. The documentation clearly explains the differences. They both increment or decrement a value but there is a difference in what the value of the expression is.
Try using the debugger to single-step through that code and watch what happens.
siabanie baniePosted Dec 12, 2011, 8:16 AM
Does it matter if I put it "Protected" instead of "protected"? Does it capital first letter e.g. Translate and translate make different? etc.. ?
One quick question:
What is the different between ++i and i++? For example if we have been given e.g
for (int i(0); i <10 i++) {
cout << i++;
cout << ++i;
}
Would the result be:
23568911
Can you please explain to me about these two operator as I am bit confused.
Also if we have following example:
int i(10), j(0);
while (i--)
j+=i;
What would be the value of i and j? It seems to me as it's using "while" then the loop never stop?
Sam HobbsPosted Dec 11, 2011, 10:48 PM
In Transition.h, I do not have the definition of the drawable and Vector3D classes. I assume you do and that is the important part. Note that you have "Protected" where you should have "protected".
I see you are much closer to having the operator >> methods. I also see that you are not sure if you need to use "stream" or "istream". Also note that you are using "Scale" instead of "scale". Also you need to change "Translate" to "translate".
There are other minor fixes that I am sure you can figure out.
Any more questions?
siabanie baniePosted Dec 11, 2011, 9:20 PM
I have made some adjustment on the file attached here - Including the operator. But the problem is I don't know what I shall put on the draw() - Please have a look at them and let me know what you think?
Thanks.
Sam HobbsPosted Dec 11, 2011, 2:00 PM
What do the overloaded "operator >>" need to do? If you know what it needs to do then you can determine what the parameter and return value should be.
siabanie baniePosted Dec 11, 2011, 9:58 AM
I think maybe...I can put like:
istream& operator >>(istream& a, Vector3D& at) -- or something like that.. I am not 100% sure what the operator function syntax is, will have to find out more.
Well perhaps the constructors and destructors not supposed to be void. But if you are creating a 2D vector or 3D vector which you reading all the values from the files. How you implements the scale and translate itself? Can you show me an example.
Thanks.
Sam HobbsPosted Dec 10, 2011, 10:00 PM
I still don't know what the argument and return type are supposed to be for the "operator >>". Do you know?
Note that you have "void" for constructors and destructors; that is however inconsistent with the way that constructors and destructors work. Look at the source code some more and everywhere that the IDE gives a red squigly underline try to figure out what it is trying to say. The IDE is trying to tell you where the problems are even before you try to compile the source code. You can hover the mouse over areas that the red squigly underline is shown and often there is an explanation of the problem. If you cannot figure it out then ask about it.
siabanie baniePosted Dec 10, 2011, 8:19 PM
#define translate_h
#include "transition.h"
class translate : public transition {
public:
virtual void translate ();
virtual void ~translate ();
virtual void draw ();
virtual void operator >>;
};
//File:translate.cpp
#include "translate.h"
void translate::translate ()
{
float x0, float x1, float y0, float y1, float z0, float z1
FILE *op, *ip1, *op2;
ip1 - fopen ("sample1.txt", "r");
}
void translate::~translate ()
{
}
void translate::draw ()
{
}
void translate::operator >>
{
}
siabanie baniePosted Dec 10, 2011, 5:31 PM
Thanks for your feedback, I have changed the names and attached the latest code with this attachement - please have a look.
I hope you can assist me on this.
Many thanks,
TMiB