nesting.cpp

来自「Since the field of object oriented progr」· C++ 代码 · 共 50 行

CPP
50
字号
                               // Chapter 6 - Program 7 - NESTING.CPP
#include <iostream.h>

class mail_info 
{
   int shipper;
   int postage;
public:
   void set(int in_class, int in_postage)
           {shipper = in_class; postage = in_postage; }
   int get_postage(void) {return postage;}
};

class box {
   int length;
   int width;
   mail_info label;
public:
   void set(int l, int w, int s, int p) {
         length = l; 
         width = w;
         label.set(s, p); }
   int get_area(void) {return length * width;}
};


int main()
{
box small, medium, large;

   small.set(2, 4, 1, 35);
   medium.set(5, 6, 2, 72);
   large.set(8, 10, 4, 98);

   cout << "The area is " << small.get_area() << "\n";
   cout << "The area is " << medium.get_area() << "\n";
   cout << "The area is " << large.get_area() << "\n";

   return 0;
}




// Result of Execution
//
// The area is 8
// The area is 30
// The area is 80

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?