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
Starting Out with C++ from Control Structures to Objects (9th Edition)
Modern Database Management
Mechanics of Materials (10th Edition)
Starting Out With Visual Basic (8th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
- Javaarrow_forwardCreate a class Student that contains three members: roll no, name and mark, and threefunctions. Write a first inputStudent() function to get data of student class. Write a secondgetMark() function that returns a student’s mark. Write a third display() function thatdisplays a student’s data. In a main() function, you need to declare 40 students and get dataof all students by using inputStudent() function. And also use a pointer array to keep allstudents by mark greater than 50 and display the searching data of each student in thatpointer array (Use the access operator -> to access a pointer points to member functions ofthe Student class)arrow_forwardSuppose in Islamabad International Airport the plans arrivals and departures are frequent and they are moving with a kinetic energy. Your task is to write a class to find the kinetic energy of an airplane coming from UK having the mass and the velocity known to pilots only. You are a pilot so your captain of the plane has given you the task to write a class to perform the calculation, the function must be defined outside the class. Your task is to provide the mass and velocity as arguments to the function and then display the kinetic energy without returning a value.arrow_forward
- Based on the class Product defined above, the member function sell() is now to be implemented. If number_items_to_sell is negative, then this variable is to be set to zero inside the function for further processing. When selling, two things can happen. First, you can have more items in stock than items to be sold. In this (good) case, the function is to reduce the number of items in stock by the number of items to be sold. Second, you have fewer items in stock than items to be sold. In this case, all items in stock are to be sold, and the number of items in stock is to be set to zero. In both cases, the function returns the money made during the sale (in Cents). This function definition is to be put into the file task5.cpp.arrow_forwardWRITE PLEASEJAVA 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 rade. please noteAll the scores are integers and a student name consists of no more than 10 characters. justify output filearrow_forwardquick answer pleasearrow_forward
- Problem Class In this exercise, you are going to create the Problem class. The Problem class is used to help simulate a math fact, for example: 2 + 5 = Your class needs to contain two contructors, one that takes String, int, int that represts the operator sign(+, -, *, or /), the minimum, and maximum values for the number range, and a second constructor that takes only a String that represents the operator sign. For the second constructor, the minimum should default to zero and the maximum to ten. Your Problem object should generate 2 random integers between the minimum and maximum values (inclusively). Each Problem object should only have one set of numbers that do not change. While you may include additional helper methods, two methods need to be available to the user. The first is the answer method that should return a double that represents the answer to the problem. The second is the toString that should return a String that represents the problem. The format should be: number…arrow_forwardThis is the tester of two classesarrow_forwardProblem Class In this exercise, you are going to create the Problem class. The Problem class is used to help simulate a math fact, for example: 2+5= Your class needs to contain two constructors, one that takes String, int, int that represents the operator sign(+,-, *, or /), the minimum, and maximum values for the number range, and a second constructor that takes only a String that represents the operator sign. For the second constructor, the minimum should default to zero and the maximum to ten. Your Problem object should generate 2 random integers between the minimum and maximum values (inclusively). Each Problem object should only have one set of numbers that do not change. While you may include additional helper methods, two methods need to be available to the user. The first is the answer method that should return a double that represents the answer to the problem. The second is the toString that should return a String that represents the problem. The format should be: number…arrow_forward
- Exercise 6 - Loaded Coin Simulation Make a new class in the Lab2 project called LoadedCoinSim that simulates the toss of a loaded coin. A coin is loaded when it is constructed such that it is more likely to land on one value than another. Assume the probability the coin will land head is HEAD_PROB, and declare that as a constant in your program. Initially, use a value of 0.75, which means 75% chance the coin will show heads. Given this probability, simulate ten coin tosses and displaying the result. At the end, display the number of times the coin showed heads. The output should appear like this: Toss 1: HEADS Toss 2: HEADS Toss 3: HEADS Toss 4: TAILS Toss 5: HEADS Toss 6: HEADS Toss 7: HEADS Toss 8: HEADS Toss 9: TAILS Toss 10: HEADS Number of heads = 8arrow_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_forwardIN C++, create a class called Employee that includes three pieces of information as data members—a first name (type string), a last name (type string) and a monthly salary (type int). Your class should have a constructor that initializes the three data members. Provide a set and a get function for each data member. If the monthly salary is not positive, set it to 0. Write a test program that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary. Then give each Employee a 10 percent raise and display each Employee’s yearly salary again.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning