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 element can be changed using the Print pane? Check all that apply.
Ronch [10]

Answer:

B

C

D

E

Explanation:

5 0
3 years ago
Read 2 more answers
Which of the following changes would be LEAST LIKELY lead to economic growth in a country?
Charra [1.4K]

Answer:

A. declines in labor productivity

Explanation:

6 0
3 years ago
Harry is undertaking a digital photography course as the college and wants to
Ludmilka [50]

C. Unconventionally yes it will break down the system potentially causing a virus

4 0
2 years ago
Rules used in naming variables in object oriented programming​
schepotkina [342]

Answer:

Explanation: Name your variables based on the terms of the subject area, so that the variable name clearly describes its purpose.

4 0
2 years ago
Attackers have recently launched several attacks against servers in your organization’s DMZ. You are tasked with identifying a s
kari74 [83]

Answer:

Option B is correct.

Explanation:

Well into the DMZ corporation of the user, intruders have currently conducted numerous attempts toward networks. He is associated with finding any response which would provide the greatest opportunity in the future to avoid such threats.  

The in-band IPS becomes the better approach for the required choices. Traffic moves via the IPS, as well as it has a better probability of avoiding inner processes through entering invasion.

4 0
3 years ago
Other questions:
  • Background Susan finished work on system architecture issues, and her system design specification was approved. Now she is ready
    15·1 answer
  • Side mirror using convex mirror or concave mirror?​
    5·2 answers
  • Jessica finds out that the government introduced a new trade policy that will increase import tariffs. She calls for a meeting o
    15·1 answer
  • 4. An advantage presented by straight-in spaces is that
    12·1 answer
  • Your company runs several databases on a single MySQL instance. They need to take backups of a specific database at regular inte
    12·1 answer
  • Write a Java program that has a static method named range that takes an array of integers as a parameter and returns the range o
    10·1 answer
  • Eric would like to have a callout text box that makes it look as if the character in an image is speaking. Which object should h
    12·2 answers
  • 9.11: Array Expander
    15·1 answer
  • How can i find these services
    10·1 answer
  • 2. Which one of the following is the purpose of relating tables in a database?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!