Remember that great app you wrote for Yogurt Yummies (Lab 10-2). They want you to enhance the C++ console application that calculates and displays the cost of a customer’s yogurt purchase. Now they need to process multiple sales. Do not change any logic for handling a single sale. Make the following enhancements:
● Add "v2" to the application output header and close.
● Declare and initialize overall totals including:
ü Number of sales.
ü Overall number of yogurts sold.
ü Overall sale amount after discount.
ü Overall tax paid.
ü Overall sale total.
● Enclose the logic for a single sale with a sentinel loop that continues to process sales until the user enters 'n'.
● After calculating sale totals, update overall totals.
● When the user enters the sentinel value ('n'), print overall totals using formatted output manipulators (setw, left/right). Run the program with invalid and valid inputs, and at least three sales. The output should look like this:
Welcome to Yogurt Yummies, v2
-----------------------------
Enter another yogurt purchase (y/n)? y
Sale 1
----------------------------------------
Enter the number of yogurts purchased (1-9): 11
Error: '11' is an invalid number of yogurts.
Enter the number of yogurts purchased (1-9): 2
Enter the percentage discount (0-20): 22
Error: '22.00' is an invalid percentage discount.
Enter the percentage discount (0-20): 4
Yogurts: 2
Yogurt cost ($): 3.50
Discount (%): 4.00
Subtotal ($): 7.00
Total after discount ($): 6.72
Tax ($): 0.40
Total ($): 7.12
Enter another yogurt purchase (y/n)? y
Sale 2
----------------------------------------
Enter the number of yogurts purchased (1-9): 5
Enter the percentage discount (0-20): 10
Yogurts: 5
Yogurt cost ($): 3.50
Discount (%): 10.00
Subtotal ($): 17.50
Total after discount ($): 15.75
Tax ($): 0.94
Total ($): 16.70
Enter another yogurt purchase (y/n)? y
Sale 3
----------------------------------------
Enter the number of yogurts purchased (1-9): 7
Enter the percentage discount (0-20): 20
Yogurts: 7
Yogurt cost ($): 3.50
Discount (%): 20.00
Subtotal ($): 24.50
Total after discount ($): 19.60
Tax ($): 1.18
Total ($): 20.78
Enter another yogurt purchase (y/n)? n
Overall totals
========================================
Sales: 3
Yogurts: 14
Total after discount ($): 42.07
Tax ($): 2.52
Total ($): 44.59
End of Yogurt Yummies, v2
This is from yogurt Yummies V1
Welcome to Yogurt Yummies
-------------------------
Enter the number of yogurts purchased (1-9): 12
Error: '12' is an invalid number of yogurts.
Enter the number of yogurts purchased (1-9): 4
Enter the percentage discount (0-20): 30
Error: '30.00' is an invalid percentage discount.
Enter the percentage discount (0-20): 10
Yogurts: 4
Yogurt cost ($): 3.50
Discount (%): 10.00
Subtotal ($): 14.00
Total after discount ($): 12.60
Tax ($): 0.76
Total ($): 13.36
End of Yogurt Yummies
In: Computer Science
What steps would my computer have to go through to resolve the name cobalamin.csclub.uwaterloo.ca to an IPv4 using a full recursive query?
In: Computer Science
The following SinglyLinkedList class is available:
class SinglyLinkedList: class _Node: """Lightweight, nonpublic class for storing a singly linked node.""" __slots__ = 'element', 'next' # streamline memory usage def __init__(self, element, next): # initialize node's fields self.element = element # reference to user's element self.next = next # reference to next node def __init__(self): # initialize list's fields self._head = None # head references to None def printList(self, label): print(label, end=' ') curr = self._head while curr != None: print(curr.element, end=" -> ") curr = curr.next print("/") ######################################################### # Only this method is required for your solution def computeStats(self): # Your code goes here ######################################################### def main(): # Create a list object for testing purpose sList = SinglyLinkedList() # Create list 2 -> 4 -> -1 -> 8 -> -5 sList._head = sList._Node(2, sList._Node(4, sList._Node(-1, sList._Node(8, sList._Node(-5, None))))) sList.printList("before:") # Call computeStats method sList.computeStats() # And see if it worked! sList.printList("after :") if __name__=="__main__": main()
Assume you have a singly-linked list of integers, some positive and some negative. Write a Python method that traverses this list to calculate both the average and the count (ie, number) of the odd values only. Once calculated, add the average to a new node at the front of the list, and the count to a new node at the end of the list. You may assume that the list will always contain at least one odd value.
Your method will be have the following method signature:
def computeStats(self):
You may use only the SinglyLinkedList class; no other methods (like size(), etc) are available.
For example, if the list initially contains:
2 → 4 → -1 → 8 → -5
the resulting list will contain:
-3.0 → 2 → 4 → -1 → 8 → -5 → 2
In: Computer Science
Explain in detail how is Machine Learning part of face mask detection?
In: Computer Science
Each new term in the Fibonacci sequence is generated by adding
the previous two terms. By starting with 1 and 2, the first 10
terms will be:
1,2,3,5,8,13,21,34,55,89,...
By considering the terms in the Fibonacci sequence whose values do
not exceed 1000, find the sum of
the all the terms up to 300.
In: Computer Science
How do i remove the decimals out of the output? Do I need to int a new value, or use Math.round?
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
double numbers[] = new double[5];
inputArray(numbers);
maxNumber(numbers);
minNumber(numbers);
}
public static void inputArray( double[] numbers) {
Scanner in = new Scanner(System.in);
for(int i = 0; i < numbers.length; i++) {
numbers[i] = in.nextDouble();
}
}
public static void maxNumber(double[] numbers) {
double maxNum = numbers[0];
for(int i = 0; i < numbers.length; i++) {
if(numbers[i] > maxNum ) {
maxNum = numbers[i];
}
}
System.out.println("Max: "+maxNum);
}
public static void minNumber(double[] numbers) {
double minNum = numbers[0];
for(int i = 0; i < numbers.length; i++) {
if(numbers[i] < minNum ) {
minNum = numbers[i];
}
}
System.out.println("Min: "+minNum);
}
}
In: Computer Science
Create a C++ program which will prompt the user to enter a password continually until the password passes the following tests.
Password is 6 chars long
Password has at least 1 number
If the input does not match the tests, it will input a specific error message. "Pass must be 6 chars long."
If the input is allowed, print a message saying "Correct Password Criteria."
In: Computer Science
Algorithm design:Suppose that three types of parentheses are allowed in an expression: parentheses, square brackets, and curly braces. Please design an efficient algorithm to determine whether the parentheses in the expression are correctly paired. Please write down the algorithm idea and steps.
Please explain what kind of data structure is used to solve the problem, and then give the specific algorithm steps
In: Computer Science
Hello. I'm trying to write down java code making stars whose numbers are determined by user input on the console (each star's data are stored in ArrayList).
the class extends JFrame and its color, size(Zoom in and Zoom out), and location are changing every time.
Moreover, its angular rotation is changed at a certain determined degree.
Does anyone know how to write down the java code of this question?
In: Computer Science
Describe domain concept briefly. What are the benefits of domain infrastructure when comparing to workgroup networking? Your elaboration using live example is required.
In: Computer Science
1
Demonstrate the use of local variables in a Java program that
has
1 function
2
Demonstrate the use of overloaded methods
each has three primitive parameters
two methods computes and returns the product to the calling method
for printing
one method computes and prints the product; does not return a
result
3
Demonstrate the use of overloaded constructors
Three constructors each initialize two variables
Three methods, 1 computes the radius of a circle, 1 computes the
area of a rectangle, and area of sphere
In: Computer Science
n following code if variable n=0, a=5 and b=10 then what will be the value of variable ‘n’ after while loop executed. Show your working as well.
while(n<=(a^b)) { n++; } printf("%d",n)
In: Computer Science
Describe/explain IoT as a tech innovation that is reshaping the infrastructure of cities. Discuss the application of IoT in three service sectors, be sure to include the application groups, locations and devices
In: Computer Science
C Programming Question:
Write a C - program to implement the following three operations:
a) Breadth-first search using Adjacency List
b) Breadth-first search using Adjacency Matrix
c) Check whether a given graph is Bipartite using Breadth-first search (adjacency list).
Please take your time, but do submit the correct and full code. Thank you very much.
In: Computer Science
Circle Class (This is in JAVA)
/** * Defines a basic shape with just area * * @author Jo Belle * @version 0.2 (10/05/2020) */ public class Shape{ private double area; public Shape(){ area = 0.0; } public Shape( double a ){ this.area = a; } public void setArea( double a ){ area = a; } public double getArea(){ return area; } public String toString(){ return "Shape:\n\tarea: " + area; } }
/** * Create a simple Circle object * * @author Jo Belle * @version 0.2 (10/12/2020) */ public class ShapeDriver{ public static void main( String[] args ){ Circle cir = new Circle( ); cir.setRadius( 5.0 ); System.out.println( cir.toString() ); } }
Given the code above, write a Circle class (and save it in a file named Circle.java) that inherits from the Shape class. Include in your Circle class, a single private field double radius. Also include a method void setRadius(double r) (which also sets area) and a method double getRadius() (which also returns the current radius). Change the accessibility modifier for area in the Shape class to be more appropriate for a base class. Make sure that ShapeDriver's main() method executes and produces the following output:
Shape: area: 78.53981633974483 radius: 5.0
Submit both your Circle.java and your Shape.java files.
In: Computer Science