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
Nesterboy [21]
3 years ago
9

Create a program in c/c++ which accepts user input of a decimal number in the range of 1 -100. Each binary bit of this number wi

ll represent the ON/OFF state of a toggle switch.
Computers and Technology
1 answer:
kirill115 [55]3 years ago
8 0

Answer:

// here is code in C++.

#include <bits/stdc++.h>

using namespace std;

void switch_fun(int input)

{

//array to store binary of input number

   int bin[7];

   // convert the number into binary

   for(int i=0; input>0; i++)

       {

           bin[i]=input%2;

           input= input/2;

       }

   // print the switch number and their status

   cout<<"Switch number:\t 1\t 2\t 3\t 4\t 5\t 6\t 7 \n";

   cout<<"status:      ";

   for(int j=6;j>=0;j--)

   {

   // if bit is 1 print "ON" else print "OFF"

       if(bin[j]==1)

           cout<<"\t ON";

       else

           cout<<"\t OFF";

   }

}

int main()

{

   int n;

   cout<<"enter the number between 1-100 only:");

   // read a number in decimal

   cin>>n

   // validate the input

   while(n<1 ||n>100)

   {

     cout<<"wrong input!! Input must be in between 1-100:"<<endl;

     cout<<"enter the number again :";

     cin>>n;

   }

// call the function with input parameter

  switch_fun(n);

return 0;

}

Explanation:

Read a decimal number from user. If the number is not between 1 to 100 the it will again ask user to enter the number until the input is in between 1-100.Then it will call the fun() with parameter n. First it will convert the decimal to binary array of size 7.Then print the status of switch.If bit is 1 then print "ON" else it will print "OFF".

Output:

enter the number between 1-100 only:-5

wrong input!! Input must be in between 1-100:

enter the number again :125

wrong input!! Input must be in between 1-100:

enter the number again :45

Switch number:   1       2       3       4       5       6       7

Status:          OFF     ON      OFF     ON      ON      OFF     ON

You might be interested in
To enable grammar correction in powerpoint, you must first enable office ____ services.
sesenic [268]

Answer:

Grammar

Explanation:

8 0
1 year ago
Read 2 more answers
An experimenter discovers that the time for people to detect a string of letters on a computer screen is 400 milliseconds, and t
nadya68 [22]

Answer:

The correct answer to the following question will be Option D (Subtractive method ).

Explanation:

  • This approach essentially requests a participant to construct two activities that are already in almost every way similar, except for a mental process that is assumed to also be included in any of the activities although omitted in another.
  • This method will be much more valuable when deciding the period for phonemic awareness, despite text-string identification.

The other three options are not related to the given scenario. So that Option D is the right answer.

3 0
2 years ago
The assignment operator has left-to-right-to-left associativity, which means that the value of the expression to the left of the
postnew [5]

Answer:

The given statement is false statement.

Explanation .

  • The assignment is assigning the value to the variable or we can say that it will also be used to initialize the variable The "=" is the symbol of the assignment operator.
  • For example

        int r=90, The value of variable 90 is assigned to 90.

  • The associativity, of assignment, is always right to left which means The right-hand side is firstly evaluated then it will be assigned in left-hand side variable or expression.  

4 0
3 years ago
Kelly is a college sophomore majoring in computer science. She is interested in gaining exposure to the most useful and current
Nonamiya [84]

Answer:

The correct answer for the given question is an option(b) i.e java.

Explanation:

Java is an object oriented programming language that is mostly used for the creating the websites.Java is most secure and reliable programming language than the other programming language.

C is a programming language but it is not object oriented programming language thats why this option is incorrect.

Visual basic is a Programming language it is also used to create a web page but it is not commonly used to create a web page  thats why this option is incorrect.

The scheme is not used to create a web page  thats why this option is also incorrect.

7 0
3 years ago
Write a program that:
Gemiola [76]

Answer:

num1 = int(input("Enter number 1: "))

num2 = int(input("Enter number 2: "))

choice = input("Do you want to multiply them?: ")

if choice.capitalize() == "Yes":

   print(num1 * num2)

else:

   print("Peace out.")

Explanation:

Gg ez.

(I wrote the it in python because I don't know what language you want it in. Next time, say what language you want.)

7 0
2 years ago
Other questions:
  • How many days has trump been a president
    11·2 answers
  • Explain the difference between using the int type and the double type for numbers.
    11·1 answer
  • A ____ is a theoretical model of computation that includes a (conceptual) tape extending infinitely in both directions.
    13·1 answer
  • Type dig www.example A in order to get the IP address of www.example. What’s the TTL of the A record returned in the response? W
    9·1 answer
  • RAM is usually a. secondary storage b. a static type of memory, used for permanent storage c. a volatile type of memory, used fo
    14·1 answer
  • A technician wants to limit access to a group of folders and is using Group Policy to prevent the users in the sales department
    9·1 answer
  • Python
    6·1 answer
  • Need help asap please
    15·1 answer
  • Which type of inventory control is expensive but helps keep inventory especially secure? A. RFID tags B. Barcodes C. Visual merc
    7·1 answer
  • Where else can the computer send the results of processing other than to output​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!