openpole.cpp

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

CPP
57
字号
                              // Chapter 5 - Program 3 - OPENPOLE.CPP
#include <iostream.h>

int area(int rec_height, int rec_width);

struct rectangle 
{
   int height;
   int width;
};

struct pole 
{
   int length;
   int depth;
};

int area(int rec_height, int rec_width)  //Area of a rectangle
{
   return rec_height * rec_width;
}


int main()
{
rectangle box, square;
pole flag_pole;

   box.height = 12;
   box.width = 10;
   square.height = square.width = 8;

   flag_pole.length = 50;
   flag_pole.depth = 6;

   cout << "The area of the box is " << 
                       area(box.height, box.width) << "\n";
   cout << "The area of the square is " << 
                       area(square.height, square.width) << "\n";
   cout << "The funny area is " << 
                       area(square.height, box.width) << "\n";
   cout << "The bad area is " << 
                       area(square.height, flag_pole.depth) << "\n";

   return 0;
}




// Result of execution
//
// The area of the box is 120
// The area of the square is 64
// The funny area is 80
// The bad area is 48

⌨️ 快捷键说明

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