-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
66 lines (54 loc) · 2.31 KB
/
main.cpp
File metadata and controls
66 lines (54 loc) · 2.31 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
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <cmath>
#include <argparser.h>
#include <string.h>
// Function to calculate the volume of a rectangular box given its dimensions
double calculateBoxVolume(double length, double width, double depth) {
return length * width * depth;
}
int main(int argc, char* argv[]) {
ArgStatus ret = PARSER_ERROR;
ArgParser parser(
"Box Volume Calculator", // Project name
"Calculate the volume of a rectangular box" // Description
);
// Add arguments for the dimensions of the box and verbose mode
parser.addArgument("length", "-l", "--length", "Height of the box", 0.0);
parser.addArgument("width", "-w", "--width", "Width of the box", 0.0);
parser.addArgument("depth", "-d", "--depth", "Depth of the box", 0.0);
parser.addArgument("verbose", "-v", "--verbose", "Enable verbose output", false);
parser.addArgument("tstr", "-s", "--string", "Test string", "Test");
// Parse command-line arguments
ret = parser.parse(argc, argv);
// checking whether the default help is triggered
// if(ret == PARSE_DEFAULT_HELP_OK){
// return 0;
// }
if(ret < PARSER_OK){
printf("Error: Error occured (%d)\n", ret);
return 1; // Return non-zero to indicate an error
}
// Retrieve values
std::string test_str = parser.get<std::string>("tstr");
double length = parser.get<double>("length");
double width = parser.get<double>("width");
double depth = parser.get<double>("depth");
bool verbose = parser.get<bool>("verbose");
if (parser.argExists("tstr")) {
printf("String Test Value %s\n", test_str.c_str());
}
// Check if the provided dimensions are valid
if (parser.argExists("length") && parser.argExists("width") && parser.argExists("depth")) {
// Calculate the volume of the box
double volume = calculateBoxVolume(length, width, depth);
// Display the result based on verbose mode
if (verbose) {
printf("Dimensions: %.2f X %.2f X %.2f\n", length, width, depth);
}
printf("Volume of the box: %.2f" , volume);
} else {
printf("Error: Invalid dimensions. All dimensions must be included.");
return 1; // Return non-zero to indicate an error
}
return 0;
}