Can't compile right now. The project is in my home pc and I'm at work.
Cannot make newUnit as const. If I do, then the problem just moves to my code inside ConvertTo(). The line m_unit = newUnit; will fail with the same problem. And I cannot declare m_unit as const because then I cannot set it anywhere except in the constructor.
Is this one of the very few cases where const_cast<>() is the only option?
hehe, I am going to write them, yes, but once at home. I'll try to finish one or two tonight so you all can see my approach more "whole" and decide. Personally, I like it. But I cannot deny the simplicity of Computergeek01's approach, especially in the prefixes. I wouldn't commit to it right now, though, without knowing how the approach can solve other problems like "transforming" kgms^-2 to N (newtons), for example.
So, what I'm saying is: I don't think there is an agreement as to which route to take right now.
class Temperature
{
private:
double temp#1 ;
double temp#2 ;
public:
//here's part I need help on. What should we make it do? How should we use the function in the Dimension class here?
} Fahrenheit, Celsius, Kelvin ;
//NOTES:
//could do things in Kelvin and say stuff using
Kelvin.temp#1 ;
//and another thing of course is to input temp
cin>> Kelvin.temp#1 ; //is this how you say it
cin.get(Kelvin.temp#1) ; //or like this is this even correct?
@mcqueen Earlier on there was an explosion of posts on this thread while I was sleeping, so if I'm honest I cannot suggest how to integrate your class with webJose's ideas, as I haven't closely read a lot of the middle pages of this thread yet :L
However, I can provide some general tips for your class :)
You have defined two variables called temp#1 and temp#2 . The hash character is not allowed in symbol names: you may only use alphanumeric characters and underscores.
You also try to access the variables temp#1 and temp#2 from outside the class, but you have declared them as private, so only member functions of the class itself may access them.
If you want to make them available to code outside the class, consider using getter and setter methods:
class Class {
double var;
public:
double GetVar() { return var; }
void Setvar(double d) { var = d; }
};
[/code]
Finally, the line Kelvin.temp#1;
does nothing. I'm not sure what you are trying to achieve here, though, anyway...
What is your plan with giving Temperature two variables? If you explain your thought process, it will be easier for us to discuss your ideas :)
class Temperature
{
public:
double temp_no_1 ;
double temp_no_2 ;
int time ;
//how do we use the dimensions class function(s) here?
} Fahrenheit, Celsius, Kelvin ;
Ok, to be trueful, as said I feel I've contributed nothing to this project. I also feel stupid, like I know nothing, although I do know C++. How can I help??? (Something easy to start with please)
Finishing the tutorial on here is a good start. From there, start making a program *you* want to make, and if there is some part you don't know how to do, go research it. Repeat until you are done. Then, go start another, harder project and repeat forever.
template<temperature>
double temp_no_1, temp_no_2 ;
cout<<"Enter two temps: " ;
cin>> temp_no_1 ;
cin>> temp_no_2 ;
class Temperature
{
public:
//functions which we will need group to come up with and I actually need help with that part anyway
} Fahrenheit, Celsius, Kelvin ;
string temptype ;
cout<<"Enter temp type: " ;
cin>> temptype ;
if (temptype=Fahrenheit)
{
//functions
cout<<"in Fahrenheit" ;
}
if (temptype=Celsius)
{
//functions
cout<<"in Celsius" ;
}
if (temptype=Kelvin)
{
//functions
cout<<"in Kelvin" ;
}
Thanks firedraco! I recently joined the Forum and that's the best tip I've gotten! Thank you! Only thing is, I'm best at shorter programs that involve class, enum, etc. I'm not great at using them when there used in long projects like this one? Do you have a tip for that?
hehe, mcqueen, I told you it was no easy task. But don't feel stupid, you are just not experienced enough.
I do believe that you need to develop some more skills and practice abstraction. Abstraction in OOP is the ability to take a problem (to be solved by your software) and "objectify" it into classes and a workflow. More specifically, you are usually given a problem in the form of an objective or objectives + some inputs. The objectives are also referred to as requirements. Once your abstraction ability is good enough, ideas start flowing more easily.
BUT, be sure that you can only exercise so much abstraction if you don't know the full capabilities of the language. As firedraco states, you should cover all of C++, and then practice all features. Not so long ago I was a complete idiot in C++ myself.
If you like, we can suggest you more appropriate coding projects if you feel this one is over your head. Let us know your interests.
Ok, update on this project on my side: Singletons seem to work OK; same goes for the functor, but I am having a bit of a problem keeping references to unit objects. I'll sort these out first before posting, because each post of code is a looooong list.
Ok, I uploaded some code here: http://ideone.com/XCVkX. The online compiler says there are errors, but I got this working in Visual Studio 2008 Pro. It says weird things, like "Length doesn't have a member called Dimension". I guess it might be a compiler setting, but I didn't find them.
Anyway, have a look. Note that I was unable for some reason to make an operator overload for operator<<(ostream&, Dimension<> const&). If any of you can tell me where I messed up, would be much appreciated. And that reminds me: To make it work as it is showing, change myHeight to myHeight.ToString() in line 567; same for doorHeight in the next line.
Darn! Nevermind about the const_cast<>. I cannot use singletons the way I wanted to because now the Unit class hold a Prefix m_prefix member field. This field is intended to be set at any moment for a specific dimension object and should affect only that object, meaning bye bye to my one-unit-fits-all feature.
I'll be changing that, meaning I will allow copies of Unit, meaning const_cast<> is irrelevant in my case now.