1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Natali [406]
3 years ago
15

Write a program in C++ or C that includes two different enumeration types and has a significant number of operations using the e

numeration types. Also write the same program using only integer variables. Compare the readability and predict the reliability differences between the two programs.
Computers and Technology
1 answer:
CaHeK987 [17]3 years ago
3 0

Answer:

Enum is a value type data type which is used to declare a list of named integer constants and can be defined using the enum keyword inside a class, or structure. The enum is used to give a name to each constant so that the constant integer can be called using its name. In most case enum provides a better readability than showing some integer values.

Explanation:

Using enum:

#include<iostream>

#include<string>

#include<stdlib.h>

using namespace std;

enum TempLevel { Low = 15, Medium = 30, High = 45 };

enum TempConverter{ Celsius = 1, Fahrenheit };

void TempLevel(int convertedValue);

int main()

{

while (true)

{

TempConverter Converter;

int userInput, choice, convertedValue;

cout << "----------------------------------" << endl;

cout << "Please enter the choice : " << endl;

cout << "Enter " << Celsius << " -- convert from Celsius to Fahrenheit" << endl;

cout << "Enter " << Fahrenheit << " -- convert from Fahrenheit to Celsius" << endl;

cout << "Choice :";

cin >> choice;

switch (choice)

{

case Celsius:

cout << "Please enter the Celsius value : ";

cin >> userInput;

convertedValue = (userInput * 9 / 5) + 32;

cout << "Fahrenheit is " << convertedValue << endl;

TempLevel(userInput);

break;

case Fahrenheit:

cout << "Please enter the Fahrenheit value : ";

cin >> userInput;

convertedValue = (userInput - 32) * 5 / 9;

cout << "Celsius is " << convertedValue << endl;

TempLevel(convertedValue);

break;

default:

cout << "Invalid Option" << endl;

exit(0);

break;

}

}

}

void TempLevel(int convertedValue)

{

string result;

convertedValue <= Low ? result = "Temperature is cold" : "";

convertedValue > Low && convertedValue <= Medium ? result = "Temperature is comfort" : "";

convertedValue > Medium && convertedValue <= High ? result = "Temperature is hot" : "";

convertedValue > High ? result = "Temperature is very hot" : "";

cout << result << endl;

}

Using integer datatype:

#include <iostream>

#include<string>

#include<stdlib.h>

using namespace std;

void TempLevel(int convertedValue);

int main()

{

while (true)

{

int userInput, choice, convertedValue;

cout << "----------------------------------" << endl;

cout << "Please enter the choice : " << endl;

cout << "Enter 1 -- convert from Celsius to Fahrenheit" << endl;

cout << "Enter 2 -- convert from Fahrenheit to Celsius" << endl;

cout << "Choice :";

cin >> choice;

switch (choice)

{

case 1:

cout << "Please enter the Celsius value : ";

cin >> userInput;

convertedValue = (userInput * 9 / 5) + 32;

cout << "Fahrenheit is " << convertedValue << endl;

TempLevel(userInput);

break;

case 2:

cout << "Please enter the Fahrenheit value : ";

cin >> userInput;

convertedValue = (userInput - 32) * 5 / 9;

cout << "Celsius is " << convertedValue << endl;

TempLevel(convertedValue);

break;

default:

cout << "Invalid Option" << endl;

exit(0);

break;

}

}

}

void TempLevel(int convertedValue)

{

string result;

convertedValue <= 15 ? result = "Temperature is cold" : "";

convertedValue > 15 && convertedValue <= 30 ? result = "Temperature is comfort" : "";

convertedValue > 30 && convertedValue <= 45 ? result = "Temperature is hot" : "";

convertedValue > 45 ? result = "Temperature is very hot" : "";

cout << result << endl;

}

You might be interested in
Which of the following is considered both an input and output peripheral? Keyboard, Microphone, Speaker, Touchscreen monitor
Aleks04 [339]
Touchscreen monitor.
6 0
3 years ago
Read 2 more answers
Which layer includes the physical transmission medium (cables or wireless media) that any network must use to send and receive t
Yuliya22 [10]

Answer:

The correct answer to the following question will be "Physical Layer".

Explanation:

  • The lowest layer of the OSI reference model is the physical layer. It's in charge of having to send bits from one desktop to the next.
  • This layer isn't acquainted with the interpretation of the parts and is concerned with setting up a physical wireless connection and sending and receiving signals.
  • This layer relies on aspects of the hardware, such as wires, transmitters, and network interface tokens.

Therefore, it will be the right answer.

4 0
3 years ago
. What process skill would a scientist use to find the length of a line
Brilliant_brown [7]

Answer:

Explanation:

A ruler

;););););););););););););););)

7 0
3 years ago
How to reload ingenuity when a pulsating blue thing is there
Hatshy [7]
Todo is very important
4 0
3 years ago
A _____ miniature battery operated transmitter that can be propelled through a non-metallic pipe or purpose of locating
Anna11 [10]
I think it is the model ET-2. Not quite sure.
7 0
3 years ago
Other questions:
  • What component has the job of managing data as it flows into and out of the places it needs to go?
    11·2 answers
  • Define the following terms:<br><br> - pigment<br> - vehicle<br> - binder<br><br> plz help
    12·2 answers
  • Does any one play sniper clash 3d ??? ​
    9·2 answers
  • Which are factors that go into a project plan? choose four answers
    14·1 answer
  • Sally thought of adding a new paragraph after the
    6·1 answer
  • What is a feature of Print Preview? Fit to Document Fit to Margin Fit to Page Fit to Size
    5·2 answers
  • I have a very quick question. So im applying for Early college and i need some future educational goals and maybe im just thinki
    6·1 answer
  • Please hurry
    15·2 answers
  • Explain the concept of conditional formatting​
    9·1 answer
  • The international system of units is very important to our worldwide science community because it is easier for scientists to sh
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!