Saturday, 9 March 2019

CPP-EX27


 write a c++ prog that will ask for a two numbers from user,find its avg & display it.Using constructor

  #include<iostream.h>
  #include<conio.h>

  class avg
  {
  int a,b;
  public: avg( ) { }
  avg(int p,int q)
  {
  a=p;
  b=q;
  }
  void display()
  {
  cout<<"\n Enter the first No:-"<<a;
  cout<<"\n Enter the second No;-"<<b;
  cout<<"\n Avg="<<(a+b)/2;
  }
  };

  void main()
  {
  clrscr();
  avg x1(10,20);
  x1.display();
  getch();
  }