Use class as the member function parameter type : member method « Class « C++ Tutorial






#include<iostream.h>
#include<iomanip.h>
class Rectangle
{
private:
  float length;
  float height;
public:
  Rectangle(){}
  Rectangle(float loge,float shge)
  {
    length=loge;
       height=shge;
  }
  void getlength()
  {
    cout<<"Input large edge:";
    cin>>length;
    cout<<"Input small edge:";
    cin>>height;
  }
  void showsquare()
  {  
    cout<<setprecision(3) <<length*height<<endl;
  }
  void addsquare(Rectangle r1,Rectangle r2);
  void addedge(Rectangle r1,Rectangle r2);
};
void Rectangle::addsquare(Rectangle r1,Rectangle r2)
{
  length=r1.length+r2.length;
  height=r1.height+r2.height;
  cout<<"\n Total of Rectangle square:"
      <<r1.length*r1.height+r2.length*r2.height;
}
void Rectangle::addedge(Rectangle r1,Rectangle r2)
{
  length=r1.length+r2.length;
  height=r1.height+r2.height;
  cout<<"\n Toatal of Rectangle length:"
      <<setprecision(3)<<(length+height)*2;
}
main()
{
  Rectangle room1(15.5,6.5);
  Rectangle room2,room3;
  room2.getlength();
  cout<<"Square of room1 Rectangle is:";
  room1.showsquare();
  cout<<"square of room2 Rectangle is:";
  room2.showsquare();
  room3.addsquare(room1,room2);
  room3.addedge(room1,room2);
  return 0;
}
Input large edge:123
Input small edge:12
Square of room1 Rectangle is:101
square of room2 Rectangle is:1.48e+003

 Total of Rectangle square:1.58e+003
 Toatal of Rectangle length:314"








9.4.member method
9.4.1.Declare a class with method
9.4.2.Implement class member function
9.4.3.The class member access operators . and ->
9.4.4.Overloading class member functions
9.4.5.Default values in member functions
9.4.6.Use class as the member function parameter type
9.4.7.member function overloading.
9.4.8.overloading two class member functions
9.4.9.overloading functions in base and derived classes