LIST OF PROGRAMMING ASSIGNMENTS/ HW FOR CS 302 _____________________________________________ HOMEWORK 1 --- DUE Wednesday, FEB. 11 From your book, page 71, EXERCISES 2.10: #2 a,c,d #3 a,e #8 #9 #10 ______________________________________________ HOMEWORK 2 --- DUE Friday, FEB. 20 (submit code by email to chris@cs1.bradley.edu, and puneet@cs1.bradley.edu. Also hand in hard copy of code, plus sample run printouts of all 5 test cases) From the notes given as a handout, consider the third data structure given for implementing the class polynomial (array of records). In addition to the methods given in class, implement the remaining member methods (add, multiply,evaluate, not zero (!) operator, Coef, LeadExp, overload of <<). The input should be interactive from screen and menu driven: Your program should first ask the user : What do you wish to do: 1. Add two polynomials 2. Multiply two polynomials 3. Evaluate one polynomial at a given value 4. Find coefficient for a given polynomial and given exponent 5. Find the leading exponent for a given polynomial. If user chooses menu options 1 or 2, he should be asked : Please input first polynomial in form of (non-zero coefficient, exponent) pairs. Please input second polynomial in same format Your program should then calculate and print resulting polynomial using the overloaded << operator. If user chooses option 3, he should be asked to input a polynomial in the format as above and to input a value ("Give a value to evaluate the polynomial on"). Your program should then print, "The evaluation of (print poly) for the value (print given value) IS (some float) If user chooses option 4, user should be asked for a polynomial and a coeficent, and in option 5, he should be asked to input a polynomial. In both cases, the input values should be echoed with the corresponding result. ------------------------------------------------------------------ HOMEWORK 3 --- DUE Friday, March 5 (submit code by email to both: chris@cs1.bradley.edu, and puneet@cs1.bradley.edu. Also hand in hard copy of code, plus sample run printouts of all 5 test cases) You are to write a program for the Peoria network of public libraries to keep track of books available at each of the branches. Each branch keeps its books in a linked list in lexicographical order by author's name. Books of the same author are arranged in order by title. There may be many copies of the same book in a library branch. The data structure to be used should be an array of structures, with the structure containing a branch_name field followed by a pointer field. The pointer should point to an ordered linked list of the books in that branch. each node of the linked list corresponds to a book and is a structure with an author_name field, a book_title field, a num_copies field which indicates how many copies of that book are available for checkout, and a pointer field to the next book in the branch. When a book is checked out from a branch, it is deleted from the branch's linked list. When it is returned to a branch, it is inserted in the appropriate place in the ordered list. A book can be returned to a different branch than the one it was checked out from. Customers can ask to find how many books of a specific author and title are available in a given branch. Your program should be menu driven with following options: 1. Create a branch and insert its books 2. Given an author name, a title and a branch name, CHECKOUT that book from the branch. 3. Given an author name, title and a branch name, RETURN that book to the branch. 4. Given an author name, title and branch name, FIND the number of copies of that book are available in that branch. 5. PRINT all books contained in a branch. 6. Exit the program. -------------------------------- When the user chooses menu choice 1, the following dialogue for input of data should ensue: What is your menu choice? 1 What is the name of the branch? ALPHA What is author and title of book? SMITH FREEDOM What is author and title of book? JONES LIFE What is author and title of book? NONE NONE Thank you, I created branch ALPHA ...menu is displayed again... What is your menu choice? 1 What is the name of the branch? BETA What is author and title of book? GUPTA ALGORITHMS What is author and title of book? GUPTA ALGORITHMS What is author and title of book? LAGOS GENIUS What is author and title of book? NONE NONE Thank you, I created branch BETA ...menu is displayed again... What is your menu choice? 2 Give author, title and branch from which to checkout the book: GUPTA ALGORITHMS BETA Thank you! The book ALGORITHMS by GUPTA has been checked out from BETA ...menu is displayed again... What is your menu choice? 2 Give author, title and branch from which to checkout the book: JONES LIFE ALPHA Thank you! The book LIFE by JONES has been checked out from ALPHA ...menu is displayed again... What is your menu choice? 3 Give author, title and branch to which book is to be returned: GUPTA ALGORITHMS BETA Thank you! The book ALGORITHMS by GUPTA has been returned to branch BETA ...menu is displayed again... What is your menu choice? 2 Give author, title and branch from which to checkout the book: JONES LIFE ALPHA Sorry! This book is not available at branch ALPHA ...menu is displayed again.. What is your menu choice? 4 Give author, title and branch for which you want to check availability: GUPTA ALGORITHMS BETA There are 2 copies of ALGORITHMS by GUPTA in branch BETA ...menu choice is displayed again... what is your menu choice? 5 Give name of branch whose books you want to see: BETA The books in BETA are: ALGORITHMS by GUPTA number of copies 2 GENIUS by LAGOS number of copies 1 ...menu is displayed again... What is your menu choice? 6 Thank you and goodbye. =========================================================== HOMEWORK 4 --- DUE Friday, April 2 (EXTENDED) email your programs to puneet@cs1.bradley.edu and chris@cs1.bradley.edu You are to write methods to build and maintain a binary sort/search tree without balancing operations. Your main program should be menu driven and should input and execute any sequence of the four commands given below. The commands add data into a binary search tree, delete data from a tree, find a given record in the tree, or list the entire tree contents. Commands in menu: INSERT inserts a given record in the tree DELETE deletes record with the given key (id) FIND search for record with given key and if found print the name, age, grade. REPORT gives a listing of all records in the tree in ascending order of ID numbers, along with the level where each node is stored on the tree. Notes: 1. You must implement the inorder method without recursion. Instead use stacks. 2. Example of runs: What would you like to do? 1. Add a node to the tree 2. Delete a node from the tree 3. Find a node in the tree 4. Report the contents of the tree 5. Exit program Choose: 1 Please enter the ID number, age and name: 700 52 RAO What would you like to do? 1. Add a node to the tree 2. Delete a node from the tree 3. Find a node in the tree 4. Report the contents of the tree 5. Exit program Choose:1 Please enter the ID number, age and name: 984 22 JONES What would you like to do? 1. Add a node to the tree 2. Delete a node from the tree 3. Find a node in the tree 4. Report the contents of the tree 5. Exit program Choose:1 Please enter the ID number, age and name: 400 36 SMITH What would you like to do? 1. Add a node to the tree 2. Delete a node from the tree 3. Find a node in the tree 4. Report the contents of the tree 5. Exit program Choose:4 Contents of tree are: 400 36 SMITH level 1 700 52 RAO level 0 984 22 JONES level 1 What would you like to do? 1. Add a node to the tree 2. Delete a node from the tree 3. Find a node in the tree 4. Report the contents of the tree 5. Exit program Choose:3 What is the id number of person? 700 The name is: RAO The age is: 52 What would you like to do? 1. Add a node to the tree 2. Delete a node from the tree 3. Find a node in the tree 4. Report the contents of the tree 5. Exit program Choose:2 What is the id of person to be deleted? 984 What would you like to do? 1. Add a node to the tree 2. Delete a node from the tree 3. Find a node in the tree 4. Report the contents of the tree 5. Exit program Choose:4 Contents of tree are: 400 36 SMITH level 1 700 52 RAO level 0 What would you like to do? 1. Add a node to the tree 2. Delete a node from the tree 3. Find a node in the tree 4. Report the contents of the tree 5. Exit program Choose:5 Thank you and goodbye ======================================================== HOMEWORK 5 --- DUE Friday, April 16 email your programs to puneet@cs1.bradley.edu and chris@cs1.bradley.edu Modify programming assignment number 4, but this time keep the tree balanced as in AVL trees. The look and feel of your program will be the same, but the trees will be balanced, as can be checked by the printed out balance value of each node. ========================================================= HOMEWORK 6 --- DUE Friday, April 30 email your programs to puneet@cs1.bradley.edu and chris@cs1.bradley.edu Write a program to maintain the representation of a simple network and compute the best path between two given nodes upon request. PROGRAMMING COMMANDS: Your program should be menu driven, with menu choices corresponding to following commands: LINK I J D sets directed link from node I to node J of distance D. DOWN I J removes any link from I to J if it exists DUMP produces a listing of all the edges in the current network, as a list of triples I,J,D PATH S G produces the shortest path from start node S to goal node G, or states that no path exists. DEND gives a listing of all the "dead end" nodes in the network. A node is dead end if its outdegree is zero. INACCESS gives a listing of all the "inaccessible" nodes in the network. A node is inaccessible if its indegree is zero. NAME I String this command supplies the name "String" for node I. For example, NAME 1 CHICAGO, NAME 2 NY, etc. You may assume that there will never be more than 30 nodes in the network. =========================================================================