For this question, we will be dealing with an inheritance hierarchy for a class
ID: 3582583 • Letter: F
Question
For this question, we will be dealing with an inheritance hierarchy for a class called Utility, that implements accounts for customers with the given utility. There are many different kinds of utilities, these include Electric, Gas, Water and Phone, among others. Every Utility has in common the fact that a customer has a 14 digit account number (implemented as an array of characters, not an int). Also, every customer has a balance that they owe the company. For any utility, there is a function bill which uses information in a subclass (and in the superclass, see the individual descriptions below) to calculate how much the customer owes, and returns this amount. Another function common to all utilities is pay which accepts an amount as its parameter, and reduces the balance by that amount. It should also have an accessor function for the account number.
One subclass of Utility is Electric. This class should store, in addition to the information it inherits from the superclass, the price per kilowatt hours (or price for short). It should also store how much the customer used this month (or rather, unbilled electricity). It should have mutator functions to set the amount of Kilowatt hours the customer used this month, and the price. The bill function defined for this class should take the amount of electricity that the customer used and multiply it by the price. It should add this to the balance stored in the superclass and return the total balance. It should also zero out the amount of kilowatt hours the customer used, since customers would get upset if they were billed twice for the same electricity.
Another subclass of Utility is Water. Water is billed at a steady rate to all customers, irrespective of how much they used. Therefore, this class should store the monthly amount. It should have a mutator function for this variable. Its billfunction should apply a 1.5% penalty to the amount the customer owes (unpaid balance), and add the monthly rate to the balance. It should return the total balance.
A: Write the .h file for the class Utility.
B: Write .h file for the class Water.
C. Implement the function bill written in the class Water.
D. Write a function that accepts as its parameter an array of pointers to different utility accounts, and its length. It prints out every account number, and how much each customer owes. For each account, it also solicits from the user a payment, and applies that amount as a payment to the account.
Explanation / Answer
This class will be the player, it will react on Key presses (move in the right direction) and it will check for collisions. It will update every tick from the engine. How we will do these things I shall explain later. Before we make our player class, let’s think for a moment what we need in it. First of all we need to be able to retrieve the location of the player (x,y) for drawing purposes. Secondly we need an update function which will move the player, if it has to be moved, which will attack, if it has to attack, and which will check if the player is actually still alive. Thirdly we need 4 functions which can set the directions.
So our class will look like this:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.