CSCI 3110 Lab 3: Inheritance and STL - Implementing SortedList and Derived Product Classes, Lab Reports of Data Structures and Algorithms

A lab assignment for a csci 3110 course focused on inheritance, abstract base classes, and the standard template library (stl). Students are required to modify their seller and product classes, implement a sortedlist class, and read data from a file to create a vector of sellers. The document also includes instructions for creating derived classes of product, such as movie and book, and details on how to read and print data from the file.

Typology: Lab Reports

Pre 2010

Uploaded on 08/19/2009

koofers-user-ur5
koofers-user-ur5 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSCI 3110
Lab3: Inheritance
Due: 11:59 p.m.
Objective: To become familiar with the STL list and vector, inheritance and abstract base
classes.
Description: This assignment is a revision of the previous program assignment. The
revisions include:
Your client will create a vector containing sellers. Modify your seller class to contain
all required methods when using a class with the Standard Template Library.
Implement a SortedList that inherits from the STL list class. In the client, you will
maintain a sorted list of pointers to products for each seller. The list will be sorted by
product name. This class should provide an insertInOrder method that inserts an
item into a list in order. This method should use methods from the STL class to insert
the item. It should also contain any other items needed (that are not provided by
STL) to allow the client to do its job.
The product class is revised as follows:
oIt is now an abstract base class.
oInstead of bidding information, it should contain a field called price.
oIt should contain a virtual method print() that prints the data members in
product. The friend << is no longer needed.
oIt should also contain a virtual method read() that allows the product’s data
members to be read from a data file. The friend >> is no longer needed.
oIt should contain a pure virtual function cost() that determines the cost of the
product.
oAdd to the product class any methods necessary to use it with STL.
Your revised program will contain the following derived classes of Product:
oadd a new class called Movie that contains additional members:
upc – a string containing the universal product code (bar code) for the
movie
movie rating – an integer value used to rate a movie from 1 to 5 (5
being the highest).
The cost() of the movie is proportionally to the movie rating. It is the
price plus the rating.
oAdd a new class called Book that contains additional members:
Isbn – a string containing the ISBN number of the book
Author – a string containing the author’s name in the form
lastname, firstname
Whether the book is new or used (bool)
An enumerated type indicating the condition of the book (EXCELLENT,
GOOD, FAIR, POOR)
The cost of the book is just the price if it is new. However, if it is used,
the price is discounted as follows: if the book’s condition is
EXCELLENT, discount by 20%; if condition is GOOD, discount by 40%; if
condition is FAIR, discount by 50%; and if condition is POOR, discount
by 70%.
Your client will read data from “sellers.txt” as in the previous programs. However, now after
the information for a seller is entered, the list of products will appear as follows:
1. The first item is a number that indicates how many products are to follow.
2. If the item is a movie, the string “Movie” appears as the first data item for the movie.
Next follows the product data (here the product name is treated as the movie’s
pf2

Partial preview of the text

Download CSCI 3110 Lab 3: Inheritance and STL - Implementing SortedList and Derived Product Classes and more Lab Reports Data Structures and Algorithms in PDF only on Docsity!

CSCI 3110

Lab3: Inheritance

Due: 11:59 p.m.

Objective : To become familiar with the STL list and vector, inheritance and abstract base classes. Description : This assignment is a revision of the previous program assignment. The revisions include:  Your client will create a vector containing sellers. Modify your seller class to contain all required methods when using a class with the Standard Template Library.  Implement a SortedList that inherits from the STL list class. In the client, you will maintain a sorted list of pointers to products for each seller. The list will be sorted by product name. This class should provide an insertInOrder method that inserts an item into a list in order. This method should use methods from the STL class to insert the item. It should also contain any other items needed (that are not provided by STL) to allow the client to do its job.  The product class is revised as follows: o It is now an abstract base class. o Instead of bidding information, it should contain a field called price. o It should contain a virtual method print() that prints the data members in product. The friend << is no longer needed. o It should also contain a virtual method read() that allows the product’s data members to be read from a data file. The friend >> is no longer needed. o It should contain a pure virtual function cost() that determines the cost of the product. o Add to the product class any methods necessary to use it with STL.  Your revised program will contain the following derived classes of Product: o add a new class called Movie that contains additional members:  upc – a string containing the universal product code (bar code) for the movie  movie rating – an integer value used to rate a movie from 1 to 5 ( being the highest).  The cost() of the movie is proportionally to the movie rating. It is the price plus the rating. o Add a new class called Book that contains additional members:  Isbn – a string containing the ISBN number of the book  Author – a string containing the author’s name in the form lastname, firstname  Whether the book is new or used (bool)  An enumerated type indicating the condition of the book (EXCELLENT, GOOD, FAIR, POOR)  The cost of the book is just the price if it is new. However, if it is used, the price is discounted as follows: if the book’s condition is EXCELLENT, discount by 20%; if condition is GOOD, discount by 40%; if condition is FAIR, discount by 50%; and if condition is POOR, discount by 70%. Your client will read data from “sellers.txt” as in the previous programs. However, now after the information for a seller is entered, the list of products will appear as follows:

  1. The first item is a number that indicates how many products are to follow.
  2. If the item is a movie, the string “Movie” appears as the first data item for the movie. Next follows the product data (here the product name is treated as the movie’s

name). The name is followed by the price. Next will be a string for the movie’s UPC, then an integer for the movie’s rating.

  1. If the item is a book, the string “Book” appears as the first data item for the book. Next follows the product data (here the product name is treated as the book’s title). The name is followed by the price. Next will be a string for the ISBN number, then the author, then a string “New” or a string “Used”, then an integer 1 (meaning POOR) or 2 (meaning FAIR) and so on. While the client is reading all of the data from the data file into a vector of sellers, dynamic binding should be used to determine the correct read() method to be used. After all sellers have been read, sort the vector of sellers by name using the vector’s sort method. Next the client should respond to a menu as follows: do { Print a menu "1. Print all sellers;
  2. Find a seller
  3. Print a seller’s books
  4. Print a seller’s movies
  5. Print all products sold by a particular seller
  6. Find a product sold by a seller
  7. Quit"; Input choice; Branch on choice:
  8. call printSellers;
  9. call findSeller;
  10. call printBooks;
  11. call printMovies;
  12. call printProducts;
  13. call findProduct;
  14. done = true; Otherwise: print "Invalid command"; End branch; }while (not done) Write list of sellers to a new file newSellers.txt (use exactly the same form as in “sellers.txt” The functions printSellers and findSeller should have the same functionality as previous labs. The function printProducts should print the products of a particular seller. It should ask for the seller and after finding the seller, it should print all of the products sold by this seller. All data for a given product (including the cost) should be displayed with appropriate labels. This function should make use of dynamic binding to determine the correct print() method to use and to determine the correct cost() function. The functions printBooks and printMovies should print all information (including the cost) about books/movies from all sellers. You will need some method to determine whether a book is pointed to or a movie. The findProduct method should find a product sold by a particular seller. It should ask for the seller. Next, it should find a product by entering a portion of the title. It should print all “products” that contain that substring in the title (name). Dynamic binding should be used to correctly print each product. Use the string class’s substring method to determine whether the portion of the title is contained in the title.