the last one
From: sudeep (sudeep_calling_at_yahoo.co.in)
Date: 10/17/04
- Next message: Ioannis Vranos: "Re: Summary of C++ (ANSI/ISO) standards"
- Previous message: sudeep: "one more"
- Next in thread: Rolf Magnus: "Re: the last one"
- Reply: Rolf Magnus: "Re: the last one"
- Reply: JKop: "Re: the last one"
- Reply: Michael Kurz: "Re: the last one"
- Reply: Chris Theis: "Re: the last one"
- Reply: Siemel Naran: "Re: the last one"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 17 Oct 2004 03:23:32 -0700
Data Storage
Problem Statement
In an organization there are 3 kinds of people: Staff, Students and
Research Associates. Research Associates are actually students who are
considered as staff, and are employed for specific projects.
You will have to create a (non-persistent) data storage mechanism in
your implementation, which allows the management of data associated
with all 3 kinds of people. Furthermore, there will be a standardized
access mechanism for accessing the data.
Program
#include "classes.h"
int main(){
PeopleContainer pc;
//add a student
Person *p = (Person *) new Student("FPGDST","d0253001");
p->SetName("gopu");
p->SetGender('M');
p->SetDateOfBirth("20-03-81");
pc.Add(p);
//another student
p = (Person *) new Student("FPGDST","d0253002");
p->SetName("radha");
p->SetGender('F');
p->SetDateOfBirth("18-12-81");
pc.Add(p);
//add staff
p = (Person *) new Staff("18-05-2000",'A');
p->SetName("sunita");
p->SetGender('F');
p->SetDateOfBirth("18-12-81");
pc.Add(p);
//a student
Student s1("FPGDST","d0253004");
s1.SetName("sandeep");
//make the student an RA
p = new RA(s1);
pc.Add(p);
//get all the students
PeopleContainer *ptrSC = pc.GetStudents();
PeopleIterator si = ptrSC->NewPeopleIterator();
cout<<"Output 1"<<endl;
p = si.First();
while(!si.IsOver()){
p->ShowDetails();
p = si.Next();
}
//all staff with given grade
cout<<endl<<"Output 2"<<endl;
PeopleContainer *ptrStaff = pc.GetStaffByGrade('X'); //invalid
grade
if(ptrStaff){ //check return if no staff found
PeopleIterator sti = ptrStaff->NewPeopleIterator();
p = sti.First();
do{
p->ShowDetails();
p = sti.Next();
}while(p!=NULL);
}
//remove a person
cout<<endl<<"Output 3"<<endl;
cout<<pc.Remove("sudeep")<<"-";
cout<<pc.Remove("sandeep");
return 0;
}
(Note - new-lines have been printed in main(). No output from
the
implemented classes should have a new-line)
You are required to implement the following classes
Class: Person
Methods:
Person()
Person(char*,char,char*) /*arguments will be the name, gender(`M' or
`F') and date */
SetName(char*)
SetGender(char )
SetDateOfBirth(char *)
char* GetName()
char GetGender()
ShowDetails() /* should list the name, gender and date of birth
separated by `:' and terminated by `#'*/
Class: Staff
Methods:
Staff()
Staff(char *, char) //joining date, grade will be passed
SetJoiningDate(char *)
SetGrade(char)
char GetGrade()
ShowDetails() /*should list person details (as in Person), and then
list the joining date, and grade separated by `:' (colon) and
terminated by `#' */
Class Student
Methods:
Student()
Student(char *, char*) //course and roll number
SetCourse(char *)
char* GetRollNumber()
ShowDetails() /* should list person details (as in Person) and then
list the course and the roll number separated by `:' and terminated by
`#' */
Class RA
Members:
RA(const Student &)
ShowDetails() /* should list the details of the person, staff and
student separated by `:' and teminated by a `#' - note this is
different from the previous descriptions of ShowDetails*/
Class PeopleContainer
Methods:
bool Add(obj *) /*where obj is pointer of type Person, Staff, Student
or RA - addition is at end of current list*/
int Remove(char *name) /* remove all people with given name and return
the number of people removed or 0 */
int Remove(obj *) /* remove all people with same name as the name of
the passed object and return the number of people removed or 0 */
Sort() /*sort the contents on the basis of type in the order Person,
Staff, RA, Student. Within a type, the order of insertion must be
maintained*/
ShowPeople() /*Show Details of all the people in the container*/
PeopleContainer * GetStudents() /*returns another container containing
students only - any modifications to the contents of returned
container must not affect the original container*/
PeopleContainer * GetFemales() /*returns another container containing
females only*/
PeopleContainer * GetStaffByGrade(char grade) /* return a container
that has all staff of given grade. If no grade or invalid is passed,
include all Staff and RAs*/
PeopleIterator NewPeopleIterator() /*returns an iterator associated
with the current PeopleContainer object*/
Class PeopleIterator
Methods:
Person* First() //returns the first element of the associated
container and the current now points to the first element
bool IsOver() // returns true if the iteration is over - i.e. Next()
will return NULL
Person* Next() /*if there is a next element in the container, it
becomes the current element and is returned. If there is no next
element, NULL is returned and current element remains the same*/
Restriction
It should not be possible to create an iterator except by using
PeopleContainer::NewPeopleIterator() method Additional Points
Valid grades for Staff will be `A', `B', `C' and `D' only. Research
Associate (RA) can have only one grade, which is `R'
Do not make assumptions about the maximum number of persons that may
be stored in the PeopleContainer.
For any method involving display, if associated data is not found then
the output for that field is suppressed (the other delimiters should
be displayed)
Though the test program will check only the specified methods of the
various classes, the students may have to use other methods and
members to aid them in the implementation.
While adding a Research Associate (RA) to the container, if a Student
having the same RollNumber is found, that Student should be removed
from the container. Do not worry about finding an exact match for all
the attributes.
PeopleContainer should be heterogeneous with reference semantics.
Objective
Using the concepts of Encapsulation, Access Mechanisms, Information
Hiding, Inheritance and Polymorphism
Getting familiar with the concepts of Object Oriented Design,
Container-Contained relationships and Iterators.
Concretizing theoretical concepts learnt in class, with practical
implementation in C++.
Submission Procedure
You must have a header file DataStore.h and C++ file DataStore.cpp.
No main() should be present in DataStore.cpp.
We will test your code against our own main routine similar to the one
given as the example usage, but using more comprehensive inputs, and
for testing a wide variety of functionality as is possible using your
class.
--------------------------------------------------------------------------------
- Next message: Ioannis Vranos: "Re: Summary of C++ (ANSI/ISO) standards"
- Previous message: sudeep: "one more"
- Next in thread: Rolf Magnus: "Re: the last one"
- Reply: Rolf Magnus: "Re: the last one"
- Reply: JKop: "Re: the last one"
- Reply: Michael Kurz: "Re: the last one"
- Reply: Chris Theis: "Re: the last one"
- Reply: Siemel Naran: "Re: the last one"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|