| Assigned | Sept. 11, 2000 |
| Due | Sept. 25, 2000 |
The ADT is one of the most powerful and important ideas in computer science. This project will give you some exercise in using ADTs. It will also give you additional experience in designing and implementing a solution in response to a set of requirements.
You will get a chance to see how exceptions can be used to handle error situations.
You will write a Makefile, include headers from multiple directories, and compile code from multiple directories. These are commonly used techniques in industry, so they're worth learning for future reference.
Here are your tasks:
/afs/umbc.edu/users/r/h/rheingan/pub/CMSC341/
template <class Comparable>
class Database {
private:
vector<Comparable> _data;
int _nrecs;
public:
// big 4
Database();
Database(string str); //passing a file name as parameter
Database(const Database &);
~Database();
const Database & operator=(const Database &);
//added PUBLIC functions
void sort(int direction, int field_nr);
void merge(string dbname);
Database & select(int field_nr, int criterion, string value);
void remove(int field_nr, int criterion, string value);
void print(ostream & out);
};
Specifically, the arguments are a list of zero or more command and argument-list pairs and the name of the file containing the database. Items on the command line are separated by tabs. When multiple commands are given, they should be executed in order, with the result database of the first becoming the input database for the next. If no commands are given, the program should print the contents of the input database.
The commands are:
For example, the command
/afs/umbc.edu/users/r/h/rheingan/pub/CMSC341/Proj1/Makefileand modify it as needed.
/afs/umbc.edu/users/r/h/rheingan/pub/CMSC341/Proj1/SetException.Hand
/afs/umbc.edu/users/r/h/rheingan/pub/CMSC341/Proj1/SetException.C
An exception can be "thrown" at any point in a program when an exceptional situation occurs. For example, an Overflow exception might be thrown when a quotient has a denominator of zero. An exception is thrown by using the syntax "throw exception". Typical code for Overflow would be:
if (denom == 0)
throw Overflow()
else
quotient = numer/denom;
When an exception is thrown, the normal flow of control is terminated while a suitable "catcher" is sought along the calling sequence. For example, part of your implementation might look like this:
bool Database::remove (Record & x) {
if (isEmpty()){
string ErrMessage = "Attempt to remove record from empty database";
throw SetException(ErrMessage);
}
// otherwise, continue processing
A function that calls remove might check for an empty database beforehand,
or it might have code like this:
try {
Database1.remove( somerecord);
}
catch (SetError & Exceptn){
cerr << "Exception:" << Exceptn.errorMsg() << endl;
}
What happens when the call to remove is made on an empty database is that
remove throws an exception. As the call is inside a "try" block, control
passes to the catch block that follows, which then deals with the exception.
If there were no enclosing try-catch blocks, the exception would not
be caught, and execution would terminate.For this project, all that you need to deal with is throwing appropriate error conditions.
enum yr {unspecified,freshman, sophomore, junior, senior, grad};
class Student {
private:
string _name;
string _major;
yr _yr;
int _idNr;
string _emailAddr;
string _date;
public:
//big 4
//constructors
Student();
Student(string name, string major, yr Year, int IdNr, string
EmailAddr, string Date);
Student (const Student &);
//destructor
~student();
//assignment
const Student & operator=(const Student &);
//Accessors
string getName() const;
string getMajor() const;
yr getLevel() const;
int getIdNr()const;
string getEmailAddr()const;
string getStudentDate()const;
//Mutators
void changeName(const string & NewName);
void setMajor(const string & NewMajor );
void setLevel(int NewLevel);
void setIdNr( int newIdNr);
void setEmailAddr(const string & newID);
void setStudentDate(const string & newDate);
//output function
friend ostream & operator <<(const ostream & O, const Student & S);
};
Cheating in any form will not be tolerated. Please re-read the Project Policy handout for further details on honesty in doing projects for this course.
Remember, the due date is firm. Submittals made after midnight of the due date will not be accepted. Do not submit any files after that time.
Submit the files using the procedure given to you for your section of the course.
A copy of the executable will be available for you to try out. Stay tuned.