Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6823043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:44:08+00:00 2026-05-26T21:44:08+00:00

Hi I am working on a class for a weather station that asks a

  • 0

Hi I am working on a class for a weather station that asks a user to input variables and it passes the hours to an array: calculating the values for average, Highs and lows. I got it to work but want to make the array[elements] private. Is it possible to do this?

Here is my code so far. Thank you in advance for any help.

Brian

#include <iostream>
#include <iomanip>

using namespace std;

class WeatherStation
{
public:
    WeatherStation();
    void GetATemperatures(int[], int);
    void DisplayATemperatures( int[], int);
    void arrayCalcs(int[], int);

private:
    static const int aTemps = 24;
    static const int atemps[aTemps];
};

WeatherStation::WeatherStation()
{
    int atemps[aTemps];
}

void WeatherStation::GetATemperatures(int atemps[], int aTemps)
{
    for (int i = 0; i < aTemps; i++ )
    {
        cout << "Please enter the temperature for " << i  << ":00 ";

        while(true)
        {
            cin >> atemps[i];

            if(atemps[i] >= -50 && atemps[i] <= 130)
            {
                break;
            } else {
                cout << "This temperature is not valid\n";
                cout << "Please enter a temperature between -50 and 130 degrees F \n";
                cout << "Please enter a new temperature: ";
            }
        }
    }
}

void WeatherStation::DisplayATemperatures( int atemps[], int aTemps)
{
    cout << setw (5) << "Hour" << setw(24)<< "Temperature \n";
    cout << "\n";

    for (int k = 0; k < aTemps; k++)
    {
        cout << setw (3) << k << ":00" << setw (16) << atemps[k]<<endl;
    }

    cout <<"\n";
}

void WeatherStation::arrayCalcs(int atemps[], int aTemps)
{
    int sumA = 0;

    double average = 0.0;
    int minA = atemps[0];

    int maxA = atemps[0];

    int lowest = 0;
    int highest = 0;

    //Sum of the AM temps
    for (int kk = 0; kk < aTemps; kk++)
    {
        sumA = sumA + atemps[kk];
    }

    //calculation for average

    average = sumA  / aTemps;

    //Figuring out the Min and Max AM temps

    for (int MM = 0; MM < aTemps; MM++)
    {
        if(minA > atemps[MM])
        {
            minA = atemps[MM];
        }
        else if(maxA < atemps[MM])
        {
            maxA = atemps[MM];
        }

        lowest = minA;
        highest = maxA;
    }


    //Display of the Calculation results
    cout << "This is the average of todays temperatures: " << average <<endl;
    cout <<endl;
    cout << "Todays High temperature is: " << highest <<endl;
    cout <<endl;
    cout << "Todays Low temperature is: " << lowest <<endl;
}

int main()
{
    cout <<"Welcome to the weather station.\n";
    cout <<"Please enter Ferenheit temperatures for calculations: \n";

    WeatherStation alpha;
    alpha.GetATemperatures(atemps, aTemps);
    alpha.DisplayATemperatures(temps, Temps);
    alpha.arrayCalcs(temps,Temps);

    cout << "\n";

    system("pause");
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:44:08+00:00Added an answer on May 26, 2026 at 9:44 pm

    1) Is the array atemps[]? If so, it’s already private… what’s the problem?

    2) Why is your array class member static? Don’t do that without damned good reason (and as this appears to be a homework assignment, I’m almost certain you don’t have a damned good reason).

    3) Your constructor has a useless line of code in it — and that’s the only line in the function.

    4) Your professor will not accept you naming variables atemps and aTemps — and if they do overlook it, I would be very concerned for the quality of education you’re receiving. It’s not that the variable names themselves are a big issue, but rather that you’re naming them so similarly, as this is a recipe for a maintenance nightmare if it were to happen in real code.

    Edit — based on our comment-chat, here is my suggestion. I have not tried to compile this and I don’t claim this is the best (or even a suggested) way to write your program… my suggestion is limited to leaving the data within your object (in a way that has room for growth beyond this question / discussion).

    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    class WeatherStation
    {
    public:
        WeatherStation();
        void GetATemperatures();
        void DisplayATemperatures();
        void arrayCalcs();
    
    private:
        static const int aTemps = 24;
        int atemps[aTemps];
    };
    
    WeatherStation::WeatherStation()
    {
    }
    
    void WeatherStation::GetATemperatures()
    {
        for (int i = 0; i < aTemps; i++ )
        {
            cout << "Please enter the temperature for " << i  << ":00 ";
    
            while(true)
            {
                cin >> atemps[i];
    
                if(atemps[i] >= -50 && atemps[i] <= 130)
                {
                    break;
                } else {
                    cout << "This temperature is not valid\n";
                    cout << "Please enter a temperature between -50 and 130 degrees F \n";
                    cout << "Please enter a new temperature: ";
                }
            }
        }
    }
    
    void WeatherStation::DisplayATemperatures()
    {
        cout << setw (5) << "Hour" << setw(24)<< "Temperature \n";
        cout << "\n";
    
        for (int k = 0; k < aTemps; k++)
        {
            cout << setw (3) << k << ":00" << setw (16) << atemps[k]<<endl;
        }
    
        cout <<"\n";
    }
    
    void WeatherStation::arrayCalcs()
    {
        int sumA = 0;
    
        double average = 0.0;
        int minA = atemps[0];
    
        int maxA = atemps[0];
    
        int lowest = 0;
        int highest = 0;
    
        //Sum of the AM temps
        for (int kk = 0; kk < aTemps; kk++)
        {
            sumA = sumA + atemps[kk];
        }
    
        //calculation for average
    
        average = sumA  / aTemps;
    
        //Figuring out the Min and Max AM temps
    
        for (int MM = 0; MM < aTemps; MM++)
        {
            if(minA > atemps[MM])
            {
                minA = atemps[MM];
            }
            else if(maxA < atemps[MM])
            {
                maxA = atemps[MM];
            }
    
            lowest = minA;
            highest = maxA;
        }
    
    
        //Display of the Calculation results
        cout << "This is the average of todays temperatures: " << average <<endl;
        cout <<endl;
        cout << "Todays High temperature is: " << highest <<endl;
        cout <<endl;
        cout << "Todays Low temperature is: " << lowest <<endl;
    }
    
    int main()
    {
        cout <<"Welcome to the weather station.\n";
        cout <<"Please enter Ferenheit temperatures for calculations: \n";
    
        WeatherStation alpha;
        alpha.GetATemperatures();
        alpha.DisplayATemperatures();
        alpha.arrayCalcs();
    
        cout << "\n";
    
        system("pause");
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a class that is storing a 2D array of class MyType
Does anyone have a working class or function to create the hashed email that
Can anybody say me, why that isn't working: class A attr_accessor :b end a
I'm working on a class that inherits from another class, but I'm getting a
I'm working on a class assignment that started small, so I had it all
I have converted a working C# class that embeds xls files to windows forms
Here is the way I have my base class working: class AguiWidgetBase { //variables
using System; using System.IO; using System.Net; using System.Text.RegularExpressions; namespace Working { class Program4 {
I have a working wrapper class for Dallmeier camera devices, It contains a callback
Here's the domain classes I'm working with: class Foo { String name, type static

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.