Notice the definition of the member function input of the class Money given in Display 11.3. If the user enters certain kinds of incorrect input, the function issues an error message and ends the program. For example, if the user omits a dollar sign, the function issues an error message. However, the checks given there do not catch all kinds of incorrect input. For example, negative amounts of money are supposed to be entered in the form –$9.95, but if the user mistakenly enters the amount in the form $–9.95, then the input will not issue an error message and the value of the Money object will be set to an incorrect value. What amount will the member function input read if the user mistakenly enters $–9.95? How might you add additional checks to catch most errors caused by such a misplaced minus sign?
Want to see the full answer?
Check out a sample textbook solutionChapter 11 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Modern Database Management (12th Edition)
Computer Science: An Overview (12th Edition)
Database Concepts (7th Edition)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Starting Out with C++: Early Objects (9th Edition)
- quick answer pleasearrow_forwardDescriptionIn this assignment, you are required to implement an electronic programming quiz system. User can createquestions and preview the quiz.Your TaskYou are asked to write a Java program for the programming quiz system. There are two types of questions:Multiple Choice Question and Ture/False Question. User can create questions using the system; andpreview the quiz, which display all questions in the system one by one. During the preview, the user canattempt the quiz by entering his/her answers to questions. The system will then immediately check theanswer and calculate. After attempting all questions, the total score will be displayed. A sample run of theprogram is shown as below (Green text refers to user input): Please choose (c)reate a question, (p)review or (e)xit >> cEnter the type of question (MC or TF) >> MCEnter the question text >> Each primitive type in Java has a correspondingclass contained in the java.lang package. These classes are called…arrow_forwardIn python how do you: Complete the FoodItem class by adding a constructor to initialize a food item. The constructor should initialize the name to "None" and all other instance attributes to 0.0 by default. If the constructor is called with a food name, grams of fat, grams of carbohydrates, and grams of protein, the constructor should assign each instance attribute with the appropriate parameter value. The given program accepts as input a food item name, fat, carbs, and protein and the number of servings. The program creates a food item using the constructor parameters' default values and a food item using the input values. The program outputs the nutritional information and calories per serving for both food items. Ex: If the input is: M&M's 10.0 34.0 2.0 1.0 where M&M's is the food name, 10.0 is the grams of fat, 34.0 is the grams of carbohydrates, 2.0 is the grams of protein, and 1.0 is the number of servings, the output is: Nutritional information per serving of None:…arrow_forward
- java. write grading program for a class with the following grading policies. thers a total of 2 quizzes, each graded on the basis of 10 points. theeres is 1 midterm exam and one final exam, each graded on the basis of 100 points. final exam counts for 50% of the grade, the midterm counts for 25%, and the 2 quizzes together count for a total of 25%. (Do not forget to normalize the quiz scores.) letter grade will be given based on the following criterion: 90 – 100 A 80 – 89 B 70 – 79 C 60 – 69 D 0 – 59 E program will read student’s scores from a txf file, save them in an arrayor arrays), process the arrays), print the student’s record, which consists of the name, 2 quiz and 2 exam scores as well along with students avg numscore for the course and final letter grade. please noteAll the scores are integers and a student name consists of no more than 10 characters. justify output filearrow_forwardNovice: How can i access a main class objects from outside the function? / Better Alternative? If i have 4 Student objects how can i print the information for the specific object given one parameter about the class, like the students Idnumber. What i came up with was making a checkId void function that takes the user input and runs an if else chain checking if the Id belongs to student 1-4 then printing the details of that classes object with the void function print. ideally i would want the if-else chain in the checkId function to call the print( student1-4) class object but im not sure how to properly do that. i dont think this is the best way to go about it, if you have any recommendations or alternatives please help me out.arrow_forward#this is a python program #topic: OOP Design a class Joker with parameterized constructor so that the following line of code prints the result shown in the output box. [You are not allowed to change the code below] #Write your class code here j1 = Joker('Heath Ledger', 'Mind Game', False) print(j1.name) print(j1.power) print(j1.is_he_psycho) print(“=====================”) j2 = Joker('Joaquin Phoenix', 'Laughing out Loud', True) print(j2.name) print(j2.power) print(j2.is_he_psycho) print(“=====================”) if j1 == j2: print('same') else: print('different') j2.name = 'Heath Ledger' if j1.name == j2.name: print('same') else: print('different') #Write your code for 2,3 here Output: Heath Ledger Mind Game False ===================== Joaquin Phoenix Laughing out Loud True ===================== different same Subtask: 1) Design the class using a parameterized constructor. 2) The first if/else block prints the output as ‘different’, but why?…arrow_forward
- Imagine a publishing company that markets its works. Create a class publication that stores the title (a string), author (string), pages (int), pulicationDate (string) and price (type float) of a publication. There should be two constructor i.e. default and parameterized. The default Constructor should initialize the data members to 0 or 0.0 or “” if integers, floating point or string respectively. The parameterized constructor should assign user defined values to the data members. The default constructor should be inline while the parameterized constructor should not be inline. There should be an input/get function to input the values to the data members and a Print() to display the contents of the class variables/datamembers. Create two objects of the class named book, and tape. The book should be created with default constructor, while tape with parameterized constructor. Call input/get for book object only. Then call Print() for both the objects to display the contents. Mention…arrow_forwardNote: Write a Java program given below Question # 1: Define a class for Students with field name, age, marks. Define getter and setter for all the fields. In the setter method, if age is less than 0, print that Age is less than zero. Similarly, if marks is less than zero or greater than 100, print in correct marks and don’t assign marks to member variable. In the Test class, create student’s object and assign the marks and age to appropriate values. Try assigning incorrect values to check if getter and setter methods work as expected.arrow_forwardRedo Programming Exercise 3 by overloading the operators as nonmembers of the class boxType. Write a test program that tests various operations on the class boxType.arrow_forward
- Write a class Runner having three private data members (distance, minutes, seconds) The class has A constructor which having no parameter – for setting values to zero or null.Getters/setters for data members.Write a function show() which displays the“The player covered “+distance+ “ in “ +minutes +” minutes , and “ + seconds+” seconds”; Write test Application that demonstrates the above class by calling all the methods, creating a Create 3 Runner objects, input values and then display the record of winner.arrow_forwardIms.taibahu.edu.sa/bbcswebdav/pid-1372401-dt-content-rid-171 C 回 80% 1 / 1 Assignment No.1 Question 1: Write a java program for a simple calculator. The program accept two numbers from user. The program consists from four classes are add, sub, mul and div. For each class, two constructors, first with no argument and second with argument. Add class for addition to get addition of two numbers, it include two methods: 1. Operation method with two parameters 2. To print result and to give a description for the method Sub class to do subtraction and it's inherit from Add class and it include 1. Operation method with two parameters 2. To print result and to give a description for the method 3. Overriding the print method" show it for subtraction" Mul class to do multiplications and it's inherit from sub class and it include 1. Operation method with two parameters 2. To print result and to give a description for the method 3. Overriding the print method “ show it for multiplication" div class…arrow_forwardYou are asked to write a discount system for a beauty saloon, which provides services and sells beauty products. It offers 3 types of memberships: Premium, Gold, and Silver. Premium, gold and silver members receive a discount of 20%, 15%, and 10%, respectively, for all services provided. Customers without membership receive no discount. All members receives a flat 10% discount on products purchased (this might change in the future). Your system shall consist of three classes: Customer, DiscountRate and Visit, as shown in the class diagram. It shall compute the total bill if a customer purchases $x of products and $y of services, for a visit. Also, write a test program VisitDriver (are not to be graded and optional) to exercise all the classes. Important: "Visit Class diagram - ERROR" Constructor method of Visit class must recieve Customer object instead of String name. Visit(Customer customer, Date date) The class DiscountRate contains only static variables and methods (underlined in…arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning