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) = &parallelepiped; 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(); } 
  • one
    You forgot to write the question itself. Just dumping the code and writing the original task is not enough. Opiishte that it is in your code does not work or does not work as it should. - Alexey Ukolov
  • one
    What is the essence of the question? - Yurii Manziuk
  • The code is terrible, but it should work on a vskidku. If you correct the jamb in checking the arguments of the cube and parallelepiped. And for one, correctly otparsite input - atoi will give the whole, not double. - Evgeny Borisov

1 answer 1

The parallelepiped and the cube are confused checks on the number of arguments.

  • can you show how to? - Neon
  • @ Nas_04, 3 and 5 in these branches rearrange. - Qwertiy
  • I did, but still the same. - Neon
  • @ Nas_04, so debaz ... - Qwertiy