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

Objectives Apply structured and modular design principles to write programs that

ID: 655020 • Letter: O

Question

Objectives

Apply structured and modular design principles to write programs that meet written specifications and requirements.

Develop a pseudo-code design using appropriate program structure (sequence, selection, repetition and nesting) to solve a given programming problem.

Use appropriate selection and repetition statements to implement the design.

Create user-defined functions to implement a modular design.

Use appropriate parameter passing mechanisms for passing data into and getting data back from functions.

Use ostream and iomanip formatting manipulators to display tabulated data.

Design and implement a menu-driven interface.

Problem Description

This program is to give the user the option of converting a set of temperatures either from Celsius to Fahrenheit (C to F) or vice versa, from Fahrenheit to Celsius (F to C), or to quit the program. If the user selects either C to F or F to C, the program will prompt the user to enter three integer values, a starting temperature, an ending temperature, and an increment. After these values have been entered the program will display a table of equivalent C and F (or F and C) temperatures, from the starting temperature to the ending temperature and incrementing by the increment value each row.

The table must meet all of the following criteria:

The table's column headings should display the degree symbol, e.g.,

Explanation / Answer

#include <iostream>

#include<iomanip.h>

using namespace std;

float celsius;

float fahrenheit;

void convertF()

{

            celsius = ((fahrenheit - 32) * 5) / 9;

}

void convertC()

{

            fahrenheit = (((celsius * 9) / 5) + 32);

}

int main()

{

            unsigned short choice;

            cout << "Welcome to the temperature converter. ";

            cout << "Please type '1' for Celsius to Fahrenheit conversion." << endl;

            cout << "Or, type '2' for Fahrenheit to Celsius conversion." << endl;

            cin >> choice;

            switch (choice)

{

            case 1:

            cout << "Please enter your temperature in Celsius. ";

            cin >> celsius;

            convertC();

            cout << " ";

            cout << "Computing... ";

            cout << "The temperature in Fahrenheit is " << fahrenheit << ". ";

            cout << "Press any key to terminate the program." << endl;

            cout << endl;

            break;

            case 2:

            cout << "Please enter your temperature in Fahrenheit. ";

            cin >> fahrenheit;

            convertF();

            cout << " ";

            cout << "Computing... ";

            cout << "The temperature in Celsius is " << celsius << ". ";

            cout << "Press any key to terminate the program." << endl;

            cout << endl;

            break;

            default:

            cout << "That is not an option!" << endl;

            cout << "Please close the program and try again." << endl;

            break;

}

            return 0;

}