// SECJ1013-PT1-Assignment 2 (20202021-1)
// Group Members:
// 1. Ahmad Nazran bin Yusri
// 2. Megat Irfan Zackry bin Ismail
// 3. Muhammad Syazwan bin Sahdan
#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() {
	
	int width=0,height=0,length=0,radius=0;
	float area=0, volume=0;
	char object = chooseObject();
	if (object == 'b'){
		setParam(width,height,length);
		area = areaRect(width, height);
		volume = area * length;
		cout << "\nBox volume = " << volume; 
	}
	
	else{
		setParam(radius, length);
		area = areaCircle(radius);
		volume = area * length;
		cout << "\nCylinder volume = " << volume;
	}

	return 0; 
}

// function definitions
char chooseObject(){
	char o;
	do {
		cout<<"b- Box\nc- Cylinder\nChoose object (b/c): ";
		cin>>o;
	}
	while (o!='b'&&o!='c');
	cout<<endl;
	return o;
}

void setParam(int &w,int &h,int &l){
	w = getParam("Width: ");
	h = getParam("Height: ");
	l = getParam("Length: ");
}


int getParam (string pname){
	int pvalue;	
	do{
		cout<<pname;
		cin>>pvalue;
	}
	while (pvalue<=0);
	return pvalue;
}

float areaRect(int w, int h){
	float area;
	area =  w * h;
	
	return area;
}

void setParam(int &r, int &l){
	r = getParam("Radius: ");
	l = getParam("Length: ");
}

float areaCircle(int r){
	float area;
	area = PI*r*r;
	
	return area;
}
