-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path22.cpp
50 lines (41 loc) · 896 Bytes
/
22.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include<cmath>
using namespace std;
typedef struct{
int xC, yC;
}POINT;
typedef struct{
POINT lt, rb;
}RECTANGLE;
int fnCalcAreaRect(const RECTANGLE&);
void fnReadPoint(POINT&);
void fnReadRectangle(RECTANGLE&);
int main(void)
{
RECTANGLE r1;
int iArea;
fnReadRectangle(r1);
iArea = fnCalcAreaRect(r1);
cout << "\nArea of the Rectangle is " << iArea << " units" << endl;
return 0;
}
void fnReadPoint(POINT& p)
{
cin >> p.xC >> p.yC;
}
void fnReadRectangle(RECTANGLE& r)
{
cout << "\nEnter the coordinates of the Left Top \n";
fnReadPoint(r.lt);
cout << "\nEnter the coordinates of the Right Bottom \n";
fnReadPoint(r.rb);
}
int fnCalcAreaRect(const RECTANGLE& r)
{
int iLen, iBrd;
// (r.rb.xC)+=1; //should not be allowed
iLen = abs(r.rb.xC - r.lt.xC);
iBrd = abs(r.rb.yC - r.lt.yC);
cout << iLen << " * " << iBrd << endl;
return iLen *iBrd;
}