Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

As part of an office automation suite, you are designing a “Binder” class to emu

ID: 3717467 • Letter: A

Question

As part of an office automation suite, you are designing a “Binder” class to emulate a three ring binder. In essence, a Binder is a container that maintains a set of “Documents” in a linear order.
Assume that someone else has a responsibility of designing the “Document” class. The Document class will eventually be a base class for several different kinds of documents, such as letters, articles, slide sets, etc.
The most essential operations on a Binder are to add a Document object at a specific position (given as an integer) or to fetch a Document previously inserted into such a position.
A junior programmer has proposde the following interface for binders.
class bBnder { Public: Binder(int maxDocuments); void put (int position, Document doc); Document get (int position); int numberOfDocuments() const; private: //data structure to be selected later };
In your best C++ style, rewrite this proposal to conform to appropriate C++ standards for robust and reusable classes. As part of an office automation suite, you are designing a “Binder” class to emulate a three ring binder. In essence, a Binder is a container that maintains a set of “Documents” in a linear order.
Assume that someone else has a responsibility of designing the “Document” class. The Document class will eventually be a base class for several different kinds of documents, such as letters, articles, slide sets, etc.
The most essential operations on a Binder are to add a Document object at a specific position (given as an integer) or to fetch a Document previously inserted into such a position.
A junior programmer has proposde the following interface for binders.
class bBnder { Public: Binder(int maxDocuments); void put (int position, Document doc); Document get (int position); int numberOfDocuments() const; private: //data structure to be selected later };
In your best C++ style, rewrite this proposal to conform to appropriate C++ standards for robust and reusable classes. As part of an office automation suite, you are designing a “Binder” class to emulate a three ring binder. In essence, a Binder is a container that maintains a set of “Documents” in a linear order.
Assume that someone else has a responsibility of designing the “Document” class. The Document class will eventually be a base class for several different kinds of documents, such as letters, articles, slide sets, etc.
The most essential operations on a Binder are to add a Document object at a specific position (given as an integer) or to fetch a Document previously inserted into such a position.
A junior programmer has proposde the following interface for binders.
class bBnder { Public: Binder(int maxDocuments); void put (int position, Document doc); Document get (int position); int numberOfDocuments() const; private: //data structure to be selected later };
In your best C++ style, rewrite this proposal to conform to appropriate C++ standards for robust and reusable classes.

Explanation / Answer

#include<iostream>
#include<fstream>
using namespace std;
const int max_docs = 100;
class Document
{
int letters;
int articles;
int slides;
int slide_sets;
public:
Document()
{
letters = 1;
articles = 1;
slides = 1;
slide_sets = 1;
}
};
class Binder
{
public:
   Binder(int maxDocuments)
   {
   no_of_docs = maxDocuments;
   }
   void put (int position, Document doc)
   {
   if(position < no_of_docs)
   doc_array[position] = doc;
   else
   cout <<"Cant insert more documents..no space.." << endl;
   }
   Document get (int position)
   {
   if(position < no_of_docs)
   return doc_array[position];
   }
   int numberOfDocuments() const
   {
   return no_of_docs;
   }
private:
   // data structure to be selected later
   Document doc_array[max_docs];
   int no_of_docs;
};
int main()
{
Binder new_binder(13);
Document doc;
new_binder.put(2,doc);
cout << "Number of documents in binder is " << new_binder.numberOfDocuments() << endl;
return 0;
}