Company must buy furniture at time 0 and must always have a furniture during the
ID: 3677655 • Letter: C
Question
Company must buy furniture at time 0 and must always have a furniture during the next 5 years. For a furniture bought at the beginning of year t, the cost of the furniture is 1000 USD. The maintenance costs per years are as follows: 60 USD for the year t (i.e. between t and t + 1), 80 USD for the year t + 1, and 120 USD for the year t + 2. The salvage value is 800 USD if we sell it at the end of year t, 600 USD at the end of year t + 1, and 500 USD at the end of year t+ 2. Since the technology is developing so fast, Company doesn’t want to use furnitures older than 3 years. Therefore each furniture should be replaced by a new one at every 3 years at most
Find the optimum plan for procurement of new furnitures for the next 5 years.
(NOTE:Derive a recursive formula for buying a furniture at time t and sell it at time x, and optimize this function by using Dynamic Programming)
Introduction to Algoirthms, Dynamic Programming
Explanation / Answer
Good wishes,
First let me give you the program:
void main()
{
int i=0,n=0,j,t[3],maintenance_cost[5],salvage_value[5],cost=1000;
string f[5];
printf("enter a furniture:");
scanf("%s",f[0]);
while(n>1825)
{
if(n%365==0)
{
for(j=0;j<5;j++)
t[j]=t[j]+1;
switch(t[i])
{
case 1:maintenance_cost[i]=maintenance_cost[i]+60;
salvage_value[i]=800;
break;
case 2:maintenance_cost[i]=maintenance_cost[i]+80;
salvage_value[i]=600;
break;
case 3:maintenance_cost[i]=maintenance_cost[i]+120;
salvage_value[i]=500;
replace(f,t,i);
break;
}
}
}
n++;
}
void replace(string[] f,int i)
{
string new;
printf("enter new furniture:");
scanf("%s",new);
f[i]=new;
t[i]=0;
maintenance_cost[i]=0;
salvage_value[i]=0;
}
Explaination:
First I am creating a loop for 5 years i.e 1825 days, I did not consider leap year because you did not specify that condition. Then after each year I increamented the time period of each furniture.
for(j=0;j<5;j++)
t[j]=t[j]+1;
Then I cheked to see if any furniture has reached 3 years of period after every year
switch(t[i])
{
case 1:maintenance_cost[i]=maintenance_cost[i]+60;
salvage_value[i]=800;
break;
case 2:maintenance_cost[i]=maintenance_cost[i]+80;
salvage_value[i]=600;
break;
case 3:maintenance_cost[i]=maintenance_cost[i]+120;
salvage_value[i]=500;
replace(f,t,i);
break;
}
if so then I called the replace() function to replace it with a new furniture
void replace(string[] f,int i)
{
string new;
printf("enter new furniture:");
scanf("%s",new);
f[i]=new;
t[i]=0;
maintenance_cost[i]=0;
salvage_value[i]=0;
}
Thus I am replacing a 3 year old furniture for a new one. I carried this process for 5 years.
I took the number of furnitures the company can have at a time as 5(dummy value) as you did not specify any.
You mentioned the cost of furniture but did not mention what to do with it.
Please make changes accordingly.
Hope this is clear.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.