subject

C++ Zip code and population (class templates)
Define a class StatePair with two template types (T1 and T2), a constructor, 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.
Ex: If the input is:
21044
the output is:
Maryland: 6079602
//main. cpp
#include
#include
#include
#include
#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> zipCodeState;
// state abbrev. - state name pairs
vector> abbrevState;
// state name - population pairs
vector> 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 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 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 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
if(zipCodeState. get(i).getValue1() == myZipCode)
{
stateAbbre = zipCodeState. get(i).getValue2();
break;
}
}
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
class StatePair {
// TODO: Define a constructor, mutators, and accessors
// for StatePair
// TODO: Define PrintInfo() method
};
#endif

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 19:00
How is the number 110 written when expanded out to place values in the base 2 (binary) number system? options: 2 x 4 + 3 x 2 + 4 x 1 1 x 2 + 1 x 2 + 0 x 2 1 x 100 + 1 x 10 + 0 x 1 1 x 4 + 1 x 2 + 0 x 1
Answers: 1
question
Computers and Technology, 23.06.2019 13:00
In excel - calculate the actual increase/decrease from first quarter to the second quarter then subtract subtract first quarter value from second quarter total then divide result by first quarter value
Answers: 1
question
Computers and Technology, 24.06.2019 06:00
Hey i really need some solving this problem: 1. encrypt this binary string into cipher text: 110000. include in your answer the formula the decoder would use to decrypt your cipher text in the format (coded answer) x n mod (m) = y & 2. decrypt this cipher text into a binary string: 106 you.
Answers: 2
question
Computers and Technology, 24.06.2019 14:30
Ahousehold consists of a married couple and their twin five-year old daughters. the couples children had no income and lived with their parents all of last year. how many exemptions can the couple claim on last years tax return or they file with the “ married filing jointly “ status? a. 4 b. 5 c. 3 d. 2
Answers: 1
You know the right answer?
C++ Zip code and population (class templates)
Define a class StatePair with two template type...
Questions
question
English, 10.09.2021 21:00
question
Mathematics, 10.09.2021 21:00
question
Mathematics, 10.09.2021 21:00
question
Physics, 10.09.2021 21:00
question
Mathematics, 10.09.2021 21:00
question
Mathematics, 10.09.2021 21:00
Questions on the website: 13722367