Good day!
There is a task that needs to be solved through classes. I could not figure it out with them, with the creation of the .h file and in general. I decided how I could, because tomorrow I can pass on the DD, the code is working, but can I somehow fix it so that the described requirements for the classes are met? Task description may not be accurate (in translation).
α) Write a program that will use the Rectangular class with the rectangle data. The variables width and height contain the data of the sides of the rectangle and belong to the class.
Write α) constructor which takes no arguments β) constructor which takes 2 arguments γ) setWidth, setHeight which take two sides of the δ rectangle
Next, write code that works for two rectangles (10.7) and (10.12). The data of the first is set initially, the second is set by setWidth and setHeight. The result - the display of their area
β) Write square class Square, is an extension of the rectangle class. Write a constructor that will receive the value of the side of the square.
Further, the program should work for squares with sides 10 and 7. Also display their area and perimeter.
γ) Add a Box-cube class and a constructor that will receive the three cube parameters (length, height, width) getVolume and getArea are used from the parent class. scale (double f) multiplies the parameters (dimensions) of the cube by f. In the program - 2 cubes (10,10,10) and (7,8,3). The screen displays the volume of the cube, the area of its surfaces. Then the scale is called - coefficients 0.5 and 2. New data is displayed on the screen.
Total: 1 program with 1 main, 3 .cpp and 3 .h (1 for each class (rectangle, squre, box))
and here is the code itself:
#include <iostream> #include <conio.h> #include <cstdlib> using namespace std; class percalc { public: void per(int a); void per(int a,int b); }; void percalc::per(int a) { cout<<"\n Perimetr of Square ="<<(4*a); } void percalc::per(int a, int b) { cout<<"\n Perimetr of Rectangle="<<((a+b)*2); } class areacalc { public: void area(int a); void area(int a,int b); void area(int a,int b,int d); }; void areacalc::area(int a) { cout<<"\n Area of Square="<<(a*a); } void areacalc::area(int a,int b) { cout<<"\n Area of Rectangle="<<(a*b); } void volume (int a,int b,int c) { cout<<"\n Volume of box="<<a*b*c; } void area (int a, int b, int c) { cout<<"\n Area of the first side of box="<<a*b; cout<<"\n Area of the second side of box="<<a*c; cout<<"\n Area of the third side of box="<<c*b; cout<<"\n Area of all sides of box="<<2*a*b+2*a*c+2*b*c; } void scale (int a,int b, int c, float sc) { area (a*sc, b*sc, c*sc); volume (a*sc, b*sc, c*sc); } main() { areacalc ac; percalc pc; cout<<"Rectangle with sides 10 and 7"<<endl; ac.area(10,7); pc.per (10,7); cout<<"\n\n\nRectangle with sides 10 and 12"<<endl; ac.area(10,12); pc.per (10,12); cout<<"\n\n\n\nSquare with side 10"<<endl; ac.area(10); pc.per (10); cout<<"\n\n\nSquare with side 7"<<endl; ac.area(7); pc.per (7); cout<<"\n\n\n\nCube with side 10"<<endl; area (10,10,10); volume(10,10,10); cout<<"\n\n\n\nScale 0,5"<<endl; scale (10,10,10,0.5); cout<<"\n\n\n\nScale 2"<<endl; scale (10,10,10,2); cout<<"\n\n\nBox with sides 7, 8 and 3"<<endl; area (7,8,3); volume(7,8,3); cout<<"\n\n\nScale 0,5"<<endl; scale (7,8,3,0.5); cout<<"\n\n\nScale 2"<<endl; scale (7,8,3,2); getch(); }