Modify this program to use namespaces and separate compilation. using c++ -Put the class definition and other function declarations Programming Projects 517 in one file. -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 #include 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 using namespace std; class PFArrayD { }; 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"; }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Modify this program to use namespaces and separate compilation. using c++
-Put the class definition and other function declarations Programming Projects 517 in one file.
-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";
}

 

note:don't use chegg

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY