How to create programme in a ATD [closed] - c++

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 yesterday.
Improve this question
Design classes according to the task. All data of the class should be declared closed and access to them should be made through appropriate methods. Initialize the class data through the constructor. Create an array of objects (dynamically). Demonstrate the work of objects of the created class with examples.
N people live in the settlement. About each known surname, age, and gender. Enter information about the residents of this point and count the number of women and men, display information about the average age of men, print the surnames of men who have not reached the middle age
I don't know how use

Related

How to find the total numbers of object created of my class? [closed]

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.

Random object generator c++ [closed]

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
I've been working on a project that is supposed to recreate the tripulation of a plane.
I couldn't figure out how to program a key feature that I want it to have.
How can I generate a set number of objects that pick their parameters from a predefined list? For example, suppose we have the class "Passenger" which takes the parameters Name, Age, Nationality and phoneNumber. I need the program to generate, let's say 10 objects of the class passenger and take their attributes randomly from an array of 20 preset names. I know I could define 10 objects by myself, but what happens if I want to generate like 100 of them? Is there a way to do it?
Thanks in advance!
You could create a vector that contains the specified number of objects and then use a for loop to dynamically create and insert Passenger objects into that vector. For random properties, just get a random number the same size as your predefined lists and get the element at that index.

State Pattern Design using OOP [closed]

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.

C++ simple text RPG game, type of creature and quantity [closed]

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

how to define a class using c++ [closed]

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...