Updates:

Pivoting content: arts and crafts, electronics, technology, and a little dose of everything else! Every Monday and Thursday (hopefully)!

Important:

Working on kyaratar.com and other projects.

C++ - Object Details X3

User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active
 

Creating an object, class, or structure in C++ (or any language actually) is fun once you understand how it works. This is essentially the building blocks to becoming a more better programmer. 


Object Details:

Object details is a program that utilizes creating your first object with some parameters. You also need to create a constructor, accessors, mutators, deconstructors, and other functions to make it a complete working object. Think of it like a person. A person is an object. Here is a drawing I made to help you understand the fundamentals of objects and what they could be associated in programming in general, not just C++. Yea lets use our favorite character from Hitman Reborn, Tsuna!

Like the image above, you can have objects with multiple parameters. You can also have objects inside objects as long as there is a function that is defined on how to read another object. An example is like you can take Tsuna, a person object, and seperate each body part as their own object. Then you can have like a head, arm, body, and leg object with their own parameters and functions.


Video Demonstration:

Here is an old video of me with a demonstration of a simple object application in C++.


Code Explanation:

The code is broken up into different parts. Header files are usually for defining and prototyping objects and functions. Then the main.cpp file is where the main actual program will run code. By seperating your code in parts, it is more easier to organize your work so you don't have to scroll and look through many lines of code at a time. When creating multiple objects, you should seperate those functions and such into different files and include them altogether into your main file.


Code:

The code is broken up into 3 files.

Driver.cpp

Show Code

Hide Code

 

Sphere.cpp

Show Code

Hide Code

 

Sphere.h

Show Code

Hide Code


Have Fun:

That's all there is for this article. If you have any questions or comments go ahead and do so below or in the video.

Tags: Computer Science, C++

Comments powered by CComment