Computer Science
Write a program to control a set of 10 motors; the motors are operating under load balancing mechanism as
follows:
• Motors operate in pairs as follows: 1,10 then 2, 9 then 3,8 then 4,7 then 5,6 then repeat.
• The operating duration for each pair is 10,000 milliseconds.
• After each operating cycle, all motors must be OFF for 10,000 milliseconds then a new cycle starts.
• The operating sequence is running 24/7.
#include <iostream>
#include <windows.h>
using namespace std;
class MotorPair {
public:
int a, b;
MotorPair(int i, int j){
this->a = i;
this->b = j;
}
void run(){
cout<<"Motor "<<this->a<<" and "<<this->b<<" running.\n";
Sleep(10000);
}
};
int main(){
MotorPair A = MotorPair(1, 10), B = MotorPair(2, 9),
C = MotorPair(3, 8), D = MotorPair(4, 7), E = MotorPair(5, 6);
MotorPair motors[5] = {A, B, C, D, E};
while(true){
for(int i = 0; i <= 4; i++){
motors[i].run();
}
cout<<"All motors are currently off. Preparing a new cycle...\n";
Sleep(10000);
}
return 0;
}
Comments
Leave a comment