The command line sets the sign of the shape, the volume of which must be calculated:
s - ball (argument - radius);
k - cube (argument - side);
p - parallelepiped (arguments are sides a, b and c)
c is a cylinder (arguments are base radius and height).
Calculate the volume of the corresponding figure. Accessing functions is implemented through a pointer.
This is what I have.
The code compiles without errors, but nothing comes the console.
#include <iostream> #include <math.h> #include <stdlib.h> #include <string.h> #include <conio.h> using namespace std; double pi = 3.14; double sphere(double r) { return (4 * pi * pow(r,3))/3; } double cube(double s) { return pow(s,3); } double parallelepiped(double a, double b, double c) { return a * b * c; } double cylinder(double r, double h) { return pi * pow(r, 2) * h; } int main(int argc, char* argv[]) { double (*psphere)(double r) = &sphere; double (*pcube)(double s) = &cube; double (*pparallelepiped)(double a, double b, double c) = ¶llelepiped; double (*pcylinder)(double r, double h) = &cylinder; if (argc > 1) { if (!strcmp(argv[1], "s")) { if(argc == 3) { cout << " Volume of the sphere: " << psphere(atoi(argv[2])) << endl; } } else if (!strcmp(argv[1], "k")) { if (argc == 3) { cout << " Volume of the cube: " << pcube(atoi(argv[2])) << endl; } } else if (!strcmp(argv[1], "p")) { if (argc == 5) { cout << "Volume of the parallelepiped: " << parallelepiped(atoi(argv[2]),atoi(argv[3]),atoi(argv[4])) << endl; } } else if (!strcmp(argv[1], "c")) { if (argc == 4) { cout << " Volume of the cylinder: " << pcylinder(atoi(argv[2]),atoi(argv[3])) << endl; } } } _getch(); }