
Modify this program to use namespaces and separate compilation. using c++
-Put the class definition and other function declarations
-Place the implementations in a separate file.
-Distribute the namespace definition across the two files.
-Place the demonstration program in a third file.
-To provide access to names in namespaces, you may use local using declarations such as using std::cout; or use local using directives such as using namespace std; inside a block, or qualify names using the names of namespaces, such as std::cout.
-You may not use global namespace directives such as the following which are not in a block and apply to the entire file: using namespace std;"
code
#include <iostream>
#include<string>
using namespace std;
class PFArrayD
{
public:
PFArrayD( );
//Initializes with a capacity of 50.
PFArrayD(int capacityValue);
PFArrayD(const PFArrayD& pfaObject);
void addElement(double element);
//Precondition: The array is not full.
//Postcondition: The element has been added.
bool full( ) const { return (capacity == used); }
//Returns true if the array is full, false otherwise.
int getCapacity( ) const { return capacity; }
int getNumberUsed( ) const { return used; }
void emptyArray( ){ used = 0; }
//Empties the array.
double& operator[](int index);
//Read and change access to elements 0 through numberUsed - 1.
PFArrayD& operator =(const PFArrayD& rightSide);
~PFArrayD( );
private:
double *a; //For an array of doubles
int capacity; //For the size of the array
int used; //For the number of array positions currently in use
};
PFArrayD::PFArrayD( ) :capacity(50), used(0)
{
a = new double[capacity];
}
PFArrayD::PFArrayD(int size) :capacity(size), used(0)
{
a = new double[capacity];
}
PFArrayD::PFArrayD(const PFArrayD& pfaObject)
:capacity(pfaObject.getCapacity( )), used(pfaObject.getNumberUsed( ))
{
a = new double[capacity];
for (int i = 0; i < used; i++)
a[i] = pfaObject.a[i];
}
void PFArrayD::addElement(double element)
{
if (used >= capacity)
{
cout << "Attempt to exceed capacity in PFArrayD.\n";
exit(0);
}
a[used] = element;
used++;
}
double& PFArrayD::operator[](int index)
{
if (index >= used)
{
cout << "Illegal index in PFArrayD.\n";
exit(0);
}
}
PFArrayD& PFArrayD::operator =(const PFArrayD& rightSide)
{
if (capacity != rightSide.capacity)
{
delete [] a;
a = new double[rightSide.capacity];
}
capacity = rightSide.capacity;
used = rightSide.used;
for (int i = 0; i < used; i++)
a[i] = rightSide.a[i];
return *this;
}
PFArrayD::~PFArrayD( )
{
delete[] a;
}
//PROGRAM TO TEST PFArrayD
#include <iostream>
using namespace std;
class PFArrayD
{
<The rest of the class definition is the same as in Display 10.10.>
};
void testPFArrayD( );
//Conducts one test of the class PFArrayD.
int main( )
{
cout << "This program tests the class PFArrayD.\n";
char ans;
do
{
testPFArrayD( );
cout << "Test again? (y/n) ";
cin >> ans;
} while ((ans == 'y') || (ans == 'Y'));
return 0;
}
void testPFArrayD( )
{
int cap;
cout << "Enter capacity of this super array: ";
cin >> cap;
PFArrayD temp(cap);
cout << "Enter up to " << cap << " nonnegative numbers.\n";
cout << "Place a negative number at the end.\n";
double next;
cin >> next;
while ((next >= 0) && (!temp.full( )))
{
temp.addElement(next);
cin >> next;
}
cout << "You entered the following "
<< temp.getNumberUsed( ) << " numbers:\n";
int index;
int count = temp.getNumberUsed( );
for (index = 0; index < count; index++)
cout << temp[index] << " ";
cout << endl;
cout << "(plus a sentinel value.)\n";
}

Step by stepSolved in 4 steps with 1 images

- 19. Function declaration/function prototype is normally created in whereas function definition is normally created in A. Header file (.h), header file (.h) B. Implementation file (.c), header file (.h) C. Header file (.h), implementation file (.c) D. Implementation file (.c), implementation file (.c) 20. Which function prototype declaration is ILLEGAL? A. int IM_Awesome(credits, CGPA); B. int IM_Awesome( ); C. int IM_Awesome(int credits, float CGPA); D. int IM_Awesome(int, float);arrow_forwardWhat is a standard library? A. A library created by the programmer B. Libraries included as part of the C++ language C. Libraries that include blueprints of classes D. There are no standard librariesarrow_forwardC++ Question: Make an execution chart like the example below for the code provided. Example chart: An execution chart is a text version of the hierarchy. Indentation is used to indicate thesublevels or calls inside a call. It also contains the data exchange between the components asdesignated in the hierarchy chart. Given below is the execution chart that corresponds to thehierarchy chart of the property tax calculation program1.0 Main()2.0 CalculatePropertyTax()3.0 displayMessage( input string messageToDisplay)3.1 return double getHomeValue()3.2 return boolean checkHomeValue()3.3 return double applyPropertyTax(input double homeValue)3.4 displayPropertyTax(input homeValue)3.5 return Boolean queryMoreData()4.0 displayMessage(input string messageToDisplay)4.1 return char getYesNo()4.2 return char convertCase(input char)3.6 displayErrorMessage() More exlanation: example: 1.0 means it's of depth 1, line 0 then 2.0 means it's one call inside a function (aka it's inside another function)…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





