Friday, July 31, 2009

C programming question?

Problem C: Determining the Profit of the Goldfish Tank





Using your solutions to problems A and B, you will solve the following problem:





Given the length, width and height of the goldfish tank in inches, determine the amount of profit you can gain by selling the fish in the tank.





Assume that each goldfish in the tank requires 250 cubic inches of room in the tank to survive. (Thus, if the dimensions of the tank were 24x12x16 inches, exactly 18 fish could fit in the tank since 24x12x16 = 4608 and 4608/250 = 18.432, but you can't have .432 of a fish.) Also, assume that you sell each goldfish for $5.00. (You can store these values in constants in your program.)











Here's an example worked out:





If the dimensions of the tank are 24x12x16, we have already determined that the cost of building the tank is $28.80 and the cost of maintaining the tank is $23.04, so the total cost is $51.84.





But, we will sell 18 goldfish at $5.00 dollars a piece for a total gross revenue of $90.00. Thus, our profit is $90.00 - $51.84 = $38.16.











There is also a possibility that you may lose money with your fishtank. If this occurs, print out a message (following the sample below) indicating the amount of money lost.











Input Specification





1. The length, width and height of the tank will be positive integers.











Output Specification





Output the profit in dollars for selling goldfish to two decimal places. If there was a profit, your output should follow the format below, where XX.XX is the profit from selling the goldfish.





Your profit from selling goldfish is $XX.XX.





Otherwise, if there was a loss, you should follow the following format:





Your loss from selling goldfish is $XX.XX.





You may choose to handle the case where there was no profit or loss in any way you see fit.











Output Samples





Below are two sample outputs of running the program. Note that these samples are NOT a comprehensive test. You should test your program with different data than is shown here based on the specifications given above. In the sample run below, for clarity and ease of reading, the user input is given in italics while the program output is in bold.











Sample Run #1





What is the length of your goldfish tank in inches?





24





What is the width of your goldfish tank in inches?





12





What is the height of your goldfish tank in inches?





16





Your profit from selling goldfish is $38.16.











Sample Run #2





What is the length of your goldfish tank in inches?





1





What is the width of your goldfish tank in inches?





1





What is the height of your goldfish tank in inches?





1000





Your loss from selling goldfish is $65.02.

C programming question?
You failed to provide the previous questions. In other words, this program depends on how you calculate your costs. I assume those come from previous questions, which are not included in your information. That said, here's some code. (Too bad the spacing kills it.) You have to put in the formulae for the cost functions, and then it should work. If I were you, I'd test the program thoroughly after you're done and not just "trust it works." But don't get me wrong, I trust I write good code. :-p





#include %26lt;stdio.h%26gt;


#include %26lt;math.h%26gt;





int promptNum(char* question);


float costBuild(int length, int height, int width);


float costMaintain(int length, int height, int width);





int main()


{


int length, height, width;


length = promptNum("What is the length of your fishtank in inches?\n");


height = promptNum("What is the height of your fishtank in inches?\n");


width = promptNum("What is the width of your fishtank in inches?\n");





int volume = length * height * width;


int fish = floor(volume / 250);


float revenue = fish * 5.00;





float costs = costBuild(length, height, width)


+ costMaintain(length, height, width);


float profit = revenue - costs;





if (profit %26gt; 0)


printf("You had a PROFIT of %9.2f\n", profit);


else if (profit %26lt; 0)


printf("You had a LOSS of %9.2f\n", 0 - profit);


else if (profit == 0)


printf("Eh, you broke even. It could be a lot worse.\n");





return 0;


}





float costBuild(int length, int height, int width)


{


float cost;


// cost = [INSERT BUILD_COST FORMULA HERE]


return cost;


}





float costMaintain(int length, int height, int width)


{


float cost;


// cost = [INSERT MAINTAIN_COST FORMULA HERE]


return cost;


}





int promptNum(char* question)


{


printf(question);


int n;


scanf("%d", %26amp;n);


return n;


}
Reply:It is not that easy. May be you can contact a C expert. Check websites like http://askexpert.info/


No comments:

Post a Comment