Question

In: Computer Science

You will create a datafile with the following information: 70 80 90 55 25 62 45...

You will create a datafile with the following information: 70 80 90 55 25 62 45 34 76 105You will then write the program to read in the values from the datafile and as you read in each number, you will then evaluate it through an if statement for the weather of the day. For example, when you read in the value 70 from the datafile, you should print to the screen that the temperature is 70° and it is nice outside. After reading in all the values, you will determine which is the highest temperature and which is the lowest temperature. For example, your output will look like this:

The temperature for today is 70. It is nice outside.

The temperature for today is 80. It is getting warm outside.

The temperature for today is 90. It is hot outside.

The temperature for today is 55. It is cool outside.

The temperature for today is 25. It is really cold outside.

The temperature for today is 62. It is comfortable outside.

The temperature for today is 45. It ischilly outside.

The temperature for today is 34. It is cold outside.

The temperature for today is 76. It is nice outside.

The temperature for today is 105. It is really hot outside.

The high temperature for today is 105.

The low temperature for today is 25

Hints: You will need to create an if statement after you read your values in from the database to check the temperatures.

The ranges should be:

Above 100 –really hot

90-100 –hot

80-90 –getting warm

70-80 –nice

60-70 –comfortable

50-60 –cool

40-50 –chilly

30-40 –cold

20-30 –really cold

Below 20 –freezing

Notice that the number values such as 90 shows up in both selections. Instead of 90, one of them has to be 89 and so on. You will determine where the cutoffs are. Do not hard code the output information. Make sure you are running it through an if statement because my datafile will have different values than yours.

Solutions

Expert Solution

//Make sure to save you temperature data in a text file named "temperature.txt"

#include <iostream>

#include <fstream>

using namespace std;

void printList(double arr[], int n);

double getLargest(double arr[], int n);

double getSmallest(double arr[], int n);

int main()

{

    double arr[200];

    int n;

    ifstream inFile;

    inFile.open("temprature.txt");

    if (inFile.fail())

    {

        cout << "Unable to open file" << endl;

        return -1;

    }

    n = 0;

    while (!inFile.eof())

    {

        inFile >> arr[n];

        n++;

    }

    inFile.close();

    cout << "Loaded tempratures from file.....\n" << endl;

    printList(arr, n);

    cout << "The high temperature for today is: " << getLargest(arr, n) << endl;

    cout << "The low temperature for today: " << getSmallest(arr, n) << endl;

    return 0;

}

void printList(double arr[], int n)

{

    int i;

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

        if(arr[i]<20)

            printf("The temperature for today is %f. It is freezing outside\n",arr[i]);

        else if(arr[i]>=20 && arr[i]<30)

            printf("The temperature for today is %f. It is really cold outside\n",arr[i]);

        else if(arr[i]>=30 && arr[i]<40)

            printf("The temperature for today is %f. It is cold outside\n",arr[i]);  

        else if(arr[i]>=40 && arr[i]<50)

            printf("The temperature for today is %f. It is chilly outside\n",arr[i]);

        else if(arr[i]>=50 && arr[i]<60)

            printf("The temperature for today is %f. It is cool outside\n",arr[i]);  

        else if(arr[i]>=60 && arr[i]<70)

            printf("The temperature for today is %f. It is comfortable outside\n",arr[i]);  

        else if(arr[i]>=70 && arr[i]<80)

            printf("The temperature for today is %f. It is nice outside\n",arr[i]);

        else if(arr[i]>=80 && arr[i]<90)

            printf("The temperature for today is %f. It is getting warm outside\n",arr[i]);

        else if(arr[i]>=90 && arr[i]<100)

            printf("The temperature for today is %f. It is hot outside\n",arr[i]);

        else if(arr[i]>=100 )

            printf("The temperature for today is %f. It is hot outside\n",arr[i]);

    }

    cout << endl;

}

D

double getLargest(double arr[], int n)

{

    double largest = arr[0];

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

    {

        if (largest < arr[i])

            largest = arr[i];

    }

    return largest;

}

double getSmallest(double arr[], int n)

{

    double smallest = arr[0];

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

    {

        if (smallest > arr[i])

            smallest = arr[i];

    }

    return smallest;

}

//SAMPLE OUTPUT

******************************************************************************************
PLEASE LIKE IT RAISE YOUR THUMBS UP
IF YOU ARE HAVING ANY DOUBT FEEL FREE TO ASK IN COMMENT SECTION
******************************************************************************************


Related Solutions

USE VISUAL BASIC / VB You will create a datafile with the following information: 70 80...
USE VISUAL BASIC / VB You will create a datafile with the following information: 70 80 90 55 25 62 45 34 76 105You will then write the program to read in the values from the datafile and as you read in each number, you will then evaluate it through an if statement for the weather of the day. For example, when you read in the value 70 from the datafile, you should print to the screen that the temperature...
Permissive Authoritative Authoritarian 70 70 55 90 80 80 90 90 75 90 70 67 M=85...
Permissive Authoritative Authoritarian 70 70 55 90 80 80 90 90 75 90 70 67 M=85 75 50 M=81 63 65 M=65 grand mean=75 Calculate your F ratio. [ If you could not answer any of the questions above about the SS and df values, go back now and make up numbers to fill in for those values then use those wrong numbers to find this F ratio. Those will be wrong, but this could be right based on those...
Use the data (12, 55), (15, 62), and (20, 80) to calculate the likelihood value for...
Use the data (12, 55), (15, 62), and (20, 80) to calculate the likelihood value for the parameter values β0 = 15 and β1 = 3 when assume σ = 2. Please show all calculations.
"Hit" Group "Smashed Into" Group 25 50 25 45 34 55 30 40 36 45 37...
"Hit" Group "Smashed Into" Group 25 50 25 45 34 55 30 40 36 45 37 41 31 50 35 35 30 37 35 45 30 55 25 50 20 45 25 43 30 42 24 40 34 36 33 45 37 50 38 41 A. Null Hypothesis? Ha: Smashed into group estimated higher speed than hit group Ho: Smashed into group estimated lower or same speed than hit group(directional hypothesis) B. Alternative hypothesis? Ha: Smashed into group estimated higher...
Use the following contingency table to complete​. A B C Total 1 10 25 55 90...
Use the following contingency table to complete​. A B C Total 1 10 25 55 90 2 40 50 60 150 Total 50 75 115 240 a. Compute the expected frequencies for each cell. b. Set up the null and alternative hypotheses to test. c. Compute X2STAT Is it significant at α=0.01​? d. Compute P-Value e.Is X2STAT significant at α=0.01​?
Complete parts​ (a) through​ (h) for the data below. x- 40, 50, 60, 70, 80 y-62,...
Complete parts​ (a) through​ (h) for the data below. x- 40, 50, 60, 70, 80 y-62, 58, 55, 47, 33 B) Find the equation of the line containing the points (50, 58) and (80, 33) y=__x+(__) D) By hand, determine the least-squares regression line The equation of the​ least-squares regression line is given by ModifyingAbove y with caret equals b 1 x plus b 0y=b1x+b0 where b1 equals r times StartFraction s Subscript y Over s Subscript x EndFractionb1=r•sysx is...
What percentage of the U.S. population is overweight by BMI? 70% 90% 50% 25%   What are...
What percentage of the U.S. population is overweight by BMI? 70% 90% 50% 25%   What are the potential mechanisms for increasing glucose uptake into muscle? Contraction mediated Glut1 translocation Insulin mediated Glut4 translocation Contraction mediated Glut4 translocation B+C Which of the following is NOT a precaution that should be taken to reduce the risk of exercise- induced hypoglycemia (low blood sugar) in patients with type 1 diabetes? Consume carbohydrate if glucose is <100 mg/dl Avoid exercising during peak insulin action...
Here is a set of sample data. 3 87 7 57 15 90 25 55 68...
Here is a set of sample data. 3 87 7 57 15 90 25 55 68 70 89 20 26 93 9 5 86 23 37 52 96 4 91 Base on the data above, identify the 5 number summary _ , _ ,_ , _ , _
z = [ 100 93 90 89 80 79 78 75 67 60 45 42 41...
z = [ 100 93 90 89 80 79 78 75 67 60 45 42 41 40 30 20 15 12 10 9 2 1] Using MATLAB, Write fully vectorized code (no loops) to find index number of which the numbers have decreased by 40. Print results to command window.
Construct a frequency polygon for the following: 60-69   12 70-79   15 80-89    10 90-99      2 100-109...
Construct a frequency polygon for the following: 60-69   12 70-79   15 80-89    10 90-99      2 100-109 1 110-119   0 120-129   1
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT