The first code: #include #include using namespace std; const int ARRAY_SIZE = 10
ID: 3540801 • Letter: T
Question
The first code:
#include
#include
using namespace std;
const int ARRAY_SIZE = 1000;
string city[ARRAY_SIZE];
double lowTemp[ARRAY_SIZE];
double highTemp[ARRAY_SIZE];
bool search(string,string);
int LoadData();
void ShowAll(int count);
int ShowCities(int count);
int main()
{int count;
char choice;
bool dataloaded=false;
cout<<"welcome to="" my="" library="" database="" n="" span="" br="" for="" cout="" l="" oad="" file="" s="" how="" all="" f="" ind="" city="" q="" uit:="" cin="" choice="" if="" toupper="" count="" while="" 0="" no="" data="" found="" dataloaded="" records="" else="" showall="" you="" must="" load="" the="" first="" showcities="" record="" return="" invalid="" entry="" void="" int="" i="" lowtemp="" hightemp="" loaddata="" char="" filename="" 30="" string="" buffer="" t="" please="" enter="" name="" of="" temperatures="" file:="" ifstream="" input="" open="" fail="" is="" it="" ok="" did="" not="" check="" -1="" getline="" substr="" m="" atoi="" c_str="" 1="" length="" close="" bool="" kount="" city:="" search="" a="" b="" j="" size="" false="" k="" break="" true="" data-mce-style="color: #ff0000;">}
Step (1)
Modify your program to use an array of structs, which will replace the parallel arrays, like this:
// These declarations should be at file scope.
struct HiLoTemp
{
string city;
double low;
double high;
};
const int ARRAY_SIZE = 1000;
HiLoTemp cities [ARRAY_SIZE];
Modify the remainder of the program to work with the new array of structs, but maintaining exactly the same functionality, as well as the added features described below.
Step (2)
Add functionality to sort the array alphabetically by the city name, in ascending or descending order.
Using this new functionality, modify your code so that the output of the Find City menu selection is sorted alphabetically in ascending order by city. Also, remove the Show All menu selection and replace it with the following two menu selections:
(S)how All Ascending, (S)how All Descending
You can use any method of sorting you want. You can use some of the built in sort functions, such as qsort(), or write your own.
Sample Dialog
Note: In the example below, the user
Explanation / Answer
Solution:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int ARRAY_SIZE = 1000;
const int STR_BUFFER_SIZE = 100;
string city[ARRAY_SIZE];
double lowTemp[ARRAY_SIZE];
double highTemp[ARRAY_SIZE];
// Function prototypes
int LoadData();
void ShowAll(int count);
int ShowCities(int count, string name);
int main()
{
int numOfRecords = 0;
char selector = 'q', yesNoAnswer = 'n';
string name = "";
cout<<"Welcome to Abdul
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.