How can I access my object's volume to compare then and display the most common size (small, medium, large, etc.) in c++?
so within my project I have to display the popular shapes, color percentages and most common size based on volume, I was able to print the popular shape and color using my global arrays:
int numColor[CC_COUNT];
double rawColor[CC_COUNT] = { 100.0, 100.0, 100.0, 100.0 };
int numShapes[SC_COUNT];
ObjectData ReadObjectData()
{
ObjectData object;
object.index = g_objectCount;
object.valid = true;
object.printed = false;
printf("Please enter the shape and color of object: ");
scanf("%d%d", &object.shape, &object.color);
const double PI = 3.14;
int i = 0;
switch(object.shape){
case SC_CUBE:
printf("Please enter cube's side length: ");
scanf("%lf", &object.dimen[i]);
object.volume = pow(object.dimen[i],3);
printf("The volume is %.4lf\n", object.volume);
break;
case SC_CUBIOD:
object.volume = 1;
printf("Please enter the cubiod's side lengths\n");
for(i = 0; i < 3; i++){
printf("Side %d: ", i+1);
scanf("%lf", &object.dimen[i]);
object.volume = object.volume * object.dimen[i];
}
printf("The volume is %.4lf\n", object.volume);
break;
case SC_SPHERE:
printf("Please enter the sphere's radius: ");
scanf("%lf", &object.dimen[i]);
object.volume = (4.0 / 3) * PI * pow(object.dimen[i], 3);
printf("The volume is %.4lf\n", object.volume);
break;
case SC_CYLINDER:
printf("Please enter the cylinder's radius and height: ");
scanf("%lf%lf", &object.dimen[0], &object.dimen[1]);
object.volume = PI * pow(object.dimen[0], 2) * object.dimen[1];
printf("The volume is %.4lf\n", object.volume);
break;
case SC_CONE:
printf("Please enter the cone's radius and height: ");
scanf("%lf%lf", &object.dimen[0], &object.dimen[1]);
object.volume = (1 / 3.0) * PI * pow(object.dimen[0], 2) * object.dimen[1];
printf("The volume is %.4lf\n", object.volume);
break;
}
numColor[object.color]++;
rawColor[object.color] -= object.volume;
numShapes[object.shape]++;
return object;
}
and implementing them here:
const char nameShapes[SC_COUNT][10] = {"Cube", "Cubiod", "Sphere", "Cylinder", "Cone"};
const char colorNames[CC_COUNT][10] = {"Red", "Green", "Blue", "Black"};
const char objsize[4][10] = {"Small", "Medium", "Large", "Giant"};
void DisplayStatistics()
{
ObjectData output;
output.index = g_objectCount;
output.valid = true;
output.printed = true;
double total;
int userInput;
double small = 0.0, medium = 0.0;
double large = 0.0, huge = 0.0;
int maxCount = 0;
int maxShape = -1;
printf("Which would you like to see\n");
printf(" 1 - Percentage of colors printed\n");
printf(" 2 - Popular 3D shape printed\n");
printf(" 3 - Most common object size by volume\n");
printf("Enter your choice: ");
scanf("%d\n", &userInput);
switch (userInput) {
case 1:
for(int i= 0; i < CC_COUNT; i++) {
total= (numColor[i] / (double) output.index) * 100;
printf("Color percentage for %s: %.2f%%\n",colorNames[i],total);
}
break;
case 2:
for(int shape = 0; shape < SC_COUNT; shape++){
if(maxCount < numShapes[shape]){
maxCount = numShapes[shape];
maxShape = shape;
}
}
printf("The most popular shape is %s\n", nameShapes[maxShape]);
break;
case 3:
if(output.volume > 0 && output.volume <= 1.0){
small++;
}
if(output.volume > 1.0 && output.volume <= 10.0){
medium++;
}
if(output.volume > 10.0 && output.volume <= 100.0){
large++;
}
if(output.volume > 100.0){
huge++;
}
small = (small / output.index) * 100;
medium = (medium / output.index) * 100;
large = (large / output.index) * 100;
huge = (huge / output.index) * 100;
printf("Small %.2f% % \n", small);
printf("Medium %.2f% % \n", medium);
printf("Large %.2f% % \n", large);
printf("Huge %.2f% % \n", huge);
break;
default:
}
}
I need to compare the volume's and display the most common size and i was told to take a similar approach as I did in the first two but Im confused on how. im trying to display it in case 3 btw
Comments
Post a Comment