C++ programming implement the following Shape class. 1. TwoDimensionalShape clas
ID: 3778309 • Letter: C
Question
C++ programming
implement the following Shape class.
1. TwoDimensionalShape class
2. ThreeDimensionalShape class
3. make a program that use Vector of Shape class pointer, which indicate each specific(derived) class object.
4. program should print the object indicated by the pointer.
Also, you should make a loop (ex) for loop) that handles every object.
in that loop, decide the dimension of shape. (if the figure is TwoDimensionalShape or ThreeDimensionalShape)
5. print volume if the figure is TwoDimensionalShape.
6. print area if the figure is ThreeDimensionalShape.
Explanation / Answer
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main () {
// local variable declaration:
vector<double> v;
double l;
double b;
double h;
double r;
char choice;
v.push_back(l); // read elements
v.push_back(b); // read elements
v.push_b ack(h); // read elements
v.push_b ack(r);
v.push_b ack(choice);
while(cin>>d) v.push_back(choice); // read elements
if (!cin.eof()) { // check if input failed
cerr << "format error ";
return 1; // error return
}
switch(choice) {
case '1' :
cout << "2D dimesion!" << endl;
getvolume();
break;
case '2' :
cout << "3D dimesion" << endl;
getarea();
break;
default :
cout << "Invalid dimesion" << endl;
}
int getvolume(int l,int b,int h,int r)
{
cubevolume=(l*b*h);
spherev=1.33*3.14*r*r*r;
cout <<cubevolume:<< cubevolume;
cout <<spherevolume:<< spherev;
}
int getarea(int l,int b,int h,int r)
{
rectangle=(l*b);
sequarea=l*l;
circle=3.14*r*r;
spherearea=4*3.14*r*r;
cout <<rectangle area:<< rectangle;
cout << sequare area:<< sequarea;
cout << sphere area:<<spherearea;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.