Define a class StatePair with two template types (T1 and T2), constructors, mutators, accessors, and a PrintInfo() method. Three vectors have been pre-filled with StatePair data in main(): vector> zipCodeState: ZIP code - state abbreviation pairs vector> abbrevState: state abbreviation - state name pairs vector> statePopulation: state name - population pairs Complete main() to use an input ZIP code to retrieve the correct state abbreviation from the vector zipCodeState. Then use the state abbreviation to retrieve the state name from the vector abbrevState. Lastly, use the state name to retrieve the correct state name/population pair from the vector statePopulation and output the pair.
Define a class StatePair with two template types (T1 and T2), constructors, mutators, accessors, and a PrintInfo() method. Three vectors have been pre-filled with StatePair data in main(): vector> zipCodeState: ZIP code - state abbreviation pairs vector> abbrevState: state abbreviation - state name pairs vector> statePopulation: state name - population pairs Complete main() to use an input ZIP code to retrieve the correct state abbreviation from the vector zipCodeState. Then use the state abbreviation to retrieve the state name from the vector abbrevState. Lastly, use the state name to retrieve the correct state name/population pair from the vector statePopulation and output the pair.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
100%
Define a class StatePair with two template types (T1 and T2), constructors, mutators, accessors, and a PrintInfo() method. Three vectors have been pre-filled with StatePair data in main():
- vector<StatePair <int, string>> zipCodeState: ZIP code - state abbreviation pairs
- vector<StatePair<string, string>> abbrevState: state abbreviation - state name pairs
- vector<StatePair<string, int>> statePopulation: state name - population pairs
Complete main() to use an input ZIP code to retrieve the correct state abbreviation from the vector zipCodeState. Then use the state abbreviation to retrieve the state name from the vector abbrevState. Lastly, use the state name to retrieve the correct state name/population pair from the vector statePopulation and output the pair.
Ex: If the input is:
21044
the output is:
Maryland: 6079602
-main.cpp:
#include<iostream>
#include <fstream>
#include <vector>
#include <string>
#include "StatePair.h"
using namespace std;
int main() {
ifstream inFS; // File input stream
int zip;
int population;
string abbrev;
string state;
unsigned int i;
// ZIP code - state abbrev. pairs
vector<StatePair <int, string>> zipCodeState;
// state abbrev. - state name pairs
vector<StatePair<string, string>> abbrevState;
// state name - population pairs
vector<StatePair<string, int>> statePopulation;
// Fill the three ArrayLists
// Try to open zip_code_state.txt file
inFS.open("zip_code_state.txt");
if (!inFS.is_open()) {
cout << "Could not open file zip_code_state.txt." << endl;
return 1; // 1 indicates error
}
while (!inFS.eof()) {
StatePair <int, string> temp;
inFS >> zip;
if (!inFS.fail()) {
temp.SetKey(zip);
}
inFS >> abbrev;
if (!inFS.fail()) {
temp.SetValue(abbrev);
}
zipCodeState.push_back(temp);
}
inFS.close();
// Try to open abbreviation_state.txt file
inFS.open("abbreviation_state.txt");
if (!inFS.is_open()) {
cout << "Could not open file abbreviation_state.txt." << endl;
return 1; // 1 indicates error
}
while (!inFS.eof()) {
StatePair <string, string> temp;
inFS >> abbrev;
if (!inFS.fail()) {
temp.SetKey(abbrev);
}
getline(inFS, state); //flushes endline
getline(inFS, state);
state = state.substr(0, state.size()-1);
if (!inFS.fail()) {
temp.SetValue(state);
}
abbrevState.push_back(temp);
}
inFS.close();
// Try to open state_population.txt file
inFS.open("state_population.txt");
if (!inFS.is_open()) {
cout << "Could not open file state_population.txt." << endl;
return 1; // 1 indicates error
}
while (!inFS.eof()) {
StatePair <string, int> temp;
getline(inFS, state);
state = state.substr(0, state.size()-1);
if (!inFS.fail()) {
temp.SetKey(state);
}
inFS >> population;
if (!inFS.fail()) {
temp.SetValue(population);
}
getline(inFS, state); //flushes endline
statePopulation.push_back(temp);
}
inFS.close();
cin >> zip;
for (i = 0; i < zipCodeState.size(); ++i) {
// TODO: Using ZIP code, find state abbreviation
}
for (i = 0; i < abbrevState.size(); ++i) {
// TODO: Using state abbreviation, find state name
}
for (i = 0; i < statePopulation.size(); ++i) {
// TODO: Using state name, find population. Print pair info.
}
}
-StatePair.h:
#ifndef STATEPAIR
#define STATEPAIR
template<typename T1, typename T2>
class StatePair {
// TODO: Define constructors
StatePair();
StatePair(T1 userKey, T2 userValue);
// TODO: Define mutators, and accessors for StatePair
// TODO: Define PrintInfo() method
};
#endif
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 5 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education