Monday, May 24, 2010

Help with this C++ Program?

The snack bar sells only six different items : a sandwich, chips, pickle, brownie, regular drink, and a large drink. All items are subject to sales tax. Set prices for the pdocuts.





The program should repeatedly display the menu below until the sale is totaled. The program should keep a running total of the amount of the sale based on the costs that you place in constants for each of the food items. The running total should be displayed somewhere each the menu is displayed again.





S - Sandwich


C - Chips


P - Pickle


B - Brownie


R - Regular Drink


L - Large Drink


X - Cancel and start over


T - Total the sale





If the sale is canceled, clear your running total and display the menu again. When the sale is totaled, calculatae the sales tax based on 7%. Print the final total due on the screen.





You can use your own functions to design a solution to the problem. You are required to use a function to calculate the sales tax. Other use of functions is up to you.

Help with this C++ Program?
i think that someone need to do their own home works ;)
Reply:I agree that you should do your homework, but since it looks like you have put forth some effort, I have no problem helping.





First off, declare your values for sandwich, chips etc in the beginning. There is no reason to keep re-assigning them.





double sandwich = 4.00;





After you have done that, change the part that prints out the menu to use those values instead of hard coded ones:





cout %26lt;%26lt; "S - Sandwich: $" %26lt;%26lt; sandwich %26lt;%26lt; endl;





Your sales tax function should be something like:





double getSalesTax(double amount)


{


return amount * .07;


}





you should probably have a printTotal too





void printTotal()


{


cout %26lt;%26lt; "Subtotal: $" %26lt;%26lt; setprecision(2) %26lt;%26lt; running_total %26lt;%26lt; endl;


cout %26lt;%26lt; "Sales Tax: $" %26lt;%26lt; setprecision(2) %26lt;%26lt; getSalesTx(runningTotal) %26lt;%26lt; endl;


count %26lt;%26lt; "Total: $" %26lt;%26lt; setprecision(2) %26lt;%26lt; (running_total + getSalesTax()) %26lt;%26lt; endl;


}





setprecision is in iomanip I believe.
Reply:yeah u should do ur own homework
Reply:class item


{


private char* name=null;


private char representativeChar=' ';


private float price=0;





public item (char* name, float price, char representativeChar)


{


this.name=name;


this.price=price;


this.representativeChar=representativeCh...


}





// Write getters and setters for all of the three variables


}





class menu


{


static float currentTotal=0.0;





public menu()


{


float SALES_TAX=7;


Item item[]={


new Item("Sandwich",4,'s'),


new Item("Chips",1.75,'c'),


.........................................


};


}





void displayMenu()


{


/*Similar to what you have already done but use objects instead of c like programming style */


cin%26gt;%26gt;inputChar;


while (inputChar != 'c' || inputChar != 't"')


{


..................................


}





if (inputChar == 'c')


currentTotal=0;





}





private addToCurrentTotal(int priceOfCurrentSelection)


{


currentTotal += priceOfCurrentSelection;


}





private float getCurrentTotal()


{


return currentTotal;


}








public float getTotalAmountDue()


{


return ( getCurrentTotal + (getCurrentTotal() * (SALES_TAX/100)));


}





public void resetCurrentTotal(){currentTotal=0;}


}








void main(char** args, int argc)


{


Menu m = new Menu();


m.displayMenu();


cout%26lt;%26lt;endl%26lt;%26lt;"Total Amount Due: " %26lt;%26lt;m.getCurrentAmountDue();


}


No comments:

Post a Comment