11. C++ Programming - Constructor (C++ Class)

  Рет қаралды 11,065

Antonie Smith

Antonie Smith

Күн бұрын

C++ Programming Tutorials brought to you by TONY TUTORIALS.

Пікірлер: 6
@luthandonomzaza1607
@luthandonomzaza1607 Жыл бұрын
Your accent says you are in South Africa. . . Super proud of you man
@aleynaaslan5516
@aleynaaslan5516 4 жыл бұрын
Hi, nice content. I need to write a program where it identifies if a number is odd or even. The software should take user input in the main function and the function that decides if the number is odd or even should be done inside the class function of your program. Mine does not work about determining whether it is odd or even. I appreciate that if you can help me.
@AntonieSmithVideos
@AntonieSmithVideos 4 жыл бұрын
Thanx =)
@aleynaaslan5516
@aleynaaslan5516 4 жыл бұрын
Mine is like that and i think it is very wrong #include using namespace std; class Numbers { int n; public: void displayMessage() { if (n%2==0) { cout
@AntonieSmithVideos
@AntonieSmithVideos 4 жыл бұрын
Hi, 1. We need to understand that the variable, "int n" declared in the class and the variable, "int n" declared in the main function is not the same variable. Actually, the variable declared in the class does not exist until an instance of the "class numbers" is created. 2. The variable, "int n" in the class must be defined as either "public" or "private". This will determine how you will interact with the variable. We need to interact with the variable, in order to initialize the variable by either a function (if the variable is private), or directly (if the variable is public). 3. If we understand how to interact with the variable, we can send the user input to the class via the correct channel. 4. Your coding to determine if the number is odd or even is perfect. It is just the way you use the class that is the problem.
@AntonieSmithVideos
@AntonieSmithVideos 4 жыл бұрын
This is my suggestion: #include using namespace std; class Numbers { public: void setn( int a ) //Set function to pass user input to the class variable { n = a; } void displayMessage() { if (n%2==0) { cout
Introduction To Classes And Objects | C++ Tutorial
11:49
Portfolio Courses
Рет қаралды 61 М.
Flipping Robot vs Heavier And Heavier Objects
00:34
Mark Rober
Рет қаралды 51 МЛН
ДЕНЬ УЧИТЕЛЯ В ШКОЛЕ
01:00
SIDELNIKOVVV
Рет қаралды 4 МЛН
НАШЛА ДЕНЬГИ🙀@VERONIKAborsch
00:38
МишАня
Рет қаралды 2,4 МЛН
Intermediate Linux and Shell Scripting
56:17
San Diego Supercomputer Center
Рет қаралды 9
Constructor Basics | C++ Tutorial
7:08
Portfolio Courses
Рет қаралды 25 М.
Object Oriented Programming (OOP) in C++ Course
1:30:26
freeCodeCamp.org
Рет қаралды 2,5 МЛН
C++ CLASSES & OBJECTS explained easy 🧍
10:54
Bro Code
Рет қаралды 23 М.
Learn Any Programming Language In 3 Hours!
22:37
Code With Huw
Рет қаралды 456 М.
Classes & Objects | C# | Tutorial 25
13:25
Giraffe Academy
Рет қаралды 174 М.
Flipping Robot vs Heavier And Heavier Objects
00:34
Mark Rober
Рет қаралды 51 МЛН