Pages

CPP Program


/*Illustrate the use of dereferencing operators to access the class 
members through pointers.  To implement this, define a class M 
with x and y as data members.  Define two methods. One is to input 
the values of x and y and other to find the sum.  The sum is a friend 
function and object of class M is passed as argument in sum.  
Sum will access the class members through dereferencing operators.  
Implement the program and display the results in a neat format
*/

#include<iostream.h>
#include<conio.h>
class M
{
      int x,y;
   public:
      void getdata(void){cout<<"Enter X : ";cin>>x;
			 cout<<"Enter Y : ";cin>>y;}
      friend void sum(M);
};
void sum(M m)
{
   M *pm = &m;
   int M:: *px = &M::x;
   int M:: *py = &M::y;
   cout<<endl<<"The sum = "<<pm->*px+pm->*py;
}
void main()
{
   clrscr();
   M om;
   om.getdata();
   sum(om);
   getch();
}

Alternate 

#include<iostream.h>
#include<conio.h>
class M
{
      int x,y;
   public:
      void getdata(void){cout<<"Enter X : ";cin>>x;
			 cout<<"Enter Y : ";cin>>y;}
      friend void sum(M);
};
void sum(M m)
{
   int M:: *px = &M::x;
   int M:: *py = &M::y;
   cout<<endl<<"The sum = "<<m.*px+m.*py;
}
void main()
{
   clrscr();
   M om;
   om.getdata();
   sum(om);
   getch();
}

Welcome BCA S6 Batch !!!!

Welcome BCA S6 batch students to our blog where we can make this as a medium for exchanging ideas !.I wish to share the codings with examples making this blog a vibrant one ! 
COBOL Program to Add Two Numbers.
Dear students please go through the program and do comment for doubts.

123456789012345678901234567890123456789012345678901234567890123456789012
       IDENTIFICATION DIVISION.
       PROGRAM-ID. SUM-OF-TWO-NUMBERS.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  NUM1    PIC S999V99.
       01  NUM2    PIC S999V99.
       01  TOTAL   PIC S9(4)V99.
       01  E-TOTAL PIC ----9.99.
       01  HAI     PIC PP999.
       01  E-HAI   PIC ZZZ.9(8).
       PROCEDURE DIVISION.
       MAIN-PARA.
           DISPLAY(01 01) SPACES.
           DISPLAY(05 05) "Enter the First Number : ".
           ACCEPT(05 32) NUM1.
           DISPLAY(07 05) "Enter the Second Number : ".
           ACCEPT(07 32) NUM2.
           COMPUTE TOTAL = NUM1 + NUM2.
           MOVE TOTAL TO E-TOTAL.
           DISPLAY(10 05) "The Sum = " E-TOTAL.
           DISPLAY(11 05) "====================".
           DISPLAY " ".
           MOVE 12 TO HAI.
           MOVE HAI TO E-HAI.
           DISPLAY E-HAI.
           STOP RUN.