Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

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 1	3	34	30	27	0 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 1	7	30	27	24	0.02	"Rain , Snow" 1	9	41	36	30	0.28	"Rain , Snow" 1	10	38	35	31	0.65	"Rain , Snow" 1	11	32	29	26	0.07	Snow 1	17	44	34	24	0.38	"Rain , Snow" 2	7	39	36	32	0.08	"Fog , Rain , Snow" 2	26	43	40	37	0.14	"Rain , Snow" 3	6	46	40	34	0.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 2	16	49	45	41	1.64	Rain 2	5	46	40	34	1.57	Rain 10	21	59	53	47	1.34	Rain    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 Day Aug 12, 2021

Solution

Sayed Shad Ahmad answered on Aug 16 2021
149 Votes
Solution_SSAZ/1.png
Solution_SSAZ/2.png
Solution_SSAZ/weather.cpp
Solution_SSAZ/weather.cpp
Including standard input output stream class
#includeIncluding filestream class
#includeIncluding the string class
#include 
Including the stringstream class
#includeUsing standard namespace
using namespace std;
Begin of Weather class
class Weathe
{
    
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 input;                           
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 use
    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 iterato
            
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 use
                if(j == in)
                {
                    
Checking if day value is equal to the day value supplied by use
                    if(days[i].day == in2)
                    {
                        
Updating the flag variable to 0 i.e. matched data is found
                        notFound = 0;
                        
                        
Displaying the fetched record
                        cout
days[i].day
"\t"
days[i].high
"\t"
days[i].avg
"\t"
days[i].low
"\t"
days[i].sum
"\t\t"
days[i].events
endl;
                        
                        
Exiting from the loop after matched data has been displayed
                        
eak;
                    }
                }
            }
            
            
Checking if the value of flag varible is true i.e. 1
            if(notFound)
            {
                
Displaying e
or message that no match found for search
                cout
"No matching record found!"
endl;
            }
            
eak;
            
        
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
days[i].day
"\t"
days[i].high
"\t"
days[i].avg
"\t"
days[i].low
"\t"
days[i].sum
"\t\t"
days[i].events
endl;
                }
            }
            
            
Checking if the value of flag varible is true i.e. 1
            if(notFound)
            {
                
Displaying e
or message that no match found for search
                cout
"No matching record found!"
endl;
            }
            
eak;
            
        
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
days[i].day
"\t"
days[i].high
"\t"
days[i].avg
"\t"
days[i].low
"\t"
days[i].sum
"\t\t"
days[i].events
endl;
                }
            }
            
            
Checking if the value of flag varible is true i.e. 1
            if(notFound)
            {
                
Displaying e
or message that no match found for search
                cout
"No matching record found!"
endl;
            }
            
eak;
            
        
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
days[i].day
"\t"
days[i].high
"\t"
days[i].avg
"\t"
days[i].low
"\t"
days[i].sum
"\t\t"
days[i].events
endl;
                }
            }
            
            
Checking if the value of flag varible is true i.e. 1
            if(notFound)
            {
                
Displaying e
or message that no match found for search
                cout
"No matching record found!"
endl;
            }
            
eak;
            
        
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
days[i].day
"\t"
days[i].high
"\t"
days[i].avg
"\t"
days[i].low
"\t"
days[i].sum
"\t\t"
days[i].events
endl;
                }
            }
            
            
Checking if the value of flag varible is true i.e. 1
            if(notFound)
            {
                
Displaying e
or message that no match found for search
                cout
"No matching record found!"
endl;
            }
            
eak;
            
        
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
days[i].day
"\t"
days[i].high
"\t"
days[i].avg
"\t"
days[i].low
"\t"
days[i].sum
"\t\t"
days[i].events
endl;
                }
            }
            
            
Checking if the value of flag varible is true i.e. 1
            if(notFound)
            {
                
Displaying e
or message that no match found for search
                cout
"No matching record found!"
endl;
            }
            
eak;
        
        
Default case is executed to inform user about invalid option when none of the above case matches 
        default:
            cout
"Invalid choice."
endl;
    }
}
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