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
C was created to work with UNIX systems in1972, and would be the foundation for several other programming languages, including j
san4es73 [151]

Answer:

True

Explanation:

C language is developed with the help of UNIX in 1972. It was developed by Denis Ritchie at Bell labs. many languages are developed with the help of C Platform. Such as C++, C sharp and Java.

7 0
3 years ago
Which type of software is created and updated by a worldwide community of programmers and is available for​ free?
Ede4ka [16]
Open source is created and updated by a worldwide community of programmers and is available for​ free. Many students are in luck, as they can easily study publicly accessible codes and have a possibility to make better software. It also has lots of advantages, such as getting <span>high-quality results when the source code is passed around, tested and fixed.The most important thing - it<span> is a valuable learning opportunity for programmers and opportunity to improve their skills.</span></span>
5 0
3 years ago
A _______________ hypervisor improves the performance of virtualization by removing the underlying operating system.
elena-14-01-66 [18.8K]
Type 1 hypervisor. also referred to as a
Bare-metal hypervisor
6 0
3 years ago
Why are graphs and charts important to analyze data?
vladimir2022 [97]

Answer:

Graphs and chart provide the GUI representation they provide the analysis in form of summary that is easy to understand and they provide good comparision.

Explanation:

Summary

Comparision

Quick to understand

6 0
2 years ago
The ub-04 form would most likely be used in what setting?
wlad13 [49]

The UB-04 form would most likely be used in the following setting:

  • Hospitals
  • Hospices
  • General health centers such as rural clinics.
  • Rehab facilities

The uniform bill (UB-04) form is also referred to as CMS-1450 and it is a standard claim form that is used for billing and submitting Medicare Part A outpatient or inpatient health claims to Medicare fiscal intermediaries such as insurance companies, medical providers (hospitals), etc.

Also, the uniform bill (UB-04) form was introduced by the National Uniform Billing Committee (NUBC) in 2004, so as to replace the UB-92 form.

Generally, UB-92 form is a paper claim form that is typically used for laboratory, radiology, surgery, etc. Thus, the UB-04 form would most likely be used in the following setting:

  • Hospitals
  • Hospices
  • General health centers such as rural clinics.
  • Rehab facilities

Read more on UB-04 form here: brainly.com/question/4437165

4 0
2 years ago
Other questions:
  • Use the script below as a starting point to create a Rectangle class. Your rectangle class must have the following methods;A con
    12·1 answer
  • If you delete a sent message on gmail does the person still get it
    14·1 answer
  • The _ are the devices that allow a computer system to communicate and interact with the outside world as well as store informati
    11·1 answer
  • We have written a method called sum with an int[] parameter nums. We want our sum method to compute the sum of nums, but our cod
    5·1 answer
  • Hello people, I was wandering if I could get some people to complete this questionnaire for my business course. It would be very
    5·1 answer
  • Give five examples of top level domain​
    10·2 answers
  • State whether True / False:<br>The pause option stops the recording temporarily.*<br>True<br>False​
    9·1 answer
  • When creating an HTML document, what do we use to set aside space for content?
    14·1 answer
  • Do network packets take the shortest route?
    14·2 answers
  • A vlan ________.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!