Question: In this question, you will create a database with information about US states. You are given usstates.txt which is a file that contains some data
In this question, you will create a database with information about US states.
You are given
usstates.txt
which is a file that contains some data about all 50
states. Its columns are, respectively: state abbreviation, state name, capital,
population, year it became a state, and number of representatives in congress.
Your job is to design and write a class, to be named
State
. The class's private
attributes should be the above mentioned six data items (use stateAbrv,
stateName, capital, population, year, numCongress); the first three should
be
string
, the last three should be
int
.
In addition to the above six attributes, which should be private, the class should
also contain the usual public methods, access methods (set/get), and utility
methods of your choice. An example of utility method (but feel free to
implement any other one) is a method that returns the number of state residents
per representative.
You will then write an implementation for the class (
state.cpp
) that is
compatible with the interface, and that contains the code for its methods.
You will have a total of three files: state.h, state.cpp, and main.cpp.
You program should first call a function that reads the data from the file and
stores it into a vector or array (your choice) of object of type
State
.
Your main program will then present a menu to the user. The menu will consist
of the following three options to allow a user to search for information about a
given state using your State class:
1. Search by state abbreviation (e.g. MI).
2. Search by year of statehood (e.g. 1837).
3. Exit program.
Please enter your choice (1-3):
Each option in the menu should be executed by a calling function.
You program, will then output the information in tabulated form:
State Abrv. Name Capital Population Year #Congress
MI Michigan Lansing 9923000 1837 14
CIS 150 Lab 12
3
The output should also display the result returned by the utility method you
implemented in the class.
In the case of option 2, if there are multiple states that have the same year of
statehood, then you program must list all of them (one state per row) as shown
below:
State Abr. Name Capital Population Year #Congress
CT Connecticut Hartford 3591000 1788 5
GA Georgia Atlanta 3591000 1788 14
...
If a corresponding state is not found in the search, then the following message
should be displayed to the user:
No state exists with this information.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
