// SECJ1013-PT1-Assignment 2 (20202021-1)
// Group Members:
// 1. Amirul Iman bin Ahmad Keflee
// 2. Muhammad Faiz Aiman bin Fakhrurrazi
// 3. Muhammad Amiruddin bin Zulkifli

#include <iostream>
#include <string>
#define PI 3.14

using namespace std;

// function prototypes
float areaCircle(int);
float areaRect(int, int);
int getParam(string);
void setParam(int &, int &);
void setParam(int &, int &, int &);
char chooseObject();

// start main function
int main() {
	char object;
	int width=0,height=0,length=0,radius=0;
	float area=0, volume=0;
	object = chooseObject();
	if (object == 'b'){
		setParam(width, height, length);
		area = areaRect(width, height);
		volume = area * length;
		cout<<"\nVolume of box = "<<volume<<endl;
	}
	else {
		setParam(radius, length);
		area = areaCircle(radius);
		volume = area * length;
		cout<<"\nVolume of cylinder = "<<volume<<endl;
	}
    return 0; 
}

void setParam(int &w, int &h, int &l){
	w = getParam("Width: ");
	h = getParam("Height: ");
	l = getParam("Length: ");
}

void setParam(int &r, int &l){
	r = getParam("Radius: ");
	l = getParam("Length: ");
}

int getParam(string pname){
	int pvalue;
	do{
		cout<<pname;
		cin>>pvalue;
		if(pvalue<=0)
		cin.clear(), cin.ignore();
	}while(pvalue<=0);
	return pvalue;
}

char chooseObject(){
	char object;
	do{
	cout<<"b - Box\nc - Cylinder\nChoose object (b/c): ";
	cin>>object;
	cout<<'\n';
	if((object!='b')&&(object!='c'))
	cin.clear(), cin.ignore();
	}while((object!='b')&&(object!='c'));
	return object;
}

float areaRect(int width, int height){
	float area;
	area = width * height;
	return area;
}

float areaCircle(int radius){
	float area;
	area = PI * radius * radius;
	return area;
}

