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

Home
C++ Tutorial
1.Language Basics
2.Data Types
3.Operators statements
4.Array
5.Development
6.Exceptions
7.Function
8.Structure
9.Class
10.Operator Overloading
11.Pointer
12.File Stream
13.template
14.STL Introduction
15.string
16.vector
17.list
18.bitset
19.set multiset
20.valarray
21.queue stack
22.deque
23.map multimap
24.STL Algorithms Modifying sequence operations
25.STL Algorithms Non modifying sequence operations
26.STL Algorithms Binary search
27.STL Algorithms Sorting
28.STL Algorithms Merge
29.STL Algorithms Min Max
30.STL Algorithms Iterator
31.STL Algorithms Heap
32.STL Algorithms Helper
C / ANSI-C
C Tutorial
C++
Visual C++ .NET
C++ Tutorial » Class » member method 
9.4.6.Use class as the member function parameter type
#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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.