Posts

Code of Constructor

                      Constructor Define Constructor:- Types of Constructor:- 1 .  Default Constructor:-  Constructor that is no parameter are called default constructor. #include<iostream> #include<conio.h> using namespace std; class sum { int a,b,c; public: sum() { a=10; b=20; } void add() { c=a+b; cout<<c; } }; main() { sum s1; s1.add(); getch(); } Output:- 30 2. Parameterized Constructor:-  A constructor that can take arguments are called parameterized constructor. #include<iostream> #include<conio.h> using namespace std; class read { int a,b; public: read(int m , int n) { a=m; b=n; } void display() { cout<<a<<b; } }; main() { read r1(10,30); r1.display(); getch(); } output:- 10 30 Note:- If you use Dev...

Define function outside the class

Image
               Program to  enter  & display detail of 5 employ Define function outside the class  :- #include<iosteram.h> #include<conio.h> class employ { char name[20]; int age; public; void getdata(); void putdata(); }; void employ::getdata() { cout<<"Enter employee name"; cin>>name; cout<<"Enter employee age"; cin>>age; } void employ::putdata() { cout<<"\n"<<name<<"\t"<<age; } void main() { clrscr(); employ b1[10]; int i; for(i=0;i<5;i++) { b1[i].getdata(); } cout<<"Employee details are: \n"; cout<<"name \t age"; for(i=0;i<5;i++) { b1[i].putdata(); } getch(); }  Note:-  If you use   turboc++   then you use this code, if y...

Find largest number using nesting and member function

                      Program to find Largest Number Code to find the largest of two number :- #include<iostream.h> #include<conio.h> class largest { int no.1, no.2; public: void input() { cout<<"Enter two no. : \n "; cin>>no.1>>no.2; } void large() { if(no.1>no.2) { cout<<no.1<<" is the largest number"; } else { cout<<no.2<<" is the largest number"; } }; void output() { large(); } }; void main() { clrscr(); largest N1; N1.input(); N1.output(); getch(); } Output to  find the largest of two number  :- Enter two no. : 10 20 20 is the largest no.    2. Code to find the Largest of three numbers :- #include<iostream> #include<conio.h> using namespace std; class largest { ...

Addition of two matrix using class

              Code of Addition of matrix using Class #include<iostream.h> #include<conio.h> class add {   int row, clm, a[10][10], b[10][10], sum[10][10]   void read()       {         cout<<"Enter the no. of rows";         cin>>row;         cout<<"Enter the no. of clms";         cin>>clm;     cout<<"Enter the first matrics \n";         for(int i=0;i<row;i++)       {            for(int j=0;j<clm;j++)           {       cin>>a[i][j];           }            cout<<end1;        }        cout<<"Enter the second matrix \n"; ...

Addition of two no. using Class

    Code of addition in c++ using class #include<iostream.h> #include<conio.h> Class addition {   int a, b, c;   public:   void input()     {      cout<<"Enter two element which you want to add \n";      cin>>a>>b;    }     void output()     {      cout<<"Sum of two no. are: \n";      c=a+b;      cout<<c;    }  }; void main()  {   addition s1   clrscr();   s1.input();   s1.output();   getch(); }  Output: - Enter two elements which you want to add  2 3 Sum of two no. are: 5 

Multiplication of matrix using Array

Image
               Code of  Multiplication of two matrix using Array #include <stdio.h>   int  main ( ) {    int  m ,  n ,  p ,  q ,  c ,  d ,  k ,  sum  =   0 ;    int  first [ 10 ] [ 10 ] ,  second [ 10 ] [ 10 ] ,  multiply [ 10 ] [ 10 ] ;      printf ( "Enter number of rows and columns of first matrix \n " ) ;    scanf ( "%d%d" ,   & m ,   & n ) ;    printf ( "Enter elements of first matrix \n " ) ;      for   ( c  =   0 ;  c  <  m ;  c ++ )      for   ( d  =   0 ;  d  <  n ;  d ++ )        scanf ( "%d" ,   & first [ c ] [ d ] ) ;      printf ( "Enter number of rows and columns of second matrix \n " ) ;    sc...

Addition of two matrix using Array

Image
                  Code of Addition of two matrix using Array #include <stdio.h> int main() {    int m, n, i, j, A[10][10], B[10][10], sum[10][10];    printf("Enter the number of rows and columns of matrix\n");    scanf("%d%d", &m, &n);    printf("Enter the elements of A matrix\n");    for (i = 0; i < m; i++)       for (j = 0; j < n; j++)          scanf("%d", &A[c][d]);    printf("Enter the elements of B matrix\n");    for (i = 0; i < m; i++)       for (j = 0 ; j < n; j++)          scanf("%d", &B[c][d]);        printf("Sum of entered matrices:-\n");        for (i = 0; i < m; i++) {       for (j = 0 ; j < n; j++) {          sum[c][d] = A[i][j] + B[...