The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
I need help!
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.
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"
Here is what i got so far:
#include <iostream>
#include <string>
#include <fstream>
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<count; 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<Org.count; i++)
{
out<<Org.call_DB[i].firstname<<" "<<Org.call_DB[i].lastname
<<" "<<Org.call_DB[i].relays<<" "<<Org.call_DB[i].cell_number
<<" "<<Org.call_DB[i].call_length<<endl;
}
//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;
}
callstats_data.txt :
Jean Hayward 9546321555 0 0 Marlon Brando 5612971340 5 50 John Kennedy 3051234567 8 25 Hillary Clinton 7542346622 24 17 George Bush 3054432762 15 30 Barack Obama 9544321011 50 100 Donald Trump 8776219988 87 82 Bernie Sanders 9042224556 4 5 Harry Ford 7877176590 11 1 Michelle Obama 5617278899 20 45 Ann Dunham 9546321555 4 3 Vladimir Putin 5612971340 79 86 Harriet Tubman 3051234567 8 25 Oprah Winfrey 5611234444 24 118 Charlotte Ray 3054432762 115 25 Tina Turner 8776219988 265 22 Shirley Chisholm 9042224556 2 5 Maritza Correla 7877176590 89 67 Margaret Thatcher 5617278899 40 56