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
CODE IN C++ THANK YOU Write a program that simulates a microprocessor with eight pins Each...