Posts

Namespace in C++

Namespace A program includes many identifiers defined in different scopes. Sometimes an identifier of one scope will overlap (i.e. collide) with an identifier of the same name in a different scope, potentially creating a problem. Identifier overlapping also occurs frequently in third-party libraries that happen to use the same names for global identifiers (such as functions).

Objects as Function Arguments in C++ Programming | C++ Programming

Objects as Function Arguments Like any other data type, an object may be used as a function argument in three ways: pass-by-value, pass-by-reference, and pass-by-pointer.

Class and Object and Memory in C++ Programming | C++ Programming

Image
Class and Object and Memory in C++ Programming   When a class is specified, memory space of all the member function is allocated but memory allocation is not done for the data member.   When an object is created, memory allocation for its data members is done. The logic behind separate memory allocation for member functions is quite obvious. All instances of a particular class would be using the same member functions but they may be storing different data in their data members.   Memory allocation for objects is illustrated in fig below Class and Object and Memory in C++ Programming It can be observed that “n” objects of the same class are created and data members of those objects are stored in distinct memory location, whereas the member functions of object 1 to object n are stored in the same memory area. Therefore, each object has a separate copy of data members and the different objects share the member functions among them.

C++ Program To Find Area Rectangle Using Class Function | C++ Programming

Source Code #include<iostream> using namespace std; #include<iomanip> class rectangle { float  length; float  breadth; public: void setdata (int l, int b) { length=l; breadth=b; } void showdata() { cout<<"length="<<length<<endl; cout<<"Breadth="<<breadth<<endl; } float  area() { return length*breadth; } void getdata() { cout<<"Enter length:\n"; cin>>length; cout<<"Enter breadth:\n"; cin>>breadth; setdata(length,breadth); } }; int main() { rectangle r; r.getdata(); r.showdata(); cout<<"Area="<<r.area(); } OUTPUT Enter length: 25 Enter breadth: 5 length=25 Breadth=5 Area=125

C Program To Find Floor and Celing Value | C Programming

C Program To Find Floor and Celing Value Using If and Else

C Program To Find Union Of Two Sets | C Programming

The collection of well-defined distinct objects is known as a set. The word well-defined refers to a specific property that makes it easy to identify whether the given object belongs to the set or not. The word ‘distinct’ means that the objects of a set must be all different. 

C Program To Find Intersection Of Two Sets | C Programming

C Program To Find Intersection Of Two Sets #include <stdio.h> #include <conio.h> int main () {     int a [ 10 ], b [ 10 ], m , n , i , j ;     int c [ 20 ], k = 0 , flag = 0 ;     int ch ;     printf ( "Enter the number of elements in first set: \n " );     scanf ( " %d " , & m );     printf ( "Enter the elements: \n " );     for ( i = 0 ; i < m ; i ++)     {         scanf ( " %d " , & a [ i ]);     }     printf ( " \n Element of First set: \n " );     for ( i = 0 ; i < m ; i ++)     {         printf ( " %d \t " , a [ i ]);     }     printf ( " \n Enter the number of elements in second set: \n " );     scanf ( " %d " , & n );     printf ( " \n Enter the elements:" );     for ( i = 0 ; i < n ; i ++)     {         scanf ( " %d " , & b [ i ]);     }     printf ( " \n Element of Second set: \n " );     for ( i = 0 ; i &l