Posts

C program to Find Cartesian Product of Two Sets | C programming

Image
C program to find the Cartesian Product of two sets   Cartesian product  is a mathematical operation that returns a set (or  product set  or simply  product ) from multiple sets. That is, for sets  A  and  B , the Cartesian product  A  ×  B  is the set of all ordered pairs  ( a ,  b )  where  a  ∈  A  and  b  ∈  B . Products can be specified using set-builder notation, e.g. {\displaystyle A\times B=\{\,(a,b)\mid a\in A\ {\mbox{ and }}\ b\in B\,\}.}

C program To Calculate The Intersection Of Two Sets | Union Of Two Sets | Differences Between Two Sets And Symmetric Difference Of Two Sets | C Programming

This Program helps to calculate intersection of two sets, union of two sets, differences of two sets and symmetric difference of two sets using one simple program in which different variables are declared so that it can be useful to find intersection of two sets, union of two sets, differences of two sets and symmetric difference of two sets Codes #include <stdio.h> int a [ 10 ], b [ 10 ], c [ 10 ], d [ 10 ], i , j , k = 0 , n , m , flag = 0 ; void unio () {     for ( i = 0 ; i < n ; i ++)     {         c [ k ] = a [ i ];         k ++;     }     for ( i = 0 ; i < m ; i ++)     {         flag = 0 ;         for ( j = 0 ; j < n ; j ++)         {             if ( b [ i ] == a [ j ])             {                 flag = 1 ;                 break ;             }         }         if ( flag == 0 )         {             c [ k ] = b [ i ];             k ++;         }     }     printf ( " \n Union \n " );     for ( i = 0 ; i < k ; i ++)

C Program To Calculate Age and Compare Using Concept of Fuzzy Set | C Programming

C Program To Calculate Age and Compare Using Concept of Fuzzy Set  #include <stdio.h> int i , age [ 5 ]; float a [ 5 ], b [ 5 ], c [ 5 ]; char name [ 5 ][ 15 ]; void unio () {     for ( i = 0 ; i < 5 ; i ++)     {         if ( a [ i ] >= b [ i ])             c [ i ] = a [ i ];         else             c [ i ] = b [ i ];     }     printf ( "union \n " );     printf ( "{ " );     for ( i = 0 ; i < 5 ; i ++)     {         printf ( " %.2f / %s ," , c [ i ], name [ i ]);     }     printf ( "}" ); } void intersection () {     for ( i = 0 ; i < 5 ; i ++)     {         if ( a [ i ] <= b [ i ])             c [ i ] = a [ i ];         else             c [ i ] = b [ i ];     }     printf ( " \n intersection \n " );     printf ( "{" );     for ( i = 0 ; i < 5 ; i ++)     {         printf ( " %.2f / %s , " , c [ i ], name [ i ]);     }     printf ( "}" ); } void comple

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