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
__ is/are the amount of blank space between lines of text in a paragraph
Natali [406]
Indents? Double Space? one of those
5 0
3 years ago
Read 2 more answers
What are smart mobile devices
Nezavi [6.7K]

portable computing tool

7 0
3 years ago
Identify a major drawback of browsing web pages on mobile devices.
Pavlova-9 [17]
It was way too much of a drawback
5 0
3 years ago
Consider a classful IPv4 address 200.200.200.200? What is its implied subnet mask? If we take the same address and append the CI
topjm [15]

Answer:

a. 255.255.255.0 (class C)

b. 255.255.255.224

Explanation:

Here, we want to give the implied subnet mask of the given classful IPV4 address

We proceed as follows;

Given IPv4 address: 200.200.200.200

Classes

Class A : 0.0.0.0 to 127.255.255.255

Class B: 128.0.0.0 to 191.255.255.255

Class C: 192.0.0.0 to 223.255.255.255

Class D: 224.0.0.0 to 239.255.255.255

so 200.200.200.200 belongs to Class C and it's subnet mask is 255.255.255.0

In CIDR(Classless Inter Domain Routing)

subnet /27 bits means 27 1s and 5 0s. so subnet

i.e 11111111.11111111.11111111.11100000 which in dotted decimal format is 255.255.255.224 .

4 0
3 years ago
A ________ is a virus that is triggered on a certain date.
marysya [2.9K]
A time bomb virus is a virus that is triggered on a certain date. It is a malicious program that is designed to release virus unto a system. Once the time has arrived, it will automatically start working what it is programmed to do since any virus could do anything depending on what it is designed to do.
8 0
3 years ago
Other questions:
  • Given a scanner reference variable named input that has been associated with an input source consisting of a sequence of integer
    14·2 answers
  • The statement ____ declares intList to be a vector and the component type to be int
    8·1 answer
  • What is the standard unit used to measure mass?​
    9·1 answer
  • Assessment
    12·1 answer
  • What is a complier in computers
    9·2 answers
  • When planning your App what difficulties did come across and why?
    5·2 answers
  • Project light with a system of lenses used for projecting slides or film into a screen.
    5·1 answer
  • The economic importance of computer viruses​
    14·2 answers
  • Write a program that first reads a list of 5 integers from input. Then, read another value from the input, and output all intege
    5·2 answers
  • If you give someone ______ to your device, they can control it through another phone or computer.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!