Question
*******************Answer in c++********************** Goals: Learn how to parse a string. Learn how to design a class. (This is not required. If you properly use a
*******************Answer in c++**********************
Goals:
Learn how to parse a string.
Learn how to design a class. (This is not required. If you properly use a manager class to manage ship records, you get 10 extra points. The array of size 10 should be private attribute of the class. In the constructor of the class the input file is processed and the data structure is populated. In the destructor the memory is released.)
Learn a little bit about Hash Table/Function methods by applying Chaining method (the other one is called Linear Probing) to implement the system.
Requirements:
Input file - Read data from the input file named txt. The five columns in the input file are:
Column | Name | Comment |
1 | Serial number | 4-digit seral number |
2 | Ship type | 1 Cruise ship 2 Cargo ship |
3 | Ship name enclosed by double quotes | There might be blanks in the name. |
4 | Year built |
|
5 | A number which indicates either the capacity for passengers or cargo | 1 - Amount of passengers 2 Cargo capacity |
Since the ship names may have blanks, we need to use getline() to read the whole line and then parse the tokens one after the other.
For each input line, a Ship record is constructed by using new
A Ship pointer array of the size 10 is used to hold the records.
Hash function The serial number is used to determine where the record is located. The size of the array is 10 and the serial number can be used as the key for calculating bucket #. The Hash function is
Bucket# = key % 10
For example, if the serial number is 1009, the bucket for the record is #9.
Each bucket can actually hold a list of records. If collision occurs, the new record is chained at the end of the list.
DisplayOne() With a given serial number, the information of the ship is displayed.
The memory must be freed at the end of the main().
Input File:
File name: ShipRecord.txt
1009 1 "Royal Queen" 2015 160 1010 2 "Carnival" 2016 1600 1019 1 "Ocean King" 2013 110 1029 2 "Royal Prince" 2012 2000 1039 2 "Royal Princess" 2010 2100 1014 2 "Royal Caribbean" 2016 1600
4 1010 1014 1009 CP 1029 1039 4 1010 1014 1009 CP 1029 1039
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started