Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PROGRAMMING QUESTION (10 POINTS) Write a program that computes the lowest annual

ID: 3754062 • Letter: P

Question

PROGRAMMING QUESTION (10 POINTS) Write a program that computes the lowest annual temperature for each of 50 states .Ask the user to enter the name of all 50 states of the United States For each state, ask the user to enter the lowest temperature for each month of the year For each state, determine the lowest temperature for the entire year For each state, display the name of the state and its lowest temperatures for the year For simplicity, you can identify month by number (1 through 12) rather than name. Write out all include statements.

Explanation / Answer

On windows , Use

>g++ temp.cpp

>a.exe

On Linux/Ubuntu

>gcc temp.cpp

>./a.out

//Temp.cpp

#include<iostream>

using namespace std;

class State //Class For Storing the State name and Lowest Temperature of each month.

{

string stateName; //State Name.

string month[12]; //String array for Month Names. Logically Does nothing but for Printing the Names of Months in Program.

float lowtemp; //Member Variable for Lowest Temperature of the state in the year.

float temp[12]; //Float array to store temperatures of 12 months.

public:

State():month{"January","February","March","April","May","June","July","August","September","October","November","December"} //This constructor does nothing but initialises the month array. Because in C++ we cannot initialise the variable in the class member declaration i.e. above declarations.

{

}

void accept() //Function for accepting the values from user.

{

cout<<"Enter State Name : "<<endl;

cin>>stateName;

for(int i=0;i<12;i++)

{

cout<<"Enter Lowest Temperature for "<<month[i]<<endl;

//cout<<"Enter Lowest Temperature for Month "<<i+1<<endl; //In case you dont want to use Names of Months .In this case Remove the Constructor with the month initialisation.

cin>>temp[i];

}

}

void Lowest() //function for finding Lowest temperature in the year.

{

lowtemp=temp[0];

for(int i=1;i<12;i++)

{

if(temp[i]<lowtemp)

{

lowtemp=temp[i]; //Storing lowest Temperature.

}

}

cout<<"Lowest Temperature for year for State "<<stateName<<" is "<<lowtemp<<endl; //printing Lowest Temperature.

}

};

int main()

{

State obj[50]; //Creating Array of States for Storing values of 50 States

for(int i=0;i<50;i++)

{

obj[i].accept(); //Calling Accept function of Each State.

}

for(int j=0;j<50;j++)

{

obj[j].Lowest(); //Calling Lowest Function for Printing Lowest Temperature of Each State.

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote