-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
56 lines (49 loc) · 1.12 KB
/
main.cpp
File metadata and controls
56 lines (49 loc) · 1.12 KB
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
51
52
53
54
55
56
/***************************************
* Simple classes example
*
* Run it with two arguments, like this:
*
* #> HelloClass -x10 -y2
*
* Created June 2022.
*
***************************************/
#include <iostream>
#include <unistd.h>
#include <cstdint>
#include "Rectangle.h"
using namespace std;
static void usage(const char *arg0)
{
cerr << "Usage: " << arg0 << " [-x num | -y num]" << endl;
exit(EXIT_FAILURE);
}
int main (int argc, char *argv[]) {
Rectangle rect;
int opt;
char *eptr;
while ((opt = getopt(argc, argv, "x:y:")) != -1)
{
switch (opt)
{
case 'x':
rect.setX(strtoul(optarg, &eptr, 10));
break;
case 'y':
rect.setY(strtoul(optarg, &eptr, 10));
break;
default:
cerr << "Unknown option: " << optopt << "\n";
usage(argv[0]);
break;
}
}
//rect.setValues (3,4);
if (rect.isValid()) {
cout << "Area: " << rect.getArea() << endl;
}
else {
cout << "Error, Rectangle is not valid!" << endl;
}
return 0;
}