I am having some difficulty hear with my project for a data structure class. We have this project due for Monday. I have been looking at code to develop the project and am having difficulty starting. This is the question.
The District Education Office maintains a database of substitute teachers in the area. If a temporary replacement is necessary for a certain subject, an available teacher is sent to the school that requests him or her. Write a menu driven program maintaining this database. The menu options should be:
1. View All Teachers Grouped per Subject Area ( do search by subject)
2. View All Available Teachers Per Subject Area ( do search by teacher)
3. Reserve Teacher for Subject ( add teacher to subject)
4. Add New Substitute Teacher ( add function)
5. Change Availability Status ( update function)
6. Delete Substitute Teacher ( delete function)
7. Save and Exit Program ( save and exit function)
Note: A switch which calls each menu option- each option is a function call.
Program Data Structures and Sources
The file substitute lists the last and first names of the substitute teachers, an indication of whether or not they are currently available (Y(es) or N(o)), and a list of numbers that represents the subjects they can teach. An example of substitutes is:
Hillard Roy Y 0 4 5
Ennis John N 2 3
Nelson William Y 1 2 4 5
Baird Lyle Y 1 3 4 5
Geiger Melissa N 3 5
Kessel Warren Y 3 4 5
Scherer Vincent Y 4 5
Hester Gary N 0 1 2 4
Linke Jerome Y 0 1
Thornton Richard N 2 3 5
Note:
0 Mathematics 1 Chemistry 2 History 3 Literature 4 Geography 5 Physics
Create a class teacher with three data members: index, left child and right child. Declare an array subjects with the same number of cells as the number of subjects(7), each cell storing a pointer to class teacher, which is really a pointer to the root of a binary search tree of teachers teaching a given subject. Also, declare an array names with each cell holding one entry from the file.
First prepare the array names to create binary search trees. To do that, load all entries from substitutes to names and sort names on the last name field using any of the sorting algorithms. Afterward create a binary tree using the function balance() given below. Go through the array names and for each subject associated with each name, create a node in the tree corresponding to this subject. The index field of such a node indicates a location in names of a teacher teaching this subject. Figure 1 shows the ordered array names and trees accessible from subjects as created by balance() for our sample file.
If the user is finished and chooses the “save and exit option” load all entires from names back to substitutes, this time with updated information.
1. I understand how to create the program menu, the file name substitues, I have an idea as to how to create the sorts, but I do not know how to follow threw with it. I have broken it down into function parts based on the menu. Would someone look at the question and give me some guidance. Thank you muchCode:void BST<T> :: balance(T data[ ], int first, int last) { if (first <= last) { int middle = (first + last) /2; insert(middle); balance(data, first, middle -1); balance(data, middle +1, last); } //end if }
Last edited by WingedPanther; 12-07-2008 at 04:29 AM. Reason: add code tags (the # button)
I guess I'm not clear on where your issue is: It appears clear that you will be adding a teacher to EACH list that teacher can teach (6, not 7 of them). Once you have a comparison function created (last, then first name), sorting should be easy.
Saving will require you to step through all lists in the array simultaneously so you can add each person only once (or use the 7th item in the array for the complete list?)
That part is straight forward to me - my difficulty has been understanding what to code will do before I type it.
The other thing is : how do I make a sort functional. Like this bubblesort for example.
Code:void bubblesort(int *data,int length) { int swapcount = 1; while(swapcount > 0) { swapcount = 0; for(int i = 0; i < length - 1; ++i) { if(data[i] > data[i + 1]) { int temp = data[i]; data[i] = data[i + 1]; data[i + 1] = temp; ++swapcount; } } } }
Last edited by WingedPanther; 12-07-2008 at 04:29 PM. Reason: add code tags (the # button)
Oh I am not clear on how to point the array names to the class Teachers.
This is my unfortunate demise ( am learning to program in VC++ at the same time![]()
this is what my code looks like at the moment. I am still working out the missing functions. Any suggestions as to what I need to clear up
Code:#include <cstdio> #include <cstdlib> #include <iostream> #include <string.h> using namespace std; #include "Teacher.h" Teacher::Teacher(void) {class Teacher { int index; int leftchild; int rightchild; char Subject[7]; char names[48]; public: Teacher(void); Teacher* pS = Subject[7]; MAX = 20; }; // Open file Subsitutes for sorting void open( const char Substitutes.txt, ios_base::openmode _Mode = ios_base::out, int _Prot = (int)ios_base::_Openprot ); // use a sorting algorithym void bubblesort(int *data,int length) { int swapcount = 1; while(swapcount > 0) { swapcount = 0; for(int i = 0; i < length - 1; ++i) { if(data[i] > data[i + 1]) { int temp = data[i]; data[i] = data[i + 1]; data[i + 1] = temp; ++swapcount; } } } } } // run the menue program hear int main(int nNumberofArgs, char* pszArgs[]) { int main void ( ); { int choice; cout << “Enter 1, 2,3,4,5,6,or 7:”; cin >> choice; switch(choice) { case 1: do "1 View All Teachers Grouped per Subject Area" //( do search by subject) void searchsub (); break; case 2: do "2 View All Available Teachers Per Subject Area" //( do search by teacher) void searchtch (); break; case 3: do "3 Reserve Teacher for Subject" //( add teacher to subject) void ReserveTeach (); break; case 4: do "4 Add New Substitute Teacher" //( add function) void AddTeach (); break; case 5: do "5 Change Availability Status" //( update function) void SubStatus (); break; case 6: do "6 Delete Substitute Teacher" //( delete function) void Delete (); break; case 7: do "7 Save and Exit Program" //( save and exit function) void Save (); void close(); default: cout << "You didn’t enter any options\n"; } // have the seven call functions on a switch statement } // This is the Balance Function for the teachers class void BST<T> :: balance(T data[ ], int first, int last) { if (first <= last) { int middle = (first + last) /2; insert(middle); balance(data, first, middle -1); balance(data, middle +1, last); } //end if }
Last edited by WingedPanther; 12-07-2008 at 04:31 PM. Reason: add code tags (the # button)
One of the tricks to using a binary tree is that you should generally read data into it so that it is sorted as you add. The sorting is handled as part of adding a node to the tree. You don't need a sort function, just a node comparator.
are d rest of function ok
some of d problems can radiate from d other functiona
I would remove bubblesort (unnecessary). You still have a lot of additional code to write before I can comment on it meaningfully.
ok, Well I am going after it again. Its due 12 tonight. I will let you see my progress even though its for marks. I would rather be able to do this properly - if this kind of programming is to be functional. Have you seen functionality in using these data structures?
There is a LOT of functionality in these types of data structures. However, there is always a learning curve and not all teachers/books are good at presenting the point of the structure before introducing the structure itself.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks