1 / 8

Lab1 C++ Warmup with Grocery Shopping

Lab1 C++ Warmup with Grocery Shopping Cop 4331 and EEL4884 © Dr. David A. Workman School of EE and Computer Science University of Central Florida 20 January 2009 Problem Statement

Mercy
Download Presentation

Lab1 C++ Warmup with Grocery Shopping

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lab1C++ Warmup withGrocery Shopping Cop 4331 and EEL4884 © Dr. David A. Workman School of EE and Computer Science University of Central Florida 20 January 2009

  2. Problem Statement You have just been introduced to the OO Data Input/Output format and design protocol. We have studied the design of the Grocery and Produce classes as examples of how to implement these input and output formats for instances of class types. The purpose of this lab assignment is deepen your understanding of these design and implementation principles as well as to give you some practice using the features of C++ needed by this assignment. You will be given the following program units to reuse, IOMgmt shall be used without change: IOMgmt, Grocery and Produce. You will be asked to write missing methods of classes Grocery and Produce, and to write the application main() that satisfies the requirements of this assignment.. (c) Dr. David A. Workman

  3. Requirements • The application shall read all input data from an external ASCII file stream. The application shall write all output data to an external ASCII file stream. • The capabilities of IOMgmt::InMgr and IOMgmt::OutMgr shall be used by the application to define and open the input and output streams. • The application shall read the following information from the input stream:(1) The number of Grocery instances to accept (nGrocery) and the number of Produce instances to accept (nProduce). These values may be specified in any order on one or two lines with the following format:nGrocery: <value>nProduce: <value>Any valid integer literal can be specified by <value>. The identifying label and corresponding value shall be delimited by white space.(2) A sequence of zero or more instances of classes Grocery and Produce, specified in the OO Data format for these classes, in any order. (c) Dr. David A. Workman

  4. Requirements • The application shall process the input file by:(1) reading the values of (nGrocery) and (nProduce) and dynamically allocating an array of Grocery instances (if nGrocery is positive), and dynamically allocating an array of Produce instances (if nProduce is positive). The values of these parameters shall be written to the output stream in the same format used for input.(2) Sequentially reading instances of Grocery and Produce as they appear in the input stream. Instances of class Grocery will be saved in the storage array, in the order encountered in the input stream, provided, of course, capacity is available to do so. Any Grocery instances for which space in the dynamic array is not available, shall be "rejected"; that is, written immediately to the output stream with a GROCERY OVERFLOW message. An analogous requirement applies to instances of class Produce.(3) Images of Grocery and Produce shall be extracted from the input stream using the extraction operator defined in class Grocery. (4) The application shall be designed to detect errors in the input specification format. If either (nGrocery) or (nProduce) are not specified, the program shall write an appropriate error message to the output stream and terminate. If a TokenError exception is thrown during the extraction of a Grocery or Produce instance, then the application shall terminate after outputting the following information: (a) the exception message and origin, (b) the accepted instances of Grocery to that point, (c) the accepted instances of Produce to that point.(5) After the input stream has been completely processed, the application shall output (a) the accepted instances of Grocery and their count; (b) the accepted instances of Produce and their count; (c) Dr. David A. Workman

  5. Sample Input & Output Grocery.input nGrocery: 5 nProduce: 2 Produce{ name: P3 markup: 2.0 cost: 350 weight: 3.5 }Produce Grocery{ name: G2 markup: 2.25 cost: 400 }Grocery Grocery{ name: G1 markup: 3.25 cost: 500 }Grocery Produce{ name: P1 markup: 2.50 cost: 300 weight: 1.75 }Produce Produce{ name: P2 markup: 1.50 cost: 200 weight: 6.0 }Produce Grocery{ name: G4 markup: 3.2 cost: 600 }Grocery Grocery{ name: G3 markup: 3.0 cost: 550 }Grocery Grocery.output nGrocery: 5 nProduce: 2 =============================== START INPUT ================== Produce item OVERFLOW. The following item is rejected: Produce{ name: P2 markup: 1.5 cost: 200 weight: 6 }Produce =============================== END INPUT ==================== Grocery{ name: G2 markup: 2.25 cost: 400 }Grocery Grocery{ name: G1 markup: 3.25 cost: 500 }Grocery Grocery{ name: G4 markup: 3.2 cost: 600 }Grocery Grocery{ name: G3 markup: 3 cost: 550 }Grocery 4 Grocery Items Accepted. Produce{ name: P3 markup: 2 cost: 350 weight: 3.5 }Produce Produce{ name: P1 markup: 2.5 cost: 300 weight: 1.75 }Produce 2 Produce Items Accepted. (c) Dr. David A. Workman

  6. Requirements • The developer shall write the following units in C++:(a) GroceryApp (main())(b) Grocery::Get() in accordance with the OO data design protocol; violations to format specification for Grocery instances shall result in throwing a TokenError exception.(c) Produce::Get() in accordance with the OO data design protocol; violations to format specification for Grocery instances shall result in throwing a TokenError exception. • No IO features of the C language are permitted. • The C++ extraction and insertion operators shall be used exclusively for reading or writing from the input and output file streams, respectively. • InMgr::setFilePos() and InMgr::resetFilePos() shall be used exclusively to manage the input stream for identifying OO instances and then reading them. • The dynamic arrays shall be deallocated by the application at the end of processing. • InMgr and OutMgr instances shall be properly closed by the application at the end of processing. (c) Dr. David A. Workman

  7. IOMgmt Architectural Design Gen/Spec AppError Composition Aggregation (container) dependency IOError TokenError association (main) OutMgr InMgr GroceryApp Writes to Grocery Produce nGrocery nProduce 1 fout: ofstream 1 fin: ifstream (c) Dr. David A. Workman

  8. Lab1 Deliverables • All and only the source files used by the developer in completing this assignment. • A UNIX makefile for this application. This makefile shall run without change on olympus.eecs.ucf.edu to compile, link and produce an executable named: GroceryApp. • All deliverables shall be submitted via Webcourses as a single (.zip) file followingthe naming convention: Lab1-Lastname-MmmDD.zip (where MmmDD is the month and day of submission.) (c) Dr. David A. Workman

More Related