Classes, Public and Private access modifiers in C++ | C++ Tutorials for Beginners #21
HTML-код
- Опубликовано: 5 фев 2020
- ►Source Code & Resources: codewithharry.com/videos/cpp-...
►This video is a part of my C++ playlist: • C++ Tutorials In Hindi
►For Doubt Solving, Brain Storming Sessions & guaranteed replies, join the channel membership here: / @codewithharry
►Click here to subscribe - / @codewithharry
►Checkout my English channel here: / programmingwithharry
Best Hindi Videos For Learning Programming:
►Learn Python In One Video - • Python Tutorial In Hin...
►Python Complete Course In Hindi - • Python Tutorials For A...
►C Language Complete Course In Hindi -
• C Language Tutorials I...
►JavaScript Complete Course In Hindi -
• JavaScript Tutorials I...
►Learn JavaScript in One Video - • JavaScript Tutorial
►Learn PHP In One Video - • Learn Php In One Video...
►Django Complete Course In Hindi -
• Python Django Tutorial...
►Machine Learning Using Python - • Machine Learning Tutor...
►Creating & Hosting A Website (Tech Blog) Using Python - • [Hindi] Web Developmen...
►Advanced Python Tutorials - • Intermediate/Advanced ...
►Object Oriented Programming In Python - • Object Oriented Progra...
►Python Data Science and Big Data Tutorials - • Python Data Science an...
Follow Me On Social Media
►Website (created using Flask) - www.codewithharry.com
►Facebook - / codewithharry
►Instagram - / codewithharry
►Personal Facebook A/c - / geekyharis
Twitter - / haris_is_here
#include
using namespace std;
//Structure of class
class Animal{
//Private variables accessible only with the help of function.
private:
int leg, eyes, ears;
public:
int sound, speed;
void setData(int a1, int b1, int c1); // Declaration only
void getData()
{
cout
same as harry 🤣 good
Well try
😁👍
Sound ko bhi integer data type me rakha hai
Sound ko string ya character data type me rakhna chahiye tha
#include
using namespace std;
class animals{
private:
int eyes;
int legs;
int ears;
public:
int speed;
int voice;
void setdata(int a, int b, int c){
eyes=a;
legs=b;
ears=c;
}
void getdata(){
cout
Time Stamp - 14:59
#include
using namespace std;
class Students
{
private:
int roll_no;
string religion;
public:
string f_name;
int standard;
int age;
void setData(int r, string rel); // r stands for roll_no & rel stands for religion.
void getData()
{
cout
Thanks Gulshan you given me best example of classes and object
@@rajrai4294 Your Welcome 🤝🏻
Syntax error aayega brother 🙂
@@curiousritik4558 Bhai coding line me aaye ho syntax error ho ya koi bhi error ho wo toh tumko hi solve krna h
Dhyaan do toh sirf logic pe
Yha gulshan ne kitne badhiya logic se ye problem likha h
@@rajrai4294 accha
Bahut achha lga mujhe, and concept are so easy to understand by watching it. 💯
You are the best Harry Bhai ...free online course provider ....😍🥰🥰
Wonderful way of teaching...thanks harry bhaiya❤️
Thank you so much sir... Very helpful n amazing ❤️😁
Thanks Harry Bhai...
Kuch smjh ni aa rha tha aaj jake sara kuch clear hua hai ...
#include
using namespace std;
class animal{
private:
int age,height,length;
public:
string name,species;
void setdata(int a,int h, int l); //note:a,h,l are just 3 random variables we have used to signify that we will be using 3 integers.
void getdata(){
cout
I got 88% marks in my midterm exam due to this playlist hoping best for the final....
Thanks ❤
Yes its great
yar muja tu samaj nahi a rahi
There are only 37 videos of this subject
Thanks Harry bhaiya ji for this amazing course that is free of cost!
# include
using namespace std;
class animal{
private:
int love;
public:
int sound;
int legs;
void setdata(int a);
void showdata(){
cout
Jjj
Love 2
Sound 2
Legs 4
The value of love is 2
The value of sound is 2
The value of legs is 4
By default data private hi hota h😅
you might be earning good ....
but here you are earning the blessings and good wishes of all struggling students who were looted by the paid training goons after expensive degree expanses and the poeple looted on the name of internship ....god bless. u dear .....keep it up
#include
#include
using namespace std;
class Student{
private:
int roll;
public:
string name;
int Class;
void setData(int r);// declared
void getData(){
cout
@Felix Enzo I've seen you commenting exactly like this in some other video as well...wtf boy
@Felix Enzo don't promote your stuff here like this, because 99% of people here don't have Gf.
hmm, helps in understanding better... thanks 😃👌👏👏
@@swaroop2518 That hurts 😂
@@swaroop2518 hahaa
short and to the point. Your videos saved a lot of time ..... Thanks for making such a great content......
Main pichle 5 dino se aise languages doondh raha tha jo bahut tuff ho sikhne mein time lage baad mein mujhe mili c++ bhai ne use bhi easy bana diya 😢rona aa raha hai
Great explanation.your effort is awesome
This tut boosted my confidence ❤❤
also me
after watching lot of videos finally , i got the right one
Coded Myself time : 14:50
#include
#include
using namespace std;
class animal{
private:
char gender;
int babbies;
public:
char name[50];
int legs;
int hands;
void setData(char, int);
void getData();
};
void animal :: setData(char gen, int bab){
gender = gen;
babbies = bab;
}
void animal :: getData(){
cout
Nice code bro 👍
would you please tell me, what is the use of strcpy(); ?
@@shreyamittal9152Strcpy(String Copy) function, is use to copy string into a variable.
Harry SIR, i tried a example - 14:47
#include
#include
using namespace std;
class pen{
private : float price;
string ink_colour;
public :
void get_data()
{
coutprice;
coutink_colour;
}
void prn_data()
{
cout
class bank
{
private : float transection, loan;
public : int profit, loss;
} ;
Thank you so much Harry bhai for making this video and I will see you next time ❤️☺️
Thank you ,much appreciated
Thankuu sir.... 🥰
Bro ur video are amazing outstanding but my exams are near kindly complete the course asap
Don't know only few view of this outstanding lecture
Class avengers{
Public:
Int speed;
Int health;
Int fire;
Void attack() {
Int attack=speed+fire;
Cout
the answer i was searching that why classes is used instead of structure is well explained here .
Thank you for the video harry bhai..
your videos make this Lockdown productive for us
learning java was so damn helpful, it was a piece of cake!
Great thanx
It went so easy ;
you made me poor to better coder.
Thank you harry bhai .... love you bhai
14:55
#include
using namespace std;
class animal{
private:
int areanum;
int sellingvalue;
public:
int population;
int speed;
void setdata(int sellingvalue,int areanum);
void getdata(){
cout
Bhai thanks and plz make full course of C++ bhai plz and thanks a lot 🙏💕 I love u ❤️😘 from my heart you are my real brother 👦 really bhai
Thanks a lot sir,it is a great content❤
you are the best teacher in the world
Very good sir.....
Ek request hai plzz data structures par bhi tutorial video bnaye.
harry sir your teaching is fabulous.. your explaination is so good..u r nice sir for coding.
Lovely teaching awesome Harry bhai
Dil se Thank you Harry bhai
challanged accepted sir ,
and your way of teaching is really very good , videos are short but cover every point of the topic . really very helpfull to learn C++ .
thank you sir
😊
Love from Bangladesh Harry Bhai 🇧🇩🇧🇩❤️
14:45
Here,the example of a class is car
It can have different properties like
- Brand
- Color
- Transmission
- Mileage
us
Luv you bro.. maza aa jaata hai aap se padh kar..
Thank you sir bht bht shukriya♥️♥️♥️♥️
Mid Sem Tests coming soon.. Please upload more videos soon. I've watched C playlist already. By the way, I love your content.
Yaar meri bhi
Midsam is very very soon
padhai likhai pr dhyan do
IAS YAS bano aur desh sambhalo
@@tasneemahmad7858 wah bhai roll numer hi lagaliya name me ?
@@uraniumgaming123 college walo ko google meet pr naam me yahi pattern chahiye
Answer of the animal class:
#include
using namespace std;
class animal{
private: string name,sound,family;
public: int legs,age;
void setdata( string name1,string sound1,string family1, int legs1, int age1);
void getdata(){
cout
Pura khol ke rakh diya😍
Thx great video..❤️
// Class 15:00
class Program{
private:
int age;
char qualification;
public:
char languages;
int projects_made;
int time_experience; // --> write this in years;
}
Such a grt Teacher & Grt Programmer
right
Thank You 🙏🏻
Greatt!!❤️
#include
using namespace std;
class animal{
private:
string Tiger;
string Cheeta;
public:
string Cow;
string Goat;
void setdata(string Tig, string Che );
void getdata(){
cout
its cheetah
tiger and cheetah not printed in output
class Animal{
private:
string sound;
int number ; // all animals has different sound
public:
string colour,food;
void setdata(string so,int sp);
void getdata(){
cout
Thank bhiya for this valuable tutorial
Q 1: Write a C++ function “addition” that will take two arguments “istVal” and “secVal” as integer
arguments and the function will add the values of “istVal” and “secVal” and return the result to
the calling statement in main function.
itna easy aap cmt me q puch rhi ho
@@usamasharjeel8532 for answer 😅🙃
@@prernaprerna4028 first time ⌚ sab kuch hard lagta hain 🙃🙃😕
#include
using namespace std;
class Sum{
public: int sum;
int add(int istVal, int secVal);
};
int Sum :: add(int istVal, int secVal){
sum= istVal + secVal;
return sum;
}
int main(){
Sum s;
cout
@@vritikapathare noice
Nice bro
Easy to Explain
Upload next video 😍
Sir thanks for these videos
superb videos!
Hello kindly c++ kai projects bhi bananna jis tara python kai app nai banye the..... Jis mai sare c++ kai topics covers hojay.... Make projects for c++.
Thank u.
9:24 class function definition
Thoda aage piche karke dekhna pada
par atlst samj aagaya
Thank YOU !!!!!!!!! Bhaiya !!'🤪🤪🙏🙏
Great course
Time Stamp - 14:50
#include
using namespace std;
class animal
{
private:
string Name;
string food;
public:
int legs;
int lifespan;
void setData(string a,string f);
void getData(){
cout
Enter the name of the animal
Dog
Enter the favourite food
Biscuits
How many legs they have
4
What is lifespan of dog
20
The name of the animal is dog
Loves to eat biscuits
Dog has 4 leags
The lifespan of dog is 20 Years
@@uditmehra5636 thanks bro for showing the output of the code
string requires header file right?
@@myth_snipe7737no its not required you can define string variables in c++ if you want to use string functions than the string.h header file required
@@unknownking798most welcome bro ❤
If we don't declare access modifier to any variable and function by default it get private.
great course harry
Thanks Harry Bhaiya
Heyy Sir make more videos as soon as possible..my exams will start from mid of march
+1
enjoy!!! :D
tera naukar h kya wo?
Ok
to padai karo to lecture bunk mat maro
Sir, in a class, you explained private and public modifiers. But what are protected modifiers?
protected modifiers have properties of both public and private modifiers. You can inherite properties from a protected modifiers but it will still be private for the user.
in protected data members of one class can be accessed outside of the class that is in another class
@@maazsajid5742 *subclass or inherited class
Thanks Bhaiya
Thank you very much sirji 🙏🏻🙏🏻
Sir, Are the content(variables + functions) written in the public category up to the end of the class '}' is considered as public or it gets terminated after the semicolon; at the end of the next line where public was written?
All the variable or function can be written either in private or in public depending on your choice or situation.
doesn't get terminated after; but terminated or we can say considered up to }
Thank you, Harry bhai!
very good explaination.
Could we get some questions for this chapter?
sir if we write those functions under private as you have written them under public can we use them in main program??
nope
@@revanthkumar1789 No bro
Thank you so much sir 😊😃💝
Thank you! 😇
there is the only difference between structure and classes in cpp that is default access specifier:
In struct it is public and in class it is private.
Inheritance can be used in structures
Class Students {
Private :
int mobileNo;
string address;
Public:
Int rollNo;
String name;
Void putdata(int mob , string addr);
Void showdata ()
{
Cout
Sister Baki program sahi hai but
mobile No, address ko cout karwa hi nahi
Great efforts
Thank you Harry bhaii!🥳
Time Stamp - 14:59
//Written By Pulastya
#include
using namespace std;
class Car{
private:
double cost_of_car;int dis,rto_num;
public:
string name; int model_num;
void setData(int a1,int b1,int c1);
void getData(){
cout
class Room
{
public:
double length;
double breadth;
double height;
double calculateArea(){
return length * breadth;
} double calculateVolume(){
return length * breadth * height; }
};
why you are defining your area function here, its very hard to read here,
Where is private keyword???
Nice video!
bro we can make functions using struct
the only difference between struct and class is by default in struct variables are public whereas in class they are private.
And i think the inheritance feature also
adarsh mishra not only inheritance there are many class properties which you can see in prev-vedio or search about it. So bcoz of that all properties of class makes a huge diff between structure and class
No in structure we cannot define Functions, and the solution of this is class🤟🏼
If you are using struct in cpp than there us no difference in class or struct...... You can also use the concept of inheritance in struct .... Know your fact before talking
#include
#include
using namespace std;
class Animal
{
private:
string name;
public:
string colour, bread;
void setData(string name, string colour, string bread);
void showData()
{
cout
*breed
Thank you bhai... ❤
Thanks bhaiya.
#include
using namespace std;
class Rectangle
{
private:
int length, width, area, peri;
public:
void SetDimensions(int l, int b);
void CalculateArea();
void CalculatePerimeter();
};
void Rectangle ::SetDimensions(int l, int b)
{
length = l;
width = b;
}
void Rectangle ::CalculateArea()
{
area = length * width;
cout
#include
#include
#include
using namespace std;
class animal
{
public:
string name, colour;
string legs, speed;
void num_getdata(void);
void getdata(void);
void showdata()
{
cout
nice bro
Smart coding bro
Thank you so much Sir
Sir jab ham koi program run karte hai, tab compiler sabse pehele program ke konse part me jata hai ??
Just a small correction, access modifiers exist in structures also
and also structures in c++ allows function definition inside the structure
#include
#include
using namespace std;
// 14:57
class Animal
{
public:
string name,sound;
int speed;
void set_animal_data(string parm_name,string param_sound,int param_speed);
void get_animal_data();
};
void Animal :: set_animal_data(string param_name,string param_sound,int param_speed){
name = param_name;
sound = param_sound;
speed = param_speed;
}
void Animal :: get_animal_data(){
cout
get_animal_data function m cout nhi krna?? ?
Nikhil, here you use
in cpp . Can we use this because this is for c and in cpp there is alternate called
@@harshprajapat165 Yup! You can use it
@@prernaprerna4028 why bro get_animal_data function me he krna h
Thanks man ❤️
void class name::function name(arguments);
Harry bhai can we use "void setData and getData" for public function
plz reply I am waiting for your reply
Functions are created for private use only... Set data... Is used bcoz we want to access the private variables through function... And get data is jst to print it.. To access the public variable we don't need functions we can directly access it.. By using dot..
Vaiya next videos Kab ayega?
Thodi jaldi kro 🙏🙏🙏🙏
very nice sir jee maza aagaya