When should you use #include “example.h” in a C++ project? [duplicate]
This question already has answers here: Resolve build errors due to circular dependency amongst classes (12 answers) Closed 15 days ago. I am working on a project that works with linked lists. I was running into some issues that I eventually traced back to the fact that I had circularly placed #include statements (ie. header […]
‘self’ or ‘this’ reference oop functionality in PLAIN C
I’m using pseudo oop paradigm with plain c, and would like to be able to have a struct function pointer have access to the rest of the structure data.
Can you give me an idea on how to solve the following task related to OOP in C++?
Define a class for a directed graph representing a traffic network. The types of nodes are: 1) location nodes, such as cities, parking lots, etc.—anything that can serve as a starting point or destination for a drive, 2) road nodes, which represent a road or road segment, in one direction, between exactly two nodes in the graph, and 3) intersection nodes, which can connect multiple roads. For each road node, the following data is stored: 1) the road length in meters, which determines the weight between the nodes that the road node connects, 2) the maximum allowed speed on the road, and 3) the maximum number of vehicles on the road. Road nodes are connected to intersection nodes, so road nodes that have a directed connection to an intersection node are considered incoming nodes, while road nodes to which the intersection node has directed connections are considered outgoing nodes. In this context, for each pair of incoming and outgoing nodes, it is defined whether it is possible to move from that incoming node to that outgoing node, the distance in meters that needs to be covered, and the average speed of vehicles, which depends on the current number of vehicles at the intersection. Additionally, it should be possible to specify the maximum allowed number of vehicles at the intersection. Serialization and deserialization of the traffic network graph should be enabled.
Define a class that represents vehicles. A vehicle moves from one location to another. Each vehicle has a defined average speed that it tends to maintain on the road, with the actual speed of the vehicle at any given time being limited by the maximum speed allowed on the road segment. It should be possible to calculate the best route for the vehicle through the traffic network, in order to minimize either the distance traveled or the time spent, taking into account the road lengths and speed limits on the road.
Safe encapsulation for many variables C++
I rewrote my blackjack game in C++ to take more of an OOP approach. One thing I know for sure is that class variables aren’t meant to be public for safety reasons and if the variable is needed standalone, you are supposed to create getters and setters for it. The problem is that my code in main.cpp
uses these variables too often. Besides there are so many of them, that setting up every one of them, would be – well – annoying.
Sources/books to improve C++ DSA knowledge and writing better code
basically, I had an OOP assignment to develop a student management system but with restrictions like using arrays only and no built in functions or Standard Library. I want to know that how can I improve my code with better programming practices if there were no restrictions
C# Class – is it OK to do all the work in the constructor?
My background is not in OOP so I would like a bit of advice please regarding a better structure for a couple of ‘modules’ I have written.
What about association in c++
I don’t understand the concept of association in C++
How to share the A::a value to the other class B::b, if in A class i have class B object
So, I’m creating the c++ project and I’ve encountered a new problem.
And the question is: How i can get the A::a value in efficent way.
I will mention that class A is pretty big and i dont want to get the A class obj.
Here’s the simplified version of the problem:
should really need to extract the member to another class
I have several classes for draw chart,
Generate random value for pokemon(object) like strength then display that value in a textbox and have the option to add this pokemon to a listbox
I want to generate a pokemon with strength(random number 1-1000) and name(random name) in 2 textboxes and all while doing this making the pokemon into an object then i want the option to add the generated pokemon object to a listbox. I want to use 2 buttons one for generating objects the other for adding the generated pokemon to a listbox.