This week, you'll be building off of last week's assignment where you loaded and printed the weather database. Now, you're going to implement a menu that allows the user to do a few different things,...

1 answer below »

This week, you'll be building off of last week's assignment where you loaded and printed the weather database. Now, you're going to implement a menu that allows the user to do a few different things, and extend the user's options for how to manipulate the data. The menu will present four options to the user: load data, print data, search, and sort. Here is an example run that indicates how the interface for the menu should look:  Welcome to Nick's weather analyzer! Would you like to (l)oad data, (p)rint data, (s)earch data, (o)rder the data, or (q)uit? l Please enter the file path: C:/Users/nicholas.insalata/Desktop/weather.txt 331 records loaded. Would you like to (l)oad data, (p)rint data, (s)earch data, (o)rder the data, or (q)uit? p    Would you like to (l)oad data, (p)rint data, (s)earch data, (o)rder the data, or (q)uit? s Would you like to search by (d)ate, temperature (h)igh, (a)vg, (l)ow, (p)recipitation, or (e)vents? d What are the month and day of the record you'd like to see? 1 3 133430270 Would you like to (l)oad data, (p)rint data, (s)earch data, (o)rder the data, or (q)uit? s Would you like to search by (d)ate, temperature (h)igh, (a)vg, (l)ow, (p)recipitation, or (e)vents? e What event would you like to search for? Snow 173027240.02"Rain , Snow" 194136300.28"Rain , Snow" 1103835310.65"Rain , Snow" 1113229260.07Snow 1174434240.38"Rain , Snow" 273936320.08"Fog , Rain , Snow" 2264340370.14"Rain , Snow" 364640340.08"Rain , Snow , Thunderstorm" Would you like to (l)oad data, (p)rint data, (s)earch data, (o)rder the data, or (q)uit? o Would you like to sort by (d)ate, temperature (h)igh, (a)vg, (l)ow, (p)recipitation, or (e)vents? p Would you like to (l)oad data, (p)rint data, (s)earch data, (o)rder the data, or (q)uit? p 2164945411.64Rain 254640341.57Rain 10215953471.34Rain    Would you like to (l)oad data, (p)rint data, (s)earch data, (o)rder the data, or (q)uit? q Thanks for using the weather analyzer!!!   To make this work, you'll need to make use of a few switches in a repeating loop to reiterate the menu choices and write a few more functions. You'll need to make a function that can search in each data category, and one more function that can sort the data in each category. Here are the prototypes of the functions that you'll need:  void search(Weather days[1000], int count); void sort(Weather days[1000], int count);  From these prototypes, you can see that the code that asks the user what they wanted to search/sort for is going to have to be in the search/sort functions rather than in main. Otherwise, how would these functions know what category to use? This will probably take some time, so start early
Answered Same DayAug 12, 2021

Answer To: This week, you'll be building off of last week's assignment where you loaded and printed the weather...

Sayed Shad Ahmad answered on Aug 16 2021
147 Votes
Solution_SSAZ/1.png
Solution_SSAZ/2.png
Solution_SSAZ/weather.cpp
Solution_SSAZ/weather.cpp
//Including standard input output stream class
#include
//Including filestream class
#include
//Including the string class
#include 
//Including the stringstream class
#include
//Using standard namespace
using namespace std;
//Begin of Weather class
class Weather
{
    //Declaring data members of Weather class to store day, high, avg, low, sum, events
    public:
        int day;
        int high;
        int avg;
        int low;
        double sum;
        string events;
};
//End of Weather class
//Function to search info from Weather data
void search(Weather days[1000], int count)
{
    char ch;                                //Variable to store parameter choice
    int i, j;                               //Iterators
    int in, in2;                            //Input variable for day, high, low, avg
    double inp;                             //Input variable for sum of precipitation
    string in
put;                           //Input variable for event
    bool notFound;                          //Flag variable for search item found

    //Asking user to choose by which parameter he/she wants to search
    cout<<"Would you like to search by (d)ate, temperature (h)igh, (a)vg, (l)ow, (p)recipitation, or (e)vents? ";
    cin>>ch;

    //Comparing the parameter value supplied by user
    switch(ch)
    {
        //If user choose d then case d is executed for searching by date
        case 'd':
            notFound = 1;                       //Resetting the flag variable
            j = 0;                              //Initialising the iterator
            //Asking month & day from user for searching data
            cout<<"What are the month and day of the record you'd like to see? ";
            cin>>in>>in2;
 
            //Iterating through the data till count i.e. total available records
            for(i=0; i            {
                //Checking if the ith record day value is 1
                if(days[i].day == 1)
                    ++j;                //Increment value of j by 1 means month is increased
 
                //Checking if j value is equal to the month value supplied by user
                if(j == in)
                {
                    //Checking if day value is equal to the day value supplied by user
                    if(days[i].day == in2)
                    {
                        //Updating the flag variable to 0 i.e. matched data is found
                        notFound = 0;
 
                        //Displaying the fetched record
                        cout< 
                        //Exiting from the loop after matched data has been displayed
                        break;
                    }
                }
            }
 
            //Checking if the value of flag varible is true i.e. 1
            if(notFound)
            {
                //Displaying error message that no match found for search
                cout<<"No matching record found!"<            }
            break;
 
        //If user choose h then case h is executed for searching by highest temparature
        case 'h':
            notFound = 1;                       //Resetting the flag variable
 
            //Asking highest temparature from user for searching data
            cout<<"What is the high temparature you like to search for? ";
            cin>>in;
 
            //Iterating through the data till count i.e. total available records
            for(i=0; i            {
                //Checking if highest temperature of record is equal to user input
                if(days[i].high == in)
                {
                    //Updating the flag variable to 0 i.e. matched data is found
                    notFound = 0;
 
                    //Displaying the fetched record
                    cout<                }
            }
 
            //Checking if the value of flag varible is true i.e. 1
            if(notFound)
            {
                //Displaying error message that no match found for search
                cout<<"No matching record found!"<            }
            break;
 
        //If user choose a then case a is executed for searching by average temparature
        case 'a':
            notFound = 1;                       //Resetting the flag variable
 
            //Asking average temparature from user for searching data
            cout<<"What is the average temparature you like to search for? ";
            cin>>in;
 
            //Iterating through the data till count i.e. total available records
            for(i=0; i            {
                //Checking if average temperature of record is equal to user input
                if(days[i].avg == in)
                {
                    //Updating the flag variable to 0 i.e. matched data is found
                    notFound = 0;
 
                    //Displaying the fetched record
                    cout<                }
            }
 
            //Checking if the value of flag varible is true i.e. 1
            if(notFound)
            {
                //Displaying error message that no match found for search
                cout<<"No matching record found!"<            }
            break;
 
        //If user choose l then case l is executed for searching by lowest temparature
        case 'l':
            notFound = 1;                       //Resetting the flag variable
 
            //Asking lowest temparature from user for searching data
            cout<<"What is the low temparature you like to search for? ";
            cin>>in;
 
            //Iterating through the data till count i.e. total available records
            for(i=0; i            {
                //Checking if lowest temperature of record is equal to user input
                if(days[i].low == in)
                {
                    //Updating the flag variable to 0 i.e. matched data is found
                    notFound = 0;
 
                    //Displaying the fetched record
                    cout<                }
            }
 
            //Checking if the value of flag varible is true i.e. 1
            if(notFound)
            {
                //Displaying error message that no match found for search
                cout<<"No matching record found!"<            }
            break;
 
        //If user choose p then case p is executed for searching by sum of precipitation
        case 'p':
            notFound = 1;                       //Resetting the flag variable
 
            //Asking sum of precipitation from user for searching data
            cout<<"What is the sum of precipitation you like to search for? ";
            cin>>inp;
 
            //Iterating through the data till count i.e. total available records
            for(i=0; i            {
                //Checking if sum of precipitation of record is equal to user input
                if(days[i].sum == inp)
                {
                    //Updating the flag variable to 0 i.e. matched data is found
                    notFound = 0;
 
                    //Displaying the fetched record
                    cout<                }
            }
 
            //Checking if the value of flag varible is true i.e. 1
            if(notFound)
            {
                //Displaying error message that no match found for search
                cout<<"No matching record found!"<            }
            break;
 
        //If user choose e then case e is executed for searching by event
        case 'e':
            notFound = 1;                       //Resetting the flag variable
 
            //Asking events from user for searching data
            cout<<"What event would you like to search for? ";
            cin>>input;
 
            //Iterating through the data till count i.e. total available records
            for(i=0; i            {
                //Checking if ith record event contains event given as user input
                j = (days[i].events).find(input);
                if(j != -1)
                {
                    //Updating the flag variable to 0 i.e. matched data is found
                    notFound = 0;
 
                    //Displaying the fetched record
                    cout<                }
            }
 
            //Checking if the value of flag varible is true i.e. 1
            if(notFound)
            {
                //Displaying error message that no match found for search
                cout<<"No matching record found!"<            }
            break;

        //Default case is executed to inform user about invalid option when none of the above case matches 
        default:
            cout<<"Invalid choice."<    }
}
//Function to sort the Weather data
void sort(Weather days[1000], int count)
{
    char ch;                            //Variable to store parameter choice
    Weather temp;                       //Temporary Weather object for swapping objects during sorting
    int i, j;                           //Iterators
    bool xchn;                          //Flag variab...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here