Ask C/C++ Expert


Home >> C/C++

Aim: Gain experience developing programs using STL containers and inheritance.
On completion you should know how to:

- Write C++ code using STL container class objects.
- Use inheritance to facilitate programming with objects.
-Gain experience writing and debugging O-O programs incrementally.

Prerequisites:
This assignment involves writing a program to handle the billing of electricity, gas and phone accounts of a meter reading and billing company. Meter reading information on electricity, gas and phone usage is contained in the file "usage.txt". Each record begins with the service type (i.e. elect, gas or phone) followed with customer details:

BillingRecord

Supplier's name
Customer's name
Customer's address
Account balance
Days since last reading

. . . and other usage information which depend on the service type:

Electricity

Gas

Phone

Previous reading

Previous reading

Number of local calls

Current reading

Current reading

Local call rate

Rate 1

Heating value

Long distance call time

Rate 1 threshold

Rate

Long distance call rate

Rate 2

Supply charge

Line rental

Supply charge

 

 

This information is used to calculate the customer's next bill. The processing of the billing records is complicated because some suppliers offer their customers discounts if they subscribe to more than one service from them. To solve this problem you are to use object oriented programming with inheritance to represent the different types of billing records. Polymorphism will also be used to allow all records to be processed efficiently in the one array.

You should complete this assignment according to the following steps and demo & submit your work according to the Submit and Demo instruction given at the end of this document. Each step is worth 2 marks and 2 marks is awarded for demoing your work on time in the lab. All code is to go in 5 files: BillRecord.h, BillRecord.cpp, BillSystem.h, BillSystem.cpp and main.cpp.

Billing System Design

The system is comprised of a BillSystem class object that own a vector of BillRecord objects in implemented in appropriately named files. The BillRecord class is a base class that has 3 derived classes for representing the 3 types of bills (elect. gas & phone). The BillSystem has public functions for reading the data file into the BillRecord vector, processing the billing information and displaying the records on the screen. Some of the functions of the BillRecord class are overridden to handle the different types of data in the derived classes.

Step 1
For step 1, get the BillRecord base class working. Examine the incomplete code in the provided files and complete the function definitions of class BillRecord and BillSystem so that the customer details (only) are read into each BillRecord of the vector BRecs from "usage.txt". Then test that main() displays the first 10 customer details on the screen, as shown below. Note: don't forget to delete the pointers in vector BRecs in the BillSystem destructor.

#  Service  Supplier  Customer       Address                    AccBal  Days

1

Phone

Origin

George Carter

24

Dingo

St Exeter

SA

27.49

28

2

Gas

EA

Paul Scott

21

Beach

Rd Barham

NSW

92.98

30

"

"

"

"

 

 

"

 

"

"

10

Gas

EA

Carol Harris

67

Broke

St Milton

NSW

20.45

29

Step 2
Declare the derived BillRecord classes: ElectBillRecord, GasBillRecord and PhoneBillrecord in BillSystem.h. These classes inherit the base class BillRecord. Make sure you provide private data members for storing the relevant usage information shown on page 1. Change the BillRecord class's private data member: AccountBalance and DaysSinceLastReading to protected to make them available to the derived classes. Also, make functions: ReadUsageInfo() and DisplayUsageInfo() into virtual functions so that they can be overridden by the base classes.

Now provide the derived classes with their versions of functions: ReadUsageInfo() and DisplayUsageInfo() to read and display their usage information appropriately.

Modify ReadFile() in BillSystem.cpp so that it reads the service type and then allocates a ElectBillRecord, GasBillRecord or PhoneBillrecord accordingly using the new operator. Then call their ReadCustDetails() and ReadUsageInfo() functions to have the data in the file read appropriately. You might have to work on the code in each ReadUsageInfo() function to get each derived class reading its file data correctly.

When you complete this step run the main() again to display 5 records showing the Customer and usage info on the screen something like this:

# Service Supplier Customer        Address                    AccBal Days

1   Phone   Origin   George Carter  53 Dingo St Exeter SA       27.49   28

(LCalls: 283, 0.14        DCalls: 245, 0.32     Rental: 0.44)

2   Gas     EA       Paul Scott     84 Beach Rd Barham NSW      92.98   30

(Readings: 14148, 14224     HV:38.40       Rate: 0.039 SuppC: 0.56)

3   Elect   Alinta   Brian Crowe    61 Beach Rd Hanwood WA      18.06   31

(Readings: 113144, 113568   R1: 0.28 R1Th: 535 R2: 0.30 SuppC: 0.86)

"             "           "           "              "          "

Step 3

To win more customers Dodo and Alinta provide 15% and 20% discount, respectively, to all customers who subscribe to all three services from them. To deal with this add a protected data member to the BillRecord class named Discount and a public member function named SetDiscount(float d) for setting it. Also set Discount to one in the constructor.

There are various methods for finding which customers should have the discount applied. You can devise your own method if you wish but try to keep it efficient. The processing for this should be done in a public member function in the BillSystem class named CalDiscounts()..

One suggestion for finding the discounted records is to use a multiset with a user defined comparison object for ordering the BillRecord pointers. The comparison object should compare the BillRecords first by name and second by address. When all Dodo or Alinta records are inserted into this multiset, customers with the same name and address will be grouped and can be accessed with multiset functions: count(), lower_bound() and upper_bound(). (E.g. erase all BillRecord pointers with a count less than 3.) Once the discount pointers are found they can be dereferenced to set the discount appropriately. Test your code by uncommenting the "step-4" code in main() and print on the screen the number of discount customers Dodo and Alinta have.

Step 4
Add two more public member functions to the BillSystem class named CalBills() and PrintReport(). Also add a public pure virtual function: UpdateBalance() in the BillRecord class and override this in the derived classes. UpdateBalance() should calculate the BillAmount and add this to the AccountBalance. The BillAmount is calculated as follows:
Elect : C = CrntReading - PrevReading;
P = SuppyCharge * DaysSinceLastReading;
If (C <= R1Thld) BillAmt = (C * Rate1 + P) * Discount - AccBalance;
Else BillAmt = (R1Thld * Rate1 + (C - R1Thld) * Rate2 + P) * Discount - AccBalance;
Gas : C = CrntReading - PrevReading;
P = SuppyCharge * DaysSinceLastReading;
BillAmt = (C * HeatingValue * Rate) * Discount - AccBalance;
Phone : L = LocalCallRate * NumLocalCalls D = LDistCallRate * LDistCallTime
P = LineRental * DaysSinceLastReading; BillAmt = (L + D + P) * Discount - AccBalance;
Note: the AccountBalance should be set to zero after the BillAmount is calculated.

PrintReport() should print the first 5 records similar to Step-1 with the "AccBal" and "Days" replaced with "BillAmt". Also, print the names and addresses of all Dodo and Alinta customers who have discounts.

Attachment:- project.zip

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M92836793
  • Price:- $120

Guranteed 48 Hours Delivery, In Price:- $120

Have any Question?


Related Questions in C/C++

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As