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
What are the features of a computer speaker​
Aliun [14]
Some computer speakers have equalization features such as bass and treble controls. Bluetooth speakers can be connected with a computer by using an Aux jack and compatible adaptor. More sophisticated computer speakers can have a subwoofer unit, to enhance bass output.
Hope that helps....it on googIe
6 0
3 years ago
Clicking the _____ box completes an entry. cancel formula enter tab
DaniilM [7]
Enter tab would complete an entry. I hope that helped ya! 
4 0
3 years ago
Can someone please help me I need to turn this in my 3:00pm Eastern time
galben [10]

Answer:

1000000000

Explanation:

8 0
3 years ago
Which media device uses the characteristic continuous?
notka56 [123]
The media device that uses characteristics continuous is the Screen.
In Continous characteristic 
is where there is timing relationship between source and destination.
4 0
3 years ago
In Web design, What kind of tag is referred to as fixed ?<br>​
Tpy6a [65]

Answer:

Most HTML tags are fixed

Explanation:

There are various kind of technology one can use for designing web application. A web designer should know HTML, CSS and other basic building block of web development.

HTML meaning hypertext markup language is used to define the basic structure of a web page . HTML has tags which are used to declare the contents on the web page. The tags includes anchor(<a>), paragraph tag(<p>),header tag(<h1>).

CSS which is known as Cascading style sheet describes the presentation of the web pages.

Other tags in HTML includes <img>, <link>, <ul>  etc and generally this tags are HTML tags which are fixed for a particular kind of job . For example you can't use an image tag <img>   to enclose video instead you use a video tag <video> tag. The header tag <h1> cannot be represented like a paragrapgh tag<p> on the web page. The both of them serve specific purpose and are fixed.  

7 0
3 years ago
Other questions:
  • Describe the Say It, Cover It, Resay It method.
    14·2 answers
  • A file that contains program code is called a ____________.
    13·1 answer
  • When did the silver market drop sharply, hurting Bolivia's income?
    7·2 answers
  • Why is there a need to compare and align one's PECs of a successful entrepreneur?
    5·1 answer
  • Match the part of motherboard to its function
    15·1 answer
  • To access WordPad, Jill will click on Start, All Programs, Accessories, and WordPad. To access Notepad, Karl will click on Start
    5·1 answer
  • An administrator running a port scan wants to ensure that no processes are listening on port 23. What state should the port be i
    7·1 answer
  • Options to rotate cells in excel are available using the _____ button in the alignment group on the home tab.
    10·1 answer
  • Varun wants to start his own business. Suggest him at least four functions of an entrepreneur.
    8·2 answers
  • When you purchase donuts, they come in boxes of 12, so 24 donuts take 2 boxes. All donuts need to be in a box, so if you buy 13
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!