Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PART1: Objectives: After finishing the lab4 part 1, you can: -handle the stack structure when applying push and pop operations to add or fetch and

PART1: Objectives: After finishing the lab4 part 1, you can: -handle the stack structure when applying push and pop operations to add or fetch and delete the nodes -handle the queue structure when applying enque and deque operations to add or fetch and delete the nodes. Requirement Statement: Write the application to allow the librarians to use Stack or Queue structure to work with books. Suppose the library only keep 2 categories of books: some books are only read at the library (Book) and some books can be checked out to bring home (BorrowedBook) Each information of book (Book) has the following information: bookID (string), ISBN (string), title (string), writer (string), publisher (string) For books that can be checked out (BorrowedBook) should have more information: Checkout date (string) and due date (string) For each structure, the librarians can 1. Add a book 2. Remove a book 3. Display the book at top (or at front of Queue) 4. Show all books in the structure After finishing a task, the application should all librarians to continue to do other task until they want to exit TASK ADD A BOOK -Allow users to type in the information of the Book or BorrowedBook -add to the stack/queue -print the the information of inserted book in the following format For Book Book ID: 495.1 YIP Book ISBN: 0-415-13535 Book title: Chinese An Essential Grammar Writer: Don Rimmington Publisher: Routledge OR for BorrowedBook Book ID: 495.1 YIP Book ISBN: 0-415-13535 Book title: Chinese An Essential Grammar Writer: Don Rimmington Publisher: Routledge Date Check out: 09/22/2017 Due date 10/06/2017 TASK REMOVE A BOOK -remove a book then print out the removed book or display message box: The Stack is empty or The queue is empty TASK DISPLAY THE BOOK AT TOP (or AT FRONT FOR THE QUEUE) -display the book at top (or front) or display the message box: The Stack is empty or The queue is empty COSC2436 Lab4 2 TASK SHOW ALL BOOKS -display all the books or borrowed book on the stack (or queue) INSTRUCTION HOW TO DO THE LAB PART1 ANALYZE: -You should read the requirement again to see what the requirement gives you and what it asks you to do then write them on the paper. -The Book and BorrowedBook should have Inheritance relationship -Also, you need to apply polymorphism in the main to deal with Book object and BorrowedBook PSEUDO-CODD AND UML -Provide UML of data type classes: class Book_yourLastName, class BorrowedBook_yourLastName -provide pseudo-code of main(): Psuedo-code is written in English that lists what you have to do step by step in the main such that your program is qualified to the requirement. Write the pseudo-code in notepad and save with the file name as PART2_Pseudocode_yourLastName -Based on what should be done in the Analyze, you should list step by step how you will do on the paper, organize these steps in good order such that if you follow these steps to write the code, your program can have the result as requested Spend time to analyze and create the pseudo-code before writing the code is the best way to improve yourself in programming. If you do not know how to write the pseudo-code, contact me to get help. WRITE THE CODE 1. Create the project name FA2017LAB4_PART1 2. Add Five classes: two data type classes, two data structure classes for Stack and Queue and one driver class FA2017LAB4_BookSystem_yourLastName Based on the UML, write the code for data type classes Based on the pseudo-code write the code for main() COMPILE THE PROJECT - RUN THE PROJECT -ensure you have the comments -ensure you have all tasks the requirements asking for PART 2: Evaluate the expression OBJECTIVES After finish this lab you can: -Apply the Stack to evaluate the infixed notation expression REQUIREMENTS: Create an application that can evaluate an infixed expression by using the Stack structure then print out the result in the following format: For example Read an infixed expression, (1 + 2) * 4 3 The output should be: (1 + 2) * 4 3 = 9 The application should allow users to choose where to read the expression: from the keyboard or from a file (file stores one expression on one line) After finishing one expression, the application should loop back to allow users to select the source to read the expression from then continue to do until the users want to exit COSC2436 Lab4 3 INSTRUCTION HOW TO DO THE LAB ANALYZE: -You should read the instruction to understand the logic to evaluate an expression PSEUDO-CODD AND UML -You do not need UML for this lab because our data types are Wrapper classes (Character and Integer) -Based on the required logic, write the pseudo-code for what you suppose to do in main() WRITE THE CODE 1. Create the project FA2017LAB4_PART2_yourLastName 2. Add a class GenericStack that can apply for any data type. You can use the code of GenericStack in the book page 167 for your reference (You do not need GenericNode and deepCopy for this lab) 3. Add the driver class named FA2017LAB4_evaluateExperession_yourLastName that has at least two user defined functions, the method processOneOperation and the method procesOneExpression User Defined function processOneOperation This method accepts two paramenters, Integer Stack and Character Stack In the body of the method 0neoperatorProcess -pop the top operator in the stack of operators -pop the two operands on the top of stack of operands -Depend on the operator, calculate the result and push the result back to the stack of operand. The result is calculated with operand1, operand2 and operator that are popped from stack of operands and from stack of operators User Defined function procesOneExpression that hold all the code to evaluate one expression -After reading one expression as a string -Using StringTokenizer or split of String to split input expression into the tokens (operands and operators) and store them to stack of operands and stact of operators by applying the following rules: phase1: Scanning expression (read expression) the program will scan the expression from left to right to extract operands, operators and the parenthesis if the extracted item is a number, push it to the stackForOperands if the extracted item is a + or operator: - check if the stackForOperators is empty, push it into the stack - if the stackForOperators is not empty, process all the operators (+, -, *, / ) in the stackForOperators from top one by one until there is no operator (+, -, * or /) at top then push the extracted operator to stackForOperators if the extracted item is a * or / operator: - check if the stackForOperators is empty, push it into the stack - if the stackForOperators is not empty, process all the operators (*, / ) in the stackForOperators from top one by one until there is no operator (* or /) at top then push the extracted operator to stackForOperators if the extracted item is an open parenthesis (, push it to stackForOperators if the extracted item is an close parenthesis ), process all operators in the stackForOperators from the top until top is an open parenthesis (; then pop the open parenthesis ( off from the stackForOperators phase2: Clearing stack Process all the operators left in the stackForOperators from top until stackForOperators is empty Display the result as the required format: The final result will be the last number in the stackForOpereands

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions