13 Write a code segment to solve this problem You do not hav

13. Write a code segment to solve this problem. You do not have to write an entire program, just a code segment. (You can keep the output very simple; your labels do not require complete sentences.)…. But make sure you can solve it.

-Declare an int constant MAX and initialize MAX to 25

-Declare a string variable for city_name

-Declare a double variable for rainfall

-Declare an int variable for the temperature in Fahrenheit
- Declare a double variable for temperature in Celsius

//// You may need to declare additional variables////

- Write a count – controlled while loop to process MAX number of cities

- For each city, prompt the user to input the city_name, the inches of rainfall and the temperature in Fahrenheit. ( the city name will not have blanks; for example, the user would enter NewYorkCity. )

- Echo print all of the input data.

- Use this formula to convert from Fahrenheit to Celsius:    C = ( 5.0/9.0 ) (F - 32 )

- If a city has a Celsius temp above 35 and rainfall less than .01 inches print out HOT AND DRY. If a city has a Celsius temp less than 5 and rainfall greater than 2.5 inches print out COLD AND DAMP.

- At the conclusion of the while loop, print out the following counts: Number of cities that were HOT AND DRY. Number of cities that were COLD AND DAMP.

- Test your solution with user input.

- Modify your program to process an input file of the same type of data values. Save this version, and then test your program with an input file of your creation.

Solution

#include <iostream>
#include <string.h>
using namespace std;
int main() {
    int const MAX = 25;
    string city_name;
    double rainfall;
    int F;
    double C;
    int count=0;
    int hd = 0;               // hot and dry count
    int cd = 0;               // cold and damp count
    while(count<MAX){
       cout << \"----------- city data -------------\"<<endl;
       cout<< \"Enter city_name:\";
       cin>> city_name;
       cout << \"Inches of rainfall:\";
       cin >> rainfall;
       cout << \"Temperature in Farenheit:\";
       cin >> F;
       C = ( 5.0/9.0 )*(F - 32 );
       cout<<\"CityName:\"<<city_name<<\"\ RainFall:\"<<rainfall<<\"\ Fareinheit Temperature:\"<<F<<endl;
      
       if(C>25 && rainfall<0.01){
           cout << \"HOT AND DRY\"<<endl;
           hd++;
       }
       if(C<5 && rainfall>2.5){
           cout << \"COLD AND DAMP\" << endl;
           cd++;
       }
       count++;
    }
    cout << \"------------- Analysis ------------\" << endl;
    cout << \"HOT AND DRY cities:\"<<hd<<endl;
    cout << \"COLD AND DAMP cities:\"<<cd<<endl;
}

/* sample output for 2 cities

*/

part 2 file reading.

#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;
int main() {
    int const MAX = 25;
    string city_name;
    double rainfall;
    int F;
    double C;
    int count=0;
    int hd = 0;               // hot and dry count
    int cd = 0;               // cold and damp count
    ifstream infile(\"citydata.txt\");
    while(count<MAX){
       cout << \"----------- city data -------------\"<<endl;
       infile >> city_name >> rainfall >> F;
       C = ( 5.0/9.0 )*(F - 32 );
       cout<<\"CityName:\"<<city_name<<\"\ RainFall:\"<<rainfall<<\"\ Fareinheit Temperature:\"<<F<<endl;
      
       if(C>25 && rainfall<0.01){
           cout << \"HOT AND DRY\"<<endl;
           hd++;
       }
       if(C<5 && rainfall>2.5){
           cout << \"COLD AND DAMP\" << endl;
           cd++;
       }
       count++;
    }
    cout << \"------------- Analysis ------------\" << endl;
    cout << \"HOT AND DRY cities:\"<<hd<<endl;
    cout << \"COLD AND DAMP cities:\"<<cd<<endl;
}

/*

sample input for 2 cities data

citydata.txt

hyd 0.1 100
ban 2.6 10


sample output

*/

13. Write a code segment to solve this problem. You do not have to write an entire program, just a code segment. (You can keep the output very simple; your labe
13. Write a code segment to solve this problem. You do not have to write an entire program, just a code segment. (You can keep the output very simple; your labe
13. Write a code segment to solve this problem. You do not have to write an entire program, just a code segment. (You can keep the output very simple; your labe

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site