Posts

Showing posts with the label Class

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