C++ program using constructors

0
597

C++ program using constructors

CONSTRUCTION:

  • Start the program
  • Create the object and pass the values to the constructors using implicit and explicit method.
  • Display the output values.
  • Stop the program.

PROGRAM:

#include<iostream.h>
#include <conio.h>
class integer
 {
 int m,n;
 public:
 integer (int,int);
void display()
 {
  cout<<”m=”<<m;
  cout <<”n=”<<n;
 }
 };
 integer::integer(int x,int y)
 {
 m=x;
 n=y;
 }
void main()
 {
 clrscr();
 integer int1(20,50);
 integer int2=integer(75,100);
 cout <<”\nobject1”<<”\n”;
 int1.dispaly();
 cout <<”\nobject2”<<”\n”;
 int2.dispaly();
 return 0;
 getch();
 }

 

Leave a Reply