Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 12, Problem 3P
Program Plan Intro
“Money” ADT Class
Program plan:
- For file “MoneyADT.h”:
- Include required header file.
- Define a class for “Money”.
- Declare the function for overload operator “<”, “<=”, “>’, “>=”, “+”, “-” and “==”.
- Declare the constructor for “Money” class.
- Declare the function for compute total amount, total dollars and total cents.
- Declare the function for operator “>>” and “<<”.
- Declare required variables.
- For file “MoneyADT.cpp”:
- Define function for overload operator “<”, “<=”, “>” and “>=”.
- Define function for “percent”.
- This function is used to compute the percentage amount for given money.
- Define function for arithmetic operator “+” and “-” with two arguments.
- Define function for overload operator “==”.
- Define function for overload operator “-” with one parameter.
- Define default constructor for “Money” class, constructor with one argument and two arguments.
- Define function “computeTotalAmount”.
- This function is used to compute the total amount.
- Define function “computeTotalDollars”.
- This function is used to compute the dollars in given amount.
- Define function “computeTotalCents”.
- This function is used to compute the cents in given amount.
- Define function “forDollarConversion” which is used to convert amount to dollar
- Define function “forCentsConversion” which is used to convert the amount to cents.
- Define function “forRoundedValue” which is used for convert the result in rounded value.
- Define function for input and output operator.
- For file “main.cpp”:
- Include required header file.
- Create an object for “Money” class.
- Create an object for “Money” class with argument.
- Declare variable for file input and file output.
- Open the given input file.
- Check the given file is found or not using “if” loop.
- Read the amount from file.
- Display the purse amount.
- Compare the given amount and purse amount.
- Compute sum of amount and purse and display it.
- Compute the difference of two amount and display it.
- Check the amount using the comparison operator “>=”.
- Check the amount using the comparison operator “>”.
- Check the amount using the comparison operator “<=”.
- Check the amount using the comparison operator “<”.
- Finally close input and output file.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Make a data type called Version that reflects the version number of a piece of software, like 115.1.1, 115.10.1, or 115.10.2. Implement the Comparable interface to make 115.1.1 less than 115.10.1, 115.1.1 less than 115.10.1, etc.
Write a program in the Java language requires the management of university students, where student data (name, student number, and specialization) are saved, and then he can add and delete study materials for the current semester, and you can also add the grade for each subject (with the addition of the final code for the degree automatically).Note: The class principle is used to solve this assignment.
only in java not in java c++
Create an interface EnhancedShape that extends Shape and also requires a method public double perimeter( ) to be implemented by any class that uses the interface.
Create a class file, an interface ehancedshape extends shape, and an interface shape file.
Chapter 12 Solutions
Problem Solving with C++ (10th Edition)
Ch. 12.1 - Suppose that you are defining an ADT class and...Ch. 12.1 - Which of the following files has a name that ends...Ch. 12.1 - Prob. 3STECh. 12.1 - Suppose you define a class in separate files and...Ch. 12.1 - Suppose you want to change the implementation of...Ch. 12.1 - What is the difference between an ADT you define...Ch. 12.2 - Consider the program shown in Display 12.5. Could...Ch. 12.2 - In Self-Test Exercise 7, we saw that you could not...Ch. 12.2 - Prob. 9STECh. 12.2 - Prob. 10STE
Ch. 12.2 - Consider the following function declarations from...Ch. 12.2 - Would the program in Display 12.8 behave any...Ch. 12.2 - Prob. 13STECh. 12.2 - In Display 12.7 there are two groupings for the...Ch. 12 - Add the following member function to the ADT class...Ch. 12 - Prob. 3PCh. 12 - Redo Practice Programs 2 from Chapter 11, but this...Ch. 12 - This Practice Program explores how the unnamed...Ch. 12 - Prob. 1PPCh. 12 - Redo (or do for the first time) Programming...Ch. 12 - Prob. 3PP
Knowledge Booster
Similar questions
- Put the client program in a separate file from the class, and divide the class into specification file (fraction.h) and implementation file (fraction.cpp), so your code will be in 3 separate files. Fraction.h #include <iostream>using namespace std; int gcd(int a, int b) { if (a == 0) return b; if (b == 0) return a; if (a == b) return a; if (a > b) return gcd(a - b, b); return gcd(a, b - a);} class Fraction {private: // numerator and denominator int n, d; public: // simplifies the fraction void simplify() { int g = gcd(n, d); n /= g; d /= g; } // default constructor Fraction() { n = 0, d = 1; } // parameterised constructor Fraction(int a, int b) { n = a, d = b; simplify(); } // prints the fration as n/d void print() const { cout << n << "/" << d; } // multiplies 2 fractions and returns it Fraction multipliedBy(Fraction f) const { f.simplify(); Fraction r; r.n = n * f.n; r.d = d * f.d; r.simplify(); return r; } // divides two fraction and…arrow_forwardCreate a Java project that shows the benefits of using generic types besides the examples from the activity. Summarize your answers and explanation for how your code examples work in 300 wordsarrow_forwardCreate a Java project using your IDE and name it using your name ( Ahmed ) and your ID ( 2051510377 ) Implement all the required classes in the default packagearrow_forward
- Does anybody know whether it's possible to simultaneously extend two distinct interfaces? Obviously, this isn't happening for no purpose.arrow_forwardWhen it is useful to use extension methods? Question 21 options: a) All the answers are correct b) when extending functionalities of an interface type c) When extending functionalities of classes that can't be inherited from (e.g. sealed classes) d) when extending functionalities of a third party library that we don't have access to the source codearrow_forwardHey there I am struggling with creating a second class module in PYTHON - that would import an already existing class I have finished from another module file called LANDINGSPOT, the class I am struggling with follows the exact order below* - class PLANE first-class which is done (Landingspot CLASS with objects ID, city, country ) and am trying to create another class module PLANE. (flightNumber, Start, goingTo). Each class would be eventually reading from text files with some spaces and commas separating randomly that’s where they would be getting data but that's for another module, which would need to import PLANE class. 'As suggested by its name, this class represents a 'Plane' from one landingSpot to another landingSpot in the program. Each Plane object must have a flightNumber (the unique 6-character code containing 3 letters followed by 3 digits), Start place, and a goingTo. Both the Start and goingTo must be LandingSpot objects within the…arrow_forward
- You are given a class with synchronized method A and a normal methodB. If you have two threads in one instance of a program, can they both execute A at the same time? Can they execute A and B at the same time?arrow_forwardYou are given a class with synchronized method A and a normal methodB. If you have two threads in one instance of a program, can they both execute A at the same time?Can they execute A and B at the same time?arrow_forwardFor how much better of a runtime can Interfaces prove to be than abstract classes?arrow_forward
- Suppose we had support for multimethods instead of or in addition to overloading. Explain how you would implement the pretty printer of Project 1 using multimethods instead of having a print() method in each class of the hierarchy. What would be the advantage of using multimethods? You can simply use the same syntax as for overloading and indicate where the multimethod dispatch happens.arrow_forwardWrite one word answers for the following: a.On compiling a file with the name “Demo.java” having a single class named Test, what is the name of the bytecode file that is created? b.When a method in asubclass has exactly the same signature as a method in the superclass, what is it known as?arrow_forwardConsider the following code. Replace the tags _??1_ and _??2_, respectively, by filling in the text fields below, such that the interface myInterface inherits from interfaces A and B and declares an (abstract) interface method trim with one String argument returning an int. interface A {public static final int x = 10;}interface B {public static int foo(int x){ return x+1; }}interface myInterface extends A _??1_ B { // replace _??1_ public int _??2_ (String s); // replace _??2_ } _??1_:Question Blank 1 of 2._??2_:Question Blank 2 of 2.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education