Question
Objectives: 1. Separate class code into a declaration (header) and implementation components; 2. Implement a copy constructor; 3. Use the preprocessor directives #ifndef, #define and
Objectives:
1. Separate class code into a declaration (header) and implementation components;
2. Implement a copy constructor;
3. Use the preprocessor directives #ifndef, #define and #endif.
This assignment is an extension of Unit 11 Programming Assignment. You will modify your implementation of call_class. The class will still manage a dynamic array of call records. Call this program "call_stats8.cpp". You must separate the declaration and implementation for the class call_class into two separate files. Please put the class declaration in the file called call_class.h, and put the class implementation in the file called call_class.cpp. Your driver will be called call_stats8.cpp that is provided. However, you will need to modify it to test the functionality of your program.
Your input data will be in the file callstats_data.txt. The descriptions of the functions you will implement are as follows:
1. the copy constructor will perform a deep copy of an object.
2. (you implemented this in the previous program) the default constructor to initialize the state of your class. The default constructor will read the data from the file callstats_data.txt into the dynamic array call_DB. If call_DB becomes full, the function should call the function double_size to double the size (capacity) of call_DB. Remember, count and call_DB are private members of your class and do not need to be passed to an member function of your class.
3. (you implemented this in the previous program) is_empty is a Boolean public member function of the class. It has no formal parameter because count is a member of the state of the class (private member) and does not need to be passed to it because the state of the class if known to all member functions of the class. If count == 0 then true is returned; otherwise false is returned.
4. (you implemented this in the previous program) is_full is a Boolean public member function of the class. It has no formal parameters because count and size are members of the state of the class (private members) and do not need to be passed to it because the state of the class if known to all member functions of the class. If count == size then true is return; otherwise false. The size is the capacity which is the total number of cells allocated to call_DB.
5. (you implemented this in the previous program) search is an integer public member function that has only one formal parameter, the key. key is the cell phone number for the record you are search for. The array of records, call_DB and count are members of the state of the class and do not need to be passed to a member function of the class; The function will return the location of key in call_DB if it is there; otherwise -1 is returned.
6. (you implemented this in the previous program) add is a void public member function that inserts the information for a call into call_DB. Duplicates cell numbers are ok; add will prompt the user for the firstname, lastname, cell number, relays and call length. You may call process record to re-process when you add a new record. add no formal parameters.
7. overload operator - as a member function of call_class with chaining. This function will have the same functionality as the remove function. Recall the following about the function remove: remove is a void public member function thaqt deletes all records with the cell number stored in key. If duplicate records exist with the same cell number they must all be deleted. remove has only one formal parameter, the key. Note, because we are overloading with chaining we must return the current object *this.
8. (you implemented this in the previous program) double_size is a void public member function that doubles the capacity of call_DB. double_size has no formal parameters because size, count and call_DB are all members of the state of the class, call_class. First, size is multipled by two; second, memory is allocated using call_record *temp=new call_record[size]; third the records in call_DB are copied into temp with the statement temp[i]=call_DB[i] using a for loop. Forth, the old memory for call_DB is de-allocated using delete [ ] call_DB; Finally, call_DB is set to point to the new memory pointed to by temp using call_DB = temp.
9. (you implemented this in the previous program) process is a void public member function the has no formal parameter because call_DB and count are members of the state of the class.. The function process will calculate the net cost of a call (net_cost), the tax on a call (call_tax) and the total cost of the call (total_cost) using the number of relay stations (relays) and the length in minutes of the call (call_length) for all call records stored in call_DB. Please consider the following:
a. The tax rate on a call (call_tax) is simply based on the number of relay stations (relays) used to make the call (0<= relays <=5 then call_tax = 1%; 6<= relays <=11 then call_tax = 3%; 12<= relays<=20 then call_tax = 5%; 21<= relays <=50 then call_tax = 8%; relays >50 then call_tax =12%) .
b. The net cost of a call is calculated by the following formula: net_cost = ( relays / 50 x 0.40 x call_length).
c. The tax on a call is equal to net_cost x call_tax / 100.
d. The total cost of a call (rounded to the nearest hundredth) is calculated by the following formula: total_cost = net_cost + call_tax . All tax and cost calculations should be rounded to the nearest hundredths.
10. (you implemented this in the previous program) overload operator << as a friend function of call_class with chaining. This function will have the same functionality as the print (it will print to the screem). Recall the following about the function print: print is a void public member function that has no formal parameters because count and call_DB are members of the state of the class. The function will print every field of every call_record in call_DB to the screen.
11.(you implemented this in the previous program) the destructor to deallocate all memory allocated to call_DB. This function has no formal parameters because call_DB is a member of the state of the class. It will be called automatically by the compiler.
Use the driver call_stats8.cpp to help you implement this program.
Output Format for the overload operator<<:
Consider the following sample output table when designing and implementing "operator<<".See section Format of Output below. (The output is in the following order: firstname, lastname, cell phone number, relays, minutes, net cost, tax rate, call tax, total call cost)
Input Stream:
In the assignment you will declare one ifstream to bind your input to the file "callstats_data.txt"
Whenever a program performs file i/o you must include the "fstream" library. Format of the input data file(input filename is "callstats_data.txt"):
Do not include column titles (The order of the columns are as follows: firstname, lastname, cell phone number, relays, minutes)
The Code outline is below
/*
REMEMBER TO BREAK THIS FILE INTO 3 COMPONMENTS.
*/
#include
#include
#include
using namespace std;
class call_record
{
public:
string firstname;
string lastname;
string cell_number;
int relays;
int call_length;
double net_cost;
double tax_rate;
double call_tax;
double total_cost;
};
class call_class
{
public:
call_class();
call_class(const call_class &);
~call_class(); //de-allocates all memory allocate to call_DB by operator new.
bool is_empty(); //inline implementation
bool is_full();//inline implementation
int search(const string key);//returns location if item in listl; otherwise return -1
void add( ); //adds the informaation for a call record to call_DB
call_class & operator-(const string key); //removes an item from the list
void double_size();
void process();
ostream & operator<<(ostream & out_to_file, call_class & Org) //prints all the elements in the
//list to the screen and to the file "stats7_output.txt".
private:
int count;
int size;
call_record *call_DB;
};
/************************************************************************************************************************************/
//Name: default constructor
//Precondition:
//Postcondition:
//Decription: Reads the data file of call information (cell number, relays and call length) into the dynamic array of call record,
//call_DB. If the count because equal to the size the function double_size is called and the memory allocated to call_DB is doubled.
/************************************************************************************************************************************/
call_class::call_class()
{
}
/************************************************************************************************************************************/
//Name: copy constructor
//Precondition:
//Postcondition:
//Decription: performs a deep copy.
/************************************************************************************************************************************/
call_class::call_class(const call_class &);
/***********************************************************************************************************************************/
//Name: is_empty
//Precondition:
//Postcondition:
//Decription: returns true if call_DB is empty
/**********************************************************************************************************************************/
bool call_class::is_empty()
{
return count == 0;
}
/**********************************************************************************************************************************/
//Name: is_full
//Precondition:
//Postcondition:
//Decription: returns true if call_DB is full
/*********************************************************************************************************************************/
bool call_class::is_full()
{
return count == size;
}
/**********************************************************************************************************************************/
//Name: search
//Precondition:
//Postcondition:
//Decription: locates key in call_DB if it is there; otherwise -1 is returned
/*********************************************************************************************************************************/
int call_class::search(const string key)
{
return -1;
}
/*********************************************************************************************************************************/
//Name: add
//Precondition:
//Postcondition:
//Decription: adds the information for a call to call_DB; if call_DB is full, double_size is called to increase the size of call_DB.
/********************************************************************************************************************************/
void call_class::add( )
{
}
/********************************************************************************************************************************/
//Name: operator-
//Precondition:
//Postcondition:
//Decription: remove key from call_DB if it is there.
/*******************************************************************************************************************************/
call_class & call_class::operator-(const string key)
{
return *this;
}
/******************************************************************************************************************************/
//Name: double_size
//Precondition:
//Postcondition:
//Decription: doubles the size (capacity) of call_DB
/******************************************************************************************************************************/
void call_class::double_size( )
{
size *=2;
call_record *temp = new call_record[size];
for(int i=0; i { temp[i] = call_DB[i]; } delete [ ] call_DB; call_DB = temp; } /******************************************************************************************************************************/ //Name: process //Precondition: //Postcondition: //Decription: calculate the net cost, tax rate, call tax and total cost for every call record in call_DB. /*****************************************************************************************************************************/ void call_class::process() { } /****************************************************************************************************************************/ //Name: operator<< //Precondition: //Postcondition: //Decription: Overloading operator<< as a friend function. Prints every field of every call_record in call_DB // formatted to the screen and a file called "stats7_output.txt". /***************************************************************************************************************************/ ostream & operator<<(ostream & out, call_class & Org) { for(int i=0; i { out< <<" "< <<" "< } //Put code to OPEN and CLOSE an ofstream and print to the file "stats7_output.txt". return out; //must have this statement } /****************************************************************************************************************************/ //Name: destructor //Precondition: //Postcondition: //Decription: de-allocates all memory allocated to call_DB. This should be the last function to be called before the program // is exited. /***************************************************************************************************************************/ call_class::~call_class() { } //driver to test the functionality of your class. int main() { call_class MyClass; MyClass.print(); call_class YourClass = MyClass; return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started