Question

This program involves inputting a set of Fahrenheit temperatures and performing a set of operations on them: The number of te

Notes/Specifications 1. Display all floating-point numbers to one decimal place. 2. No global variables. 3. Your code must no

You can vary it as long as the fahr and cels temperatures line up vertically and everything is clearly labeled.

This program involves inputting a set of Fahrenheit temperatures and performing a set of operations on them: The number of temperatures to input is determined by the user at the beginning of the program. You must ask them to enter the number of temperatures that they will be typing in. This number must be between 1 and 30 (inclusive.) If it is not, you need to display a message informing the user that the value they entered is out of range and make them re-input as many times as needed 1. 2. Temperature values must be between -175.0 to 175.0 (inclusive). Reject any values that are not in this range and prompt for a re-input. 3. You must declare an array to hold your (double) temperature values. 4. The report consists of the following output (which must be done in this order): a. All of the temperatures, in ascending order b. The average temperatures (for Fahrenheit and Celsius) c. The highest and lowest temperatures (for Fahrenheit and Celsius) d. The number of temperatures input e. The amount of temperatures abovelequal toland below the average (once) f. The amount of Fahrenheit (only) temperatures 100 or higher, greater tharn 32 but less than 100, and 32 or lower.
Notes/Specifications 1. Display all floating-point numbers to one decimal place. 2. No global variables. 3. Your code must not generate any compiler warnings or errors as submitted. 4. You must use main) as a driver function and move all of your tasks to other functions. Part of your grade is breaking down the problem into smaller components. Each function should only handle one primary task (generating and outputting the same part of a report cannot be in the same function.) Do not throw everything (or function calls to everything) into a function called by main() in an attempt to circumvent this guideline - doing so will result in a significant penalty. The only permissible statements in main) are: Declaring variables; Calling other functions; The return 0 statement. o o 5. Your program must compile without any warnings or errors. 6. Make sure your code is well documented and observes style guidelines. Code that is difficult to read/follow and/or has poor variable/function names will result in a deduction.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <iomanip>

using namespace std;

double fahrenheitToCelsius(double F){
    return (F - 32) * 5 / 9;
}

void inputTemp(double fTemp[], double cTemp[], int &num){
    cout << "Enter number of temperatures to input: ";
    cin >> num;
    while(num < 1 || num > 30){
        cout << "Number of temperatures must be in range 1 and 30(inclusive)." << endl;
        cout << "Enter number of temperatures to input: ";
        cin >> num;
    }
    for(int i = 0; i < num; i++){
        cout << "Enter temperature in Fahrenheit: ";
        cin >> fTemp[i];
        while(fTemp[i] < -175.0 || fTemp[i] > 175.0){
            cout << "Temperature must be between -175.0 to 175.0(inclusive)." << endl;
            cout << "Enter temperature in Fahrenheit: ";
            cin >> fTemp[i];
        }
        cTemp[i] = fahrenheitToCelsius(fTemp[i]);
    }
}

//Function to sort temperatures using bubble sort
void sortTemp(double temp[], const int num){
    for(int i = 0; i < num - 1; i++)
        for(int j = 0; j < num - i - 1; j++)
            if(temp[j] > temp[j + 1]){
                //Swap adjacent temperatures
                double t = temp[j];
                temp[j] = temp[j + 1];
                temp[j + 1] = t;
            }
}

//Function to get average temperature
double getAvgTemp(const double temp[], const int num){
    double sum = 0.0;
    for(int i = 0; i < num; i++)
        sum += temp[i];
    return sum/num;
}

//Function to get highest temperature
double getHighTemp(const double temp[], const int num){
    double high = temp[0];
    for(int i = 1; i < num; i++)
        if(temp[i] > high)
            high = temp[i];
    return high;
}

//Function to get lowest temperature
double getLowTemp(const double temp[], const int num){
    double low = temp[0];
    for(int i = 1; i < num; i++)
        if(temp[i] < low)
            low = temp[i];
    return low;
}

//Function to get number of temperatures above average
int numAboveAverage(const double temp[], const int num){
    double avg = getAvgTemp(temp, num);
    int n = 0;
    for(int i = 0; i < num; i++)
        if(temp[i] > avg)
            n++;
    return n;
}

//Function to get number of temperatures equal to average
int numEqualToAverage(const double temp[], const int num){
    double avg = getAvgTemp(temp, num);
    int n = 0;
    for(int i = 0; i < num; i++)
        if(temp[i] == avg)
            n++;
    return n;
}

//Function to get number of temperatures below average
int numBelowAverage(const double temp[], const int num){
    double avg = getAvgTemp(temp, num);
    int n = 0;
    for(int i = 0; i < num; i++)
        if(temp[i] < avg)
            n++;
    return n;
}

//Function to get number of Fahrenheit temperatures 100 or higher
int numFHigherThan100(const double temp[], const int num){
    int n = 0;
    for(int i = 0; i < num; i++)
        if(temp[i] >= 100)
            n++;
    return n;
}

//Function to get number of Fahrenheit temperatures > 32 but < 100
int numFBetween32And100(const double temp[], const int num){
    int n = 0;
    for(int i = 0; i < num; i++)
        if(temp[i] > 32 && temp[i] < 100)
            n++;
    return n;
}

//Function to get number of Fahrenheit temperatures 32 or lower
int numFLowerThan32(const double temp[], const int num){
    int n = 0;
    for(int i = 0; i < num; i++)
        if(temp[i] <= 32)
            n++;
    return n;
}

void printReport(const double fTemp[], const double cTemp[], const int num){
    //Part (a)
    cout << "\nTemperatures in ascending order:" << endl;
    cout << left << setw(15) << "Fahrenheit" << setw(15) << "Celsius" << endl;
    for(int i = 0; i < num; i++)
        cout << left << setprecision(1) << fixed << setw(15) << fTemp[i] << setw(15) << cTemp[i] << endl;
    cout << endl;

    //Part (b)
    cout << "Average temperature(in Fahrenheit): " << getAvgTemp(fTemp, num) << endl;
    cout << "Average temperature(in Celsius): " << getAvgTemp(cTemp, num) << endl;
    cout << endl;

    //Part (c)
    cout << "Highest temperature(in Fahrenheit): " << getHighTemp(fTemp, num) << endl;
    cout << "Lowest temperature(in Fahrenheit): " << getLowTemp(fTemp, num) << endl;
    cout << "Highest temperature(in Celsius): " << getHighTemp(cTemp, num) << endl;
    cout << "Lowest temperature(in Celsius): " << getLowTemp(cTemp, num) << endl;
    cout << endl;

    //Part (d)
    cout << "Number of temperature inputs: " << num << endl;
    cout << endl;

    //Part (e)
    cout << "Number of temperatures above average(in Fahrenheit): " << numAboveAverage(fTemp, num) << endl;
    cout << "Number of temperatures equal to average(in Fahrenheit): " << numEqualToAverage(fTemp, num) << endl;
    cout << "Number of temperatures below average(in Fahrenheit): " << numBelowAverage(fTemp, num) << endl;
    cout << "Number of temperatures above average(in Celsius): " << numAboveAverage(cTemp, num) << endl;
    cout << "Number of temperatures equal to average(in Celsius): " << numEqualToAverage(cTemp, num) << endl;
    cout << "Number of temperatures below average(in Celsius): " << numBelowAverage(cTemp, num) << endl;
    cout << endl;

    //Part (f)
    cout << "Number of temperatures 100 or higher(in Fahrenheit): " << numFHigherThan100(fTemp, num) << endl;
    cout << "Number of temperatures greater than 32 but less than 100(in Fahrenheit): " << numFBetween32And100(fTemp, num) << endl;
    cout << "Number of temperatures 32 or lower(in Fahrenheit): " << numFLowerThan32(fTemp, num) << endl;
    cout << endl;
}

int main(){
    const int MAX = 30;
    int num = 0;//Number of temperatures
    double fTemp[MAX], cTemp[MAX];//Array to hold Fahrenheit and Celsius temperatures
    inputTemp(fTemp, cTemp, num);
    sortTemp(fTemp, num);
    sortTemp(cTemp, num);
    printReport(fTemp, cTemp, num);
    return 0;
}

SAMPLE OUTPUT:
CAUsersShubham Desktop\Main.exe Enter number of temperatures to input 55 Number of temperatures must be in range 1 and 30 (in

FOR ANY HELP JUST DROP A COMMENT

Add a comment
Know the answer?
Add Answer to:
You can vary it as long as the fahr and cels temperatures line up vertically and everything is clearly labeled. This program involves inputting a set of Fahrenheit temperatures and performing a set...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • General overview This program will convert a set of temperatures from Fahrenheit to Celsius and Kelvin....

    General overview This program will convert a set of temperatures from Fahrenheit to Celsius and Kelvin. Your program will be reading in three double values. The first values are starting and ending temperatures. The third value is the increment value. There is no prompt for the input. There is an error message that can be displayed. This is discussed later. You need to display output for all of the values between the starting and ending values. First two values are...

  • In this project you will create a console C++ program that will have the user to...

    In this project you will create a console C++ program that will have the user to enter Celsius temperature readings for anywhere between 1 and 365 days and store them in a dynamically allocated array, then display a report showing both the Celsius and Fahrenheit temperatures for each day entered. This program will require the use of pointers and dynamic memory allocation. Getting and Storing User Input: For this you will ask the user how many days’ worth of temperature...

  • Can you help me to create this program, please? Prompt the user for the user for...

    Can you help me to create this program, please? Prompt the user for the user for a number of degrees in Fahrenheit as an int. That number should be passed to a function named ffocREFO. This function will do the necessary calculation to convert the passed temperature to degrees Celsius as a double. The function MUST have a void return type and have the following prototype: void ffccREF(double& celsius, int Faren); In your main, display both the entered temperature and...

  • Write a C++ program that prompts a user to enter a temperature in Fahrenheit as a...

    Write a C++ program that prompts a user to enter a temperature in Fahrenheit as a real number. After the temperature is entered display the temperature in Celsius. Your program will then prompt the user if they want to continue. If the character n or N is entered the program will stop; otherwise, the program will continue. After your program stops accepting temperatures display the average of all the temperatures entered in both Fahrenheit and Celsius. Be sure to use...

  • Write a program in C++ that gives the temperature of earth at a depth. It must...

    Write a program in C++ that gives the temperature of earth at a depth. It must be in C++ and follow the information below: Problem description Write a program to take a depth in kilometers inside the earth as input data; calculate and display the temperature at this depth in both degrees Celsius and degree Fahrenheit. The formulas are: Celsius temperature at depth in km: celsius = 10 x depth(km) + 20 Convert celsius to fahrenheit: fahrenheit = 1.8 x...

  • You must write a C program that prompts the user for two numbers (no command line...

    You must write a C program that prompts the user for two numbers (no command line input) and multiplies them together using “a la russe” multiplication. The program must display your banner logo as part of a prompt to the user. The valid range of values is 0 to 6000. You may assume that the user will always enter numerical decimal format values. Your program should check this numerical range (including checking for negative numbers) and reprompt the user for...

  • C++ optional exercise. You are going to convert temperatures in this program. You will give the...

    C++ optional exercise. You are going to convert temperatures in this program. You will give the user the choice of converting Fahrenheit to Celsius or Celsius to Fahrenheit. With the correct answer you will also display the number entered. The user should have the option to convert as many temperatures as they want. Use functions and a menu (also a function) and, assume they will convert at least one temperature. When finished upload and submit the zipped project. the formulas...

  • This program will take the user's input as a temperature in degrees Fahrenheit. The user will...

    This program will take the user's input as a temperature in degrees Fahrenheit. The user will then click a radio button indicating whether a table of temperatures, starting with the entered value, will be displayed in increments of 5 degrees F or 10 degrees F. When a submit button is clicked your code will display a HTML table of temperature values. The first column will be temperatures in degrees Fahrenheit, given in increments of 5 or 10 degrees F, depending...

  • C++ requirements All values must be read in as type double and all calculations need to...

    C++ requirements All values must be read in as type double and all calculations need to be done using type double. For part 2 you MUST have at least 4 functions, including main. The main function will be the driver of the program. It needs to either do the processing or delegate the work to other functions. Failure to follow the C++ requirements could reduce the points received from passing the tests. General overview This program will convert a set...

  • CIST 1305 – Program Design and Development Chapter 4 Assignment #7 [Decisions/If Statements & Loops] (50...

    CIST 1305 – Program Design and Development Chapter 4 Assignment #7 [Decisions/If Statements & Loops] (50 Points) Please do the following exercises: Pastoral College is a small college in the Midwest. Design the pseudo-code for a program that accepts a student name, major field of study, and grade point average. Display a student’s data with the message “Dean’s list” if the student’s grade point average is above 3.5, “Academic probation” if the grade point average is below 2.0, and no...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT