I'm very confused on this topic of how to structure my classes so that they all "wire together" and inherit the proper functions and data that I want them to.
I want to have a Car.c and car.h which are "wired" with body.c/body.h, which in turn is wired with a frame.c/frame.h, wheel.c/wheel.h, and driver.c/driver.h.
Each part of the car holds some type of data, mostly ints:
The car has a (total) mass and car_name. The body has a mass and color. The frame has a mass. The wheel(s) have a mass and force. [There will be 4 instances of wheel] The driver has a mass and driver_name.
Each of these functionalities must come from their respective .c and .h files, and be amalgamated in the car.c and car.h (which should contain all the functionality of its parts).
Then, in my main test program, I am to make an instance of car and hardcode in its values of: mass (which comes from the total mass of all of its parts, this is where i start to lose it. How will I access its parts' masses in the test program?), color (a character array), current position (an integer), current velocity (an integer), and current acceleration (which comes from the total newton force of the 4 wheels, again this is where I start to get very confused).
(Then in the test program I am to print out a simulation of this car over a period of 100 seconds, and show its position, velocity, and acceleration at each point (based on the mass, total newton force, and starting position). This part is of course a simple while loop, and is somewhat trivial.)
I am somewhat confused/lost all around, and I am making a list of questions to ask my teacher today after class, and I have been posting online (to no avail, yet) for help on this program. I have a strong desire to learn this stuff, but it does not come easily for me.
From what I understand, I will need to allocate memory for all of the data each class holds. Then, using function pointers, as well as #include "X.h" , I will need to somehow link up all of the classes together so that car has access to all of the parts' functions which set, for example, the newton force of each wheel. To be honest, this is about the extent of my knowledge. I have no idea how to actually implement these ideas, let alone the syntax to do so.
We have learned a slight bit about structs, malloc, sizeof, and pointers, but I have not used them to link functionality or data from separate classes together ever before in my life. (I feel that my teacher is competent, but he took a big difficulty jump on this lab assignment. We really have not even discussed function pointers yet in class for more than 5 minutes. I am both frustrated but highly intrigued to find out how this stuff works. I know object orientation in C is the basis for most modern programming.)
LUCKILY, my teacher did give us an example of a simple program structure based on 2 .c and .h files. It has a person.c/person.h and employee.c/employee.h, and, of course, employee inherits some of the data and functionality of person (like the name). I can post some of the code, here, if that helps anyone understand what I'm talking about.
I will be very greatful if anyone here can give me help on this project. I've been working on it for no less than 12 hours thus far (and I haven't even started debugging, yeesh) , and i KNOW it is not that hard of a lab and does not deserve this much time.