You will be creating TWO console applications from pages 223 and 224 in your book.
6.17 -- name it "Ch6-17" (Visual C# 2012 How To Program (Fifth Edition – Fourth Edition Acceptable) )
Create a class called ShoppingCart with a single method called FillCart that that does the requested tasks. Do not put anything in your main method except for the creation of the ShoppingCart class and a single call to FillCart.
Hint: They are asking for a loop that asks for two separate values (two ReadLines). The loop should terminate if the user enters a specific value for one of the items. Just have the loop terminate (i.e., break) when the user enters a 0 for a product id. Each time through the loop, you should use a switch statement to check the product id and add the appropriate product price (* quantity) to the running total. After the loop is terminated, you are to print the total. NOTE: If the user enters a product id that doesn't exist, you should also let them know this and (obviously) not add any amount to a running total.
6.21 -- name it "Ch6-21"
Do this as described in the book. BUT,
a) this should be in a class called Pythagoras and a method called Triples
b) the method should take a single parameter that determines the largest side to test (i.e., the maximum a/b/c value---in other words, don't just assume that you should stop at 500)
c) the method should keep track two running totals: the number of triples found and the total number of combinations attempted...increment these at the appropriate place in your code to give you the correct counts
d) at the end of the loop, display these totals with an appropriate label (e.g., "Total Found: 123")
e) your main method should ask the user for the largest side, create an instance of Pythagoras, and call Triples with the value provided by the user
Hint: As the book says, this is a loop nested in a loop nested in a loop testing ALL values of a, b, and c (i.e., a^2+b^2=c^2a2+b2=c2) between 1 and the max value. Print out the three sides in the form:
a = NUM, b = NUM, c = NUM
for all combinations that work. ONLY for the combinations that work. And yes, this is "brute force" at its most profound.
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
public void FillCart()
int productId = 5;
double total = 0.0;
Console.WriteLine(" product1: $2.98\n product 2: $4.50\n product 3: $9.98\n");
while (productId != 0)
Console.Write(" product id: ");
productId = Convert.ToInt32(Console.ReadLine()); ...
This is only a preview of the solution. Please use the purchase button to see the entire solution