Friday, January 8, 2010

I have a programme to be coded can any body can help me?

2. A restaurant manager wants to know how many employees are needed at the restaurant each hour of the day. The minimum number of employees needed at any hour is 3. After that, one additional employee is required for each 20 customers. The restaurant is open 24 hrs a day. The manager has counted the number of customers each hour for 14 days. The manager will use the average number of customers for each hour over the 14 days to calculate the needed number of employees each hour. Develop a solution to output the needed number of employees per hour( There is no such thing as partial employee.)I have a programme to be coded can any body can help me?
Here is how it would look like in PERL....





#Begin Code


#$var will contain the number that the manager will input


$var = shift;


#The problem states a min of 3 employees


$min_employee = 3;


#Here, we divide the number that the manager will input


#to find out how many additional employees we will need


$needed_employee = ($var / 20);


#This outputs the number that we calculated


#Though, I would suggest that this line be left out


#Since the problem didn't ask for it


print ';original num is $needed_employee\n';;





#Here we say that if the number of employees that we need


#is greater than zero, then we will add three


if ($needed_employee %26gt; 0){


#This is to obtain only the digits before the period


#It is to satisfy the statement ';There is no such thing as


#partial employee';


$needed_employee =~ m/([^*\.])/;


$needed_employee = $1 + $min_employee;


print ';Needed Employee = $needed_employee\n';;}


else{


#If we get anything less than one; say .90 then


#we just default to the min number of employees


print ';Needed Employee = $min_employee\n';;


}


#End Code





Here is example output....


--------------------------------------鈥?br>

As you can see here, we input 19 people and PERL tells us that we need 3 since it is the min.





perl abs.pl 19


original num is 0.95


Needed Employee = 3


--------------------------------------鈥?br>




Here, we input 20 and PERL says we need the 3 min employee plus 1 more since we reached 20. The total now becomes 4.





perl abs.pl 20


original num is 1


Needed Employee = 4


--------------------------------------鈥?br>




and so on and so on........





perl abs.pl 40


original num is 2


Needed Employee = 5





perl abs.pl 59


original num is 2.95


Needed Employee = 5





perl abs.pl 60


original num is 3


Needed Employee = 6

No comments:

Post a Comment