Question

CODE IN C++

Write a program that simulates a microprocessor with eight pins Each pin is of enumerated type and serves a device from the sServicing USEB Camera On Servicing CAMERA ower On ower On SB On ervicing USB SB On Servicing USEB round On

THANK YOU

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

Note: If this is not the technique you are looking for, drop a comment stating the exact requirements, I’ll update as needed.

#include<iostream>

#include<stdlib.h>

#include<time.h>

using namespace std;

//defining an enumeration to represent the type of each pin

enum Type{

                GROUND=0,POWER=1,USB=2,AVAILABLE=3,CAMERA=4,AUDIO=5,KEYBOARD=6,MONITOR=7               

};

//method to simulate the pin interrupts

void simulate(){

                //defining an object of Type enum

                Type pin;

                //looping infinitely

                while(true){

                                //generating a random number between 0 and 7

                                int rnd_num=rand()%8;

                                //casting integer to enum and assigning to the type

                                pin=static_cast<Type>(rnd_num);

                                //switching the value of pin

                                switch(pin){

                                               //checking for each case

                                               case GROUND:

                                                               //displaying message to let the user know which signal is set.

                                                               cout<<"Ground on"<<endl;

                                                               break;

                                               case POWER:

                                                                cout<<"Power on"<<endl;

                                                               break;

                                               case USB:

                                                               cout<<"USB on"<<endl;

                                                               cout<<"Servicing USB"<<endl;

                                                               break;

                                               case AVAILABLE:

                                                               cout<<"Available on"<<endl;

                                                               break;

                                               case CAMERA:

                                                               cout<<"Camera on"<<endl;

                                                               cout<<"Servicing CAMERA"<<endl;

                                                               break;

                                               case AUDIO:

                                                               cout<<"Audio on"<<endl;

                                                               cout<<"Servicing AUDIO"<<endl;

                                                               break;

                                               case KEYBOARD:

                                                               cout<<"Keyboard on"<<endl;

                                                               cout<<"Servicing KEYBOARD"<<endl;

                                                               break;

                                               case MONITOR:

                                                               cout<<"Monitor on"<<endl;

                                                               cout<<"Servicing MONITOR"<<endl;

                                                               break;                                  

                                }

                }

}

int main(){

                //seeding random number generator

                srand(time(NULL));

                //simulating and looping forever

                simulate();

                return 0;

}

/*OUTPUT (infinite loop)*/

Keyboard on

Servicing KEYBOARD

Camera on

Servicing CAMERA

USB on

Servicing USB

Ground on

Available on

Audio on

Servicing AUDIO

Keyboard on

Servicing KEYBOARD

USB on

Servicing USB

USB on

Servicing USB

Ground on

Camera on

Servicing CAMERA

Monitor on

Servicing MONITOR

Audio on

Servicing AUDIO

USB on

Servicing USB

USB on

Servicing USB

Ground on

Add a comment
Know the answer?
Add Answer to:
CODE IN C++ THANK YOU Write a program that simulates a microprocessor with eight pins Each...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT