As part of an office automation suite, you are designing a \"Binder\" class to e
ID: 3548048 • Letter: A
Question
As part of an office automation suite, you are designing a "Binder" class to emulate a 3-ring binder. In essence, a Binder is a container that maintains a set of "Documents" in a linear order.
Assume that someone else has the responsibility of designing the "Document" class. The Document class will actually 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 proposed the following interface for the binders.
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;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.