pgrm_013.cpp (895B)
1 /* in-line and non-inline functions */ 2 3 #include<iostream> 4 using namespace std; 5 class cuboid { 6 private: 7 float length, breadth, height; 8 public: 9 cuboid() {length = breadth = height = 0;} 10 11 void getData(); 12 void display(); 13 14 //inline 15 float volume() { 16 return length * breadth * height; 17 } 18 19 //inline 20 float surfaceArea() { 21 return 2 * (length * breadth + breadth * height + height * length); 22 } 23 }; 24 25 // non inline 26 void cuboid :: getData() { 27 cout << "Enter length, breadth and height: "; 28 cin >> length >> breadth >> height; 29 } 30 31 // non inline 32 void cuboid :: display() { 33 cout << "\nCuboid Details" << endl; 34 cout << "length: " << length << endl; 35 cout << "breadth: " << breadth << endl; 36 cout << "Height: " << height << endl; 37 cout << "Volume: " << volume() << endl; 38 cout << "Surface Area: " << surfaceArea() << endl; 39 } 40 41 int main() { 42 cuboid obj; 43 obj.getData(); 44 obj.display(); 45 return 0; 46 }