Posts

Showing posts with the label cpp

c++ operator overloading

Image
C++ operator overloading In this article, you will learn about why or how to the operator overloading and complete the concept of operator overloading with examples. The operators are used for the primitive data type like +,-, and / same enables the usage of these operators for user-defined data type known as operator overloading. C++ allows the programmer to use operators for the user-defined data type. In order to add the two objects of the class, usage of the operator overloading makes it very easy to add the two objects. Why operator overloading used? The c++ language gives the facility to programmer to use the operators with the objects of the class rather than the usage of the difficult code to perform operations. The operator overloading give a lot of easy to programmer to perform different operation with objects of the classes. How to operator overload? The following is the syntax of the operator overloading. Syntax Operator keyword followed by the symbol of the operator. =>

C++ Object and Function

Image
C++ Object and Function  In this post, you will learn how to pass an object to the function and how to object return from the function in the c++ language. How to pass the object to the function? Passing the object is just like passing the variable or structure to the function. Following is the example of how to pass an object to the function. #include<iostream> using namespace std; class myhouse{ //define the myhouse class int numberofroom; //attributes int numberoffloor; public: myhouse(int room, int floor){ //constructor numberofroom=room; numberoffloor=floor; } void display(myhouse &obj) //passing the object in the function { cout<<obj.numberoffloor<<endl; cout<<obj.numberofroom<<endl; } void getdata(){ //function for accessing data cout<<numberoffloor<<endl;                                        //display number of floor cout<<numberofroom<<

constructors in c++

Image
C++ constructors In this article, you will learn the complete concept of the constructors in c++ and constructors type in cpp. what is a constructor? The constructor is the member function of the class which makes the objects of the class. The constructor called automatically when the object is created. Types of constructor There are three types of constructors in the c++ language. default constructor parameterized constructor copy constructor How to create constructors? For the creation of the constructor make the member function of the class name without return data type and write in the function what you initialize during the object creation. The privacy of the constructor usually public in the class  Following is the syntax of the constructor. What is the syntax of the constructor class myhouse{ public: myhouse(){ cout<<" hello constructor"; } }; The member function my house without return data type is the constructor of the class. Default constructor The co

c++ classes and objects

Image
C++ classes and objects In this article, you will learn about the classes and objects in the c++ language in some interesting way to understand the concept of classes and objects. Class is the user-defined data type with user-defined functionalities that are enabled by creating the object of the class. Why we need a class? Suppose an example of the student, the student has a name, roll number, and university name, etc. All the properties must be attached to the student class like qualification, marking. This is an example also taken in understanding the structure concept. Difference between class and structure There is only one difference between structure and class is class gives privacy to the user-defined data type, but the structure does not give privacy to the user. The classes provide the functionality to the data type but the behaviour or operation does not allow in the structure. How privacy define in the class The new thing adds in the classes is the access specifiers which ar

C++ type conversion

Type casting In this article, you will learn about the concept of the type casting in the C++ language. Typecasting is the conversion of the data type of the expression into the other data type.Type casting is mainly two types  Implicit conversion Explicit conversion Implicit conversion Implicit conversion does not need any additional work, All the work done by the compiler automatically. These conversions of the data done by the compiler are known as implicit conversions. During the fundamental type conversion in the c++ language, Implicit conversion is very helpful.such as type conversion ( int to float,float to int,double to int,short to int ,and some pointers conversion). How implicit conversion use in c++? Example: #include<iostream> using namespace std; int main() { int num=92;               //declare and define the int number double number2;        //declare double number           number2=num;           //assign the int number to the double number cout<

C++ Structure

C++ Structure The collection of the different types of variables under the one name is called the Structure. These variables are called data members of the structure. The variables are the different types of data and different lengths. The structure is like class and also user-defined data type but with some differences with class. In the structure, no privacy is available and in the class, privacy is available to the datatype. What is the syntax of the structure in c++? Following is the syntax of the structure struct structname{ member1type    member1name; member2type    member2name; member3type    member3name; }; here,structname is the name of the structure, and members of the structure are declared between the brackets{}.The semicolon (;) add at the end of the structure. This is the most common mistake that happened to miss the semicolon. Take an example of a student for the understanding of how to use structure. The student has properties like name,age, university name,Roll Number