Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I need to define a class to hold stock data in c++. At minimum it needs a method for "meanvalue", a method for "vairance", and properties for "trading volume" and other historical data.
Here's a start:
class Stock
{
public:
Stock();
~Stock();
int MeanValue();
int Variance();
private:
int mMeanValue;
int mVariance;
};
I'll leave the implementation of the methods in this class up to you.
You'll probably want to have a name property, and perhaps an exchange property, method to handle updates to specific things like volume, quotes, trade prices, etc. You can do this with key/value pairs or define methods for each.
For things like variance and history, you will have to have methods that are triggered by the updates so you can change the calculated values.
You really should consider showing us what you have, then we'll be more likely to help...
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
For example, I have my class employee. I want to keep record how many employees till date have worked for me. I can make static count variable and add 1 in my constructor. But whenever my temporary object will be created when we pass object in parameters or return object of our class it will add for them too.
Static class member is the right way to go. A few things to be careful about:
Make sure you overload all constructors. The ones you don't want to support you should explicitly delete.
Don't forget to decrement in destructor.
If this program of yours is multithreaded then use atomic_uint or provide locking mechanism of your own.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
A simple example of how you would structure this would be particularly useful.
This is how I would do it:
MyMotor is an instance of the class Motor. This class has four functions idle(), accelerate(), flat(), decelerate(). (I assume you know how to build a basic class with private members and its constructors)
Then in main(), I create MyMotor and control it based on states. States can be controlled/monitored using Boolean Values. Whatever state I am in and whenever, certain function will be called.
Next time give it a try before you ask here, in order to get better responses.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
So pretend I'm developing a car class and I want one of the car class's functions to return a list of passengers, except I'd like to put a list reference as an argument and just set that list instead of returning a list.
void GetPassengerList(PassengerList &passengerList); //sets the list
I don't know if I should call it GetPassengerList or SetPassengerList, or something else. I feel like using the words get / set make it seem like there is a private variable that is being manipulated like the typical getter / setter methods. What's a good naming convention to use here?
In our team for input/output arguments we either use
void AdjustPassengerList(PassengerList&);
or
void AddPassengersTo(PassengerList&);
Depending on the use-case. For example the first one could be used if you want a list created from more than one car. The second usually reads well in code, something like:
car.AddPassengersTo(list);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
So i've been learning c++ through www.learncpp.com/c++ primer and through the power of google for a while now and my goal has always been to make an RPG of some sort, even if it's a text based one.
Currently with my limited knowledge i'm trying to make a system that stores items/weapons/characters/spells/stats/etc.
I know that structs have public variables by
default and classes have private variables by default.
I also know that they all store data
Only thing i don't know is what's the difference between all 3 of them and when i should be using each one.
Modern C++ treats structs and classes the same, the only difference is that structs default to public while classes default to private. They are basically collections of data with associated functionality.
For example
class Player
{
private:
int health;
int attack;
public:
void calculateHealth(int healthChange);
}
Enums are basically named numbers, for example:
enum Months {January=1, February=2 ...}
So now instead of saying if currentMonth == 3 you can say if currentMonth == Months.March
Enums make the code easier to follow.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have just started writing simple RPG game in C++. There will be a class (schema, not code)
class creature
string name;
int hp, strength...
There will also be quantity of them. But if I want to create two groups of same type creature, example: ('a', 100, 10)', it would be wasting of time and memory to make them separately, writing name and all other parameters two times, with only quantity being different. Do you know any method to implement quantity of creatures stacks, without necessity to repeat data?
Because I have just started working, I will be trying to do something and tell you about results.
How about wrapping it in a class that represents quantity as well?
What I mean is
class CreatureGroup {
Creature creature;
int quantity;
};