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
In the scenario below, select the evaluation factor that is most important.
jasenka [17]

Answer:

A. Connectivity

Explanation:

I just answered this question.

4 0
2 years ago
There is a simple method for constructing a magic square for any odd value of n:
DaniilM [7]

Answer:

See Explaination

Explanation:

class MagicSquare():

def __init__(self,side):

self.side=side

self.two_dimension=[]

for row in range(1,side+1):

row_line=[]

for col in range(1,side+1):

row_line.append(0)

self.two_dimension.append(row_line)

def display(self):

row=0

col=int((self.side-1)/2)

for i in range(1,self.side**2+1):

self.two_dimension[row][col]=i

row-=1

col+=1

if row==-1:

row=self.side-1

if col==self.side:

col=0

if self.two_dimension[row][col]==0:

continue

else:

row+=1

if row==self.side:

row==0

for line in self.two_dimension:

for num in line:

print("{0:>3}".format(num),end=" ")

print()

def main():

for i in range(1,14,2):

square=MagicSquare(i)

square.display()

print("----------------------------------------------------")

if __name__ == '__main__':

main()

3 0
3 years ago
In what domain electrica energy is the most use
amm1812

Answer:the main signal bearing entities are voltage and their current in circuit environments.

Explanation:

5 0
2 years ago
Suppose an 80286 microprocessor is in protected mode. How it is switched back
iris [78.8K]

Answer:

  hardware-initiated reset

Explanation:

Once in protected mode, the 80286 is designed to remain there until it is reset by hardware.

__

External hardware can be designed so that software can cause such a reset. In the 1984 PC/AT, such hardware combined with code in the BIOS allowed real mode re-entry and returned execution control to the program that caused the reset.

5 0
3 years ago
Which of the following experiences is considered a simulation?
Butoxors [25]

Answer:

c

Explanation:

3 0
3 years ago
Other questions:
  • What procedures are involved in saving a file for the first time?
    10·2 answers
  • Which of these browsers was the first widely adopted?
    12·1 answer
  • Consider a multidimensional array A stored in row-major order with 22 rows and 6 columns whose subscripts start at 0. If each el
    8·1 answer
  • A USB device used to transfer photos from the memory card to a hard drive is called a _____.
    12·1 answer
  • Universal Containers uses a custom object within the product development team. Product development, executives, and System Admin
    11·1 answer
  • In 3-5 sentences describe whether or not files should be deleted from your computer explain your answer
    12·1 answer
  • Which tool can be used to increase the space between a bullet point or a number and text?
    11·2 answers
  • What is the scope of each variable?
    11·2 answers
  • A computer on a network that is not the server​
    15·1 answer
  • Mille gets a text from her friend asking if she wants to come over. It seems like a bit of a hassle to go to her friend's house,
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!