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

Having trouble geting this to run correctly. Any info is appreciated. Thanks in

ID: 3716294 • Letter: H

Question

Having trouble geting this to run correctly. Any info is appreciated. Thanks in advance.

using namespace std;

#include <fstream>

#include <iostream>

#include <string>

#include <iomanip>

class CityInfo {

private:

void verifyRainfall_Entered();

void verifyTemp_Entered();

void verifyHumidity_Entered();

int temp;

float rainfall, humidity;

public:

void acceptInfo();

void dispInfo();

string city,state,zip;

};

int main()

{

acceptInfo();

dispInfo();

return 0;

}

//---------------------------------

void CityInfo::acceptInfo()

{

cout<<" Enter City Name : ";

cin>>city;

cout<<" Enter State Code: ";

cin>>state;

//Convert state code to upper case.

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

{

state[i]=toupper(state[i]);

}

  

cout<<" Enter ZipCode : ";

cin>>zip;

cout<<" Enter Rainfall : ";

cin>>rainfall;

verifyRainfall_Entered();

  

cout<<" Enter Humidity : ";

cin>>humidity;

verifyHumidity_Entered();

  

cout<<" Enter Temperature : ";

cin>>temp;

verifyTemp_Entered();

  

}

//------------------------------------

void CityInfo::verifyRainfall_Entered()

{

while(1)

{

if( rainfall >= 0 && rainfall <= 300) /// VERIFY THE RANGE FOR GIVEN RAINFALL

break; // LOOP WILL BREAK ONLY WHEN VALUE ENTERED IS WITHIN RANGE

else

{

cout<<" Rainfall entered is not in Range....";

cout<<" Enter Rainfall in range from 0 to 300 : ";

cin>>rainfall;

}  

}

}

//---------------------------------------

void CityInfo::verifyHumidity_Entered()

{

while(1)

{

if( humidity >= 0 && humidity <=100 ) // VERIFY THE RANGE FOR GIVEN HUMIDITY

break; // LOOP WILL BREAK ONLY WHEN VALUE ENTERED IS WITHIN RANGE

else

{

cout<<" Humidity entered is not in Range....";

cout<<" Enter Humidity in range from 0 to 100 : ";

cin>>humidity;

}  

}

}

//---------------------------------------------

void CityInfo::verifyTemp_Entered()

{

while(1)

{

if( temp >= -100 && temp <= 150) // VERIFY THE RANGE FOR GIVEN TEMP

break; // LOOP WILL BREAK ONLY WHEN VALUE ENTERED IS WITHIN RANGE

else

{

cout<<" Temperature is not in Range....";

cout<<" Enter Temperature in range from -100 to 150 : ";

cin>>temp;

}  

}  

  

}

//------------------------------------------------- DISPLAY REPORT OF CITY

void CityInfo::dispInfo()

{

cout<<" City Name : "<<city<<" State : "<<state<<" Zip : "<<zip;

cout<<" Rainfall : "<<rainfall;

cout<<" Relative Humidity : "<<humidity<<"%";

cout<<" Temperature : "<<temp;

};

Explanation / Answer

MODIFY YOUR INT MAIN() FUNCTION TO THIS

TO CALL ANY FUNCTION YOU NEED AN OBJECT TO BE CREATED TO THE CLASS

AND YOU HAVE TO ACCESS VARIABLE AND FUNCTIONS THROUGH THE OBJECT

int main()

{
CityInfo ci; // OBJECT IS CREATED TO THE CLASS
ci.acceptInfo(); // CALLING THE ACCEPTINFO() OF THE CLASS USING ITS OBJECT

ci.dispInfo(); // CALLING THE DISPINFO() THROUGH THE OBJECT OF THE CLASS

return 0;

}

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