Question
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
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.
b.
c. d.
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%) .
The net cost of a call is calculated by the following
formula: net_cost = ( relays / 50 x 0.40 x call_length). The tax on a call is equal to net_cost x call_tax / 100. 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.
(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.
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%) .
The net cost of a call is calculated by the following
formula: net_cost = ( relays / 50 x 0.40 x call_length). The tax on a call is equal to net_cost x call_tax / 100. 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.
(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.
10.
11.
the destructor to de- his function has no formal
(you implemented this in the previous program)
allocate all memory allocated to call_DB. T
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)
Jean Hayward Marlon Brando John Kennedy
Input Stream:
9546321555 5612971340 3051234567
0 0 5 50 8 25
0 0.01
2 0.01 1.6 0.03
0 0 0.02 2.02 0.05 1.65
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)
Jean Hayward Marlon Brando John Kennedy Hillary Clinton George Bush Barack Obama Donald Trump Bernie Sanders Harry Ford Michelle Obama Ann Dunham Vladimir Putin Harriet Tubman Oprah Winfrey Charlotte Ray Tina Turner Shirley Chisholm Maritza Correla Margaret Thatcher
9546321555 5612971340 3051234567 7542346622 3054432762 9544321011 8776219988 9042224556 7877176590 5617278899 9546321555 5612971340 3051234567 5611234444 3054432762 8776219988 9042224556 7877176590 5617278899
0 0 5 50 8 25
24 17 15 30 50 100 87 82
4 5 11 1 20 45
4 3 79 86 8 25 24 118 115 25 265 22 2 5 89 67 40 56
Format of Output to screen:
(the order of the columns is as follows: firstname, lastname, cell phone number, relays, minutes, net cost, tax rate, call tax, total call cost)
Jean Hayward Marlon Brando John Kennedy Hillary Clinton George Bush Barack Obama Donald Trump Bernie Sanders Harry Ford Michelle Obama Ann Dunham Vladimir Putin Harriet Tubman Oprah Winfrey Charlotte Ray Mary Carter Tina Turner Shirley Chisholm Maritza Correla Margaret Thatcher
9546321555 5612971340 3051234567 7542346622 3054432762 9544321011 8776219988 9042224556 7877176590 5617278899 9546321555 5612971340 3051234567 5611234444 3054432762 9544321011 8776219988 9042224556 7877176590 5617278899
0 0 5 50 8 25
24 17 15 30 50 100 87 82
4 5 11 1 20 45
4 3 79 86 8 25 24 118 115 25 43 10 265 22 2 5 89 67 40 56
0 0.01
2 0.01 1.6 0.03 3.26 0.08 3.6 0.05 40 0.08 57.07 0.12 0.16 0.01 0.09 0.03 7.2 0.05 0.1 0.01 54.35 0.12 1.6 0.03 22.66 0.08 23 0.12 3.44 0.08 46.64 0.12 0.08 0.01 47.7 0.12 17.92 0.08
0 0 0.02 2.02 0.05 1.65 0.26 3.53 0.18 3.78
3.2 43.2 6.85 63.92 0 0.16 0 0.09 0.36 7.56 0 0.1 6.52 60.87 0.05 1.65 1.81 24.47 2.76 25.76 0.28 3.72 5.6 52.24 0 0.08 5.72 53.43 1.43 19.35
#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