how to set values for objects, dynamically? I want to take in number of students records to hold from user and set these values, can you show how?
@AntonieSmithVideos3 жыл бұрын
I need you to first explain what you mean by setting the values of an object dynamically. When the object of type certain class has been created you want the private variable to be set to default values? You can look at the video of the constructor. You can also overload the constructor function to take parameters if need be. This will enable you to set private variables to specific values when the object is instantiated. Hope this helps.
@dudewheresmycar36182 жыл бұрын
How would I ask the user for input instead of hardcoding the name and student number Thanks
@AntonieSmithVideos2 жыл бұрын
Easily by using the cin function. Main Function: Student Student1; string name_input; cout > name_input; Student1.setName(name_input);
@eddys2007yt3 жыл бұрын
good brother... your explanation (set/get) is done in (main). what if (set) is done by (main) and (get) is done by another class. I try always empty. help-help.
@AntonieSmithVideos3 жыл бұрын
Hi Eddy, I don't know if I understand your question correctly. But here goes. When we have a class with functions (normally public) and variables (normally private), we want to interact specifically. If one class would call a get function of another class it will create a problems. Because, what if the class you are calling is not instantiated (object of type class). You cannot call functions in a class if there is no object. Analogy: Class = House Plan Object = Physical house built on the plan If the object you are calling from instantiated another object within itself, thats not a problem. But it a normal sense, rather stay away from classes calling other class functions.
@RedSparrow_FREEDOM2 жыл бұрын
why have you started with public? it is private by default so you can start without say private and later ypu can put public?!!!
@AntonieSmithVideos2 жыл бұрын
You are correct that member variables and functions are by default private. Maybe should have started with private and then public. I think it is just better to state explicitly that member variables/functions are either private or public. Will avoid confusion in the long run. Especially when you are new to learning OOP programming.