Concept explainers
My mother always took a little red counter to the grocery store. The counter was used to keep a tally of the amount of money she would have spent so far on that visit to the store, if she bought all the items in her basket. There was a four-digit display, increment buttons for each digit, and a reset button. There was an overflow indicator that came up red if more money was entered than the $99.99 it would register. (This was a long time ago.) Write and implement the member functions of a class Counter that simulates and slightly generalizes the behavior of this grocery store counter. The constructor should create a Counter object that can count up to the constructor’s argument. That is, Counter(9999) should provide a counter that can count up to 9999. A newly constructed counter displays a reading of 0. The member function void reset(); sets the counter’s number to 0. The member functions void incr1(); increments the units digit by 1, void incr10(); increments the tens digit by 1, and void incr100(); and void incr1000(); increment the next two digits, respectively. Accounting for any carry when you increment should require no further action than adding an appropriate number to the private data member. A member function bool overflow(); detects overflow. (Overflow is the result of incrementing the counter’s private data member beyond the maximum entered at counter construction.)
Use this class to provide a simulation of my mother’s little red clicker. Even though the display is an integer, in the simulation, the rightmost (lowerorder) two digits are always thought of as cents and tens of cents, the next digit is dollars, and the fourth digit is tens of dollars.
Provide keys for cents, dimes, dollars, and tens of dollars. Unfortunately, no choice of keys seems particularly mnemonic. One choice is to use the keys asdfo: a for cents, followed by a digit 1 to 9; s for dimes, followed by digits 1 to 9; d for dollars, followed by a digit 1 to 9; and f for tens of dollars, again followed by a digit 1 to 9. Each entry (one of asdf followed by 1 to 9) is followed by pressing the Return key. Any overflow is reported after each operation. Overflow can be requested by pressing the o key.
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
Problem Solving with C++, Student Value Edition
Additional Engineering Textbook Solutions
Introduction To Programming Using Visual Basic (11th Edition)
Artificial Intelligence: A Modern Approach
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Absolute Java (6th Edition)
Modern Database Management (12th Edition)
C++ How to Program (10th Edition)
- Develop a program to determine the price for a custom shop sign. The price is determined by the number of colors in the sign, if the sign will have lighting, and if an old sign must be removed. Lighted signs cost 25% more than the base price, and removal of an old sign costs 10% of the base price of the new sign. You must validate the input; make sure the number of colors is greater than 0. You must use switch to calculate base price based on the number of colors. The total cost must be represented in currency ($) and two digits decimal points. Your program’s prompt and messages should look similar to the sample provided. The fee schedule is shown below: Colors in the sign Base Price 1 $250 2 $325 3 $450 4 $625 5 or more $850 For example: Num Base Price Light Remove With Light With Remove Total Cost 1 $250.00 Y Y $312.50 $25.00 $337.50 1 $250.00 Y N $312.50 $0.00 $312.50 1 $250.00 N Y…arrow_forwardThe Ibra College of Technology has an automated system that calculates the overall grade for each student of a class. The system gets to know the number of students in a class from the teacher. For each student, it asks their name and the number of subjects they took. For each subject, they ask the score. They then take the average of the scores of all the subjects, divide it by 10 and display the name and GPA for each student. Read the number of students in a class, the name and the number of subjects for each student. Then read the scores of each subject for each student, calculate the GPA by averaging the scores and dividing the average by 10. Finally, display the name and GPA for each student.arrow_forwardYour company is asking you to write a program that calculates the average grade for the students in a class. The program should use a loop to read in the grades. Should you use a sentinel control loop or a counter control loop? Explain your answer.arrow_forward
- This exercise is for a simplified supermarket cash register system. The normal procedure for using the cash register is as follows: • A customer arrives at the checkout with items to pay. • The cashier records the identification number of each item, as well as the quantity if it is greater than one. • The checkout displays the price of each item and its description. • When all purchases are recorded, the cashier signals the end of the sale. • The cash register displays the total purchases. • The customer chooses his method of payment: ✓ cash: the cashier collects the money received; the cashier indicates the currency to be returned to the customer; ✓ check: the cashier checks the creditworthiness of the customer by transmitting a request to an authorization center via the cashier; ✓ credit card: a bank terminal is part of the cash register. It transmits an authorization request to an authorization center according to the type of card. • The cash register registers the sale and prints a…arrow_forwardThis exercise is for a simplified supermarket cash register system. The normal procedure for using the cash register is as follows:• A customer arrives at the checkout with items to pay.• The cashier records the identification number of each item, as well as the quantity if it is greater than one.• The checkout displays the price of each item and its description.• When all purchases are recorded, the cashier signals the end of the sale.• The cash register displays the total purchases.• The customer chooses his method of payment:✓ cash: the cashier collects the money received; the cashier indicates the currency to be returned to the customer;✓ check: the cashier checks the creditworthiness of the customer by transmitting a request to an authorization center via the cashier;✓ credit card: a bank terminal is part of the cash register. It transmits an authorization request to an authorization center according to the type of card.• The cash register registers the sale and prints a receipt.•…arrow_forwardDevelop a program that can perform both as a unit converter and a calculator using a menu driven interface. This system will allow users to convert various physical quantities across different units. The program should provide conversions for volume, length, mass, temperature, area. Users should be able to input values and select the desired conversion, and the program should output the converted result.Also, should be able to perform various calculation like addition, subtraction, multiplication, division, square of a number, logarithmic value and the program should output the result.Condition:Use necessary concept like if-else, looping, array or structureUse any programming language.Use suitable modern tools for solving the problem. ### Need fast Answerarrow_forward
- Write a program that asks for two numbers. After the input of two numbers, ask the user whatoperation to do between the numbers. Perform the operation according to the user’s choice and displaythe result. After the display, ask the user if he wants to continue. If the user continues, ask for a numberand an operation. Perform the selected operation with the recent result and the new input value. Displaythe result according to the user’s choice and ask the user again if he wants to continue. Repeat thisprocess as long as the user wants to continue.When selecting an operation, it must be case sensitive. If the user provides an invalid input in selectingan operation, display an error message and ask again for an operation. The program must not exit. Theprogram will only terminate after the user select not to continue.arrow_forwardQuestion 5 Write a Verilog Program using 2 seven segment displays and 4 switches. Switch 1 increments a number on one seven segment display. Switch 2 decrements the number on that display. Switch 3 increments a number on another seven segment display. Switch 4 decrements the number on that display too Full explain this question and text typing work only We should answer our question within 2 hours takes more time then we will reduce Rating Dont ignore this linearrow_forwardUsing python, write a program that takes the x-y coordinates of a point in the Cartesian plane and displays a message telling either an axis on which the point lies or the quadrant in which it is found. Sample Output: (-1.0, -2.5) is in quadrant III (0.0, 4.8) is on the y axisarrow_forward
- This lab is Part 2 of a 2 Part Lab called InflationRate. Please complete the instructions. Here is sample output for one run of the program when it's complete. Match the output EXACTLY. Enter the old and new consumer price indices: 238.343 238.250Inflation rate is -0.0390204Try again? (y or Y): yEnter the old and new consumer price indices: 238.250 237.852Inflation rate is -0.167049Try again? (y or Y): nAverage rate is -0.103035 Part 2 1. Here are the original instructions from Part 1. // TODO #1: declare two float variables for the old consumer price index (cpi) and the new cpi // TODO #2: Read in two float values for the cpi and store them in the variables // TODO #3: call the function InflationRate with the two cpis // TODO #4: print the results 2. Put the logic in TODO #2-4 into a loop that asks the user to enter 'y' (or 'Y') if there's more data to be entered. 3. Keep a running total of the valid inflation rates and the number of computed rates to calculate the average…arrow_forwardyou will take the output from the first task and write an algorithm and matching code to perform the second task, which is to calculate and print out the GPA rounded to 2 decimal places. So, for the test input [1, 4, 3, 3, 2, 1, 3, 0, 3, 2, 2] The output would be 2.18 output from 1st task is in photo Identify which pattern or patterns could best be applied to the solution of the second task. State clearly the name of the pattern and the pattern number, for example “List generation Pattern 2.2 Pattern 4.1 Formula Pattern 4.2 Case analysis (two cases)) Pattern 4.3 Case analysis (multiple cases) Pattern 4.4 Case analysis (nested cases) Pattern 4.5 Sequence generation Pattern 2.2 List generation Pattern 2.3 List filtering Pattern 2.4 List transformation Pattern 2.5 Reduction: counting Pattern 2.6 Reduction: aggregation Pattern 2.7 Reduction: find value Pattern 2.8 Reduction: find best value Pattern 2.9 Reduction: version 3 find position of first best valuearrow_forwardHello, I'm new in VHDL coding. I need car parking simulation code, required specifications are: 1- The car park counts the number of cars parked inside. The maximum count is 1000. 2- Each car enter must be given a number(code) that indicates when leaving when it enters and how much time it had spent inside. 3- The car park signals an error condition if a car leaves when the count is 0 or a car enters when the count is 1000. 4- The car park reports the time when a car has entered or leave in hours and minutes. 5- An output CAR COUNT indicates how many cars are inside the car park. 6- An output Car count indicates how many cars can enter. Please put the instructions beside the code. Thanks...arrow_forward
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage