Question

In: Computer Science

c++ Design the Weather class that contains the following members: Data members to store: -a day...

c++

Design the Weather class that contains the following members:

Data members to store:

-a day (an integer)

-a month (an integer)

-a year (an integer)

-a temperature (a float)

-a static data member that stores the total of all temperatures (a float)

Member functions:

-a constructor function that obtains a day, month, year and temperature from the user. This function should also accumulate/calculate the total of all temperatures (i.e., add the newly entered temperature to the total).

-a static function that computes and displays the day which has the lowest temperature. Note: An array of Weather objects and the size of the array will be passed to this function.

-a static function that computes and displays the average temperature. This function should use a parameter,if necessary.

Design the main( )function, which instantiates/creates any number of objects of the Weather class as requested by the user (i.e., creates a dynamic array of Weather objects). main( )should also call appropriate functions to compute and display the day that has the lowest temperature, as well as the average temperature.Your program should include all necessary error checking.

A sample run of this program could be as follows:

How many days => 4

Enter day, month, year, temperature => 29 11 2018 15.6

Enter day, month, year, temperature => 30 11 2018 8.7

Enter day, month, year, temperature => 1 12 2018 3.1

Enter day, month, year, temperature => 2 12 2018 3.5

Lowest temperature = 3.1C, Day 1/12/2018

Average temperature = 7.7 C

Solutions

Expert Solution

If you have any doubts, please give me comment...

#include<iostream>

#include<iomanip>

using namespace std;

class Weather{

    public:

        int day;

        int month;

        int year;

        float temperature;

        static float total;

        Weather(){

            cout<<"Enter day, month, year, temperature => ";

            cin>>day>>month>>year>>temperature;

            total += temperature;

        }

        static void displayLowestTemperature(Weather *w, int n){

            int lowest = 0;

            for(int i=0; i<n; i++){

                if(w[lowest].temperature>w[i].temperature){

                    lowest = i;

                }

            }

            cout<<"Lowest temperature = "<<w[lowest].temperature<<"C, Day "<<w[lowest].day<<"/"<<w[lowest].month<<"/"<<w[lowest].year<<endl;

        }

        static void displayAverageTemperature(int n){

            double avg = total/n;

            cout<<"Average temperature = "<<avg<<" C"<<endl;

        }

};

float Weather::total = 0;

int main(){

    int n;

    cout<<"How many days => ";

    cin>>n;

    Weather *w = new Weather[n];

    cout<<setprecision(1)<<fixed;

    Weather::displayLowestTemperature(w, n);

    Weather::displayAverageTemperature(n);

    return 0;

}


Related Solutions

C++ Assignment. Design the Weather class that contains the following members: Data members to store: -...
C++ Assignment. Design the Weather class that contains the following members: Data members to store: - a day (an integer) - a month (an integer) - a year (an integer) - a temperature (a float) - a static data member that stores the total of all temperatures (a float) Member functions: - a constructor function that obtains a day, month, year and temperature from the user. This function should also accumulate/calculate the total of all temperatures (i.e., add the newly...
C++ program: Create a Date class that contains three members: the month, the day of the...
C++ program: Create a Date class that contains three members: the month, the day of the month, and the year, all of type int. The user should enter a date in the format 12/31/2001, store it in an object of type Date, then retrieve the object and print it out in the same format. Next create an employee class. The member data should comprise an employee number (type int) and the employee’s compensation (in dollars; type float). Extend the employee...
C++ Define a MyDate class to represent a data that has 3 data members: day, month,...
C++ Define a MyDate class to represent a data that has 3 data members: day, month, year. The class should have: A default constructor to initialize the day, month, and year to 0. A constructor that accepts three integers as arguments to initialize the day, month, and year if the three arguments are valid. A copy constructor that accepts a reference to a MyDate object as argument. This constructor use the argument's three data fields to initialize the day, month,...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance:...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance: balance held in the account interestRate: annual interest rate. accountID: unique 3 digit account number assigned to each BankAccount object. Use a static data member to generate this unique account number for each BankAccount count: A static data member to track the count of the number of BankAccount objects created. Member Functions void withdraw(double amount): function which withdraws an amount from accountBalance void deposit(double...
Create a "Date" class that contains: three private data members: month day year (I leave it...
Create a "Date" class that contains: three private data members: month day year (I leave it to you to decide the type) "setters" and "getters" for each of the data (6 functions in total) One advantage of a "setter" is that it can provide error checking. Add assert statements to the setter to enforce reasonable conditions. For example, day might be restricted to between 1 and 31 inclusive. one default constructor (no arguments) one constructor with three arguments: month, day,...
11. Payroll in C++ Design a PayRoll class that has data members for an employee’s hourly...
11. Payroll in C++ Design a PayRoll class that has data members for an employee’s hourly pay rate, number of hours worked of type double. The default constructor will set the hours worked and pay rate to zero. The class must have a mutator function to set the pay rate for each employee and hours worked. The class should include accessors for both the hours worked and the rate of pay. The class should lastly have a getGross function that...
C++ CLASSES 1. Define a class date that has day, month and year data members. 2....
C++ CLASSES 1. Define a class date that has day, month and year data members. 2. Define a class reservation with following data members: - An integer counter that generates reservation numbers. - An integer as a reservation number. The counter is incremented each time a reservation object is created. This value will be assigned as the reservation number. - Number of beds. - Reservation date from class date. 3. Define a class rooms with data members: - Room number...
In c++ Design a class named Account that contains: a.An int data field named id for...
In c++ Design a class named Account that contains: a.An int data field named id for the account. b.A double data field named balancefor the account. c.A double data field named annualInterestRate that stores the current interestrate. d.A no-arg constructor that creates a default account with id 0, balance 0, andannualInterestRate 0. e.The set and get functions for id,balance, and annualInterestRate. f.A functionearnedAmount()that calculates and returns the amount of dollars earned after one year. g.A function named printAccountInfo() that print...
c++ E2b: Design a class named Rectangle to represent a rectangle. The class contains:
using c++E2b: Design a class named Rectangle to represent a rectangle. The class contains:(1) Two double data members named width and height which specifies the width and height of the rectangle .(2) A no-arg constructor that creates a rectangle with width 1 and height 1.(3) A constructor that creates a rectangle with the specified width and height .(4) A function named getArea() that returns the area of this rectangle .(5) A function named getPerimeter() that returns the perimeter of this...
Design a Ship class that the following members: A field for the name of the ship...
Design a Ship class that the following members: A field for the name of the ship (a string). A field for the year that the ship was built (a string). A constructor and appropriate accessors and mutators. A toString method that displays the ship’s name and the year it was built. Design a CruiseShip class that extends the Ship class. The CruiseShip class should have the following members: A field for the maximum number of passengers (an int). A constructor...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT