Hi guys i'm new to the forum and i currently have a problem with my program. I'm confused about how to make my program work. The code below shows what i have done up to this stage. [input]Whenever the user input 0 0 the led pattern remains unchange. when 0 1 is input, the led pattern is rotated right by 1 led position. when 1 0 is input the led pattern is rotated left by 1 led position. when 1 1 is input. only the 5th led from the left is lighted up.[/input]
Can anyone please help me? Please tell me if i missed out on any info.
Code:
#include <iostream>
using namespace std;
class Switch
{
protected:
int sw1, sw2;
public:
void setSwitch(int a,int b);
void getSwitch();
};
void Switch::setSwitch(int a,int b)
{
sw1 = a;
sw2 = b;
}
void Switch::getSwitch()
{
cout<<"Enter logic states of sw1 and sw0, seperated by a space:";
cin>>sw1;
switch(sw1){
case 00:cout<<"Enter logic states of sw1 and sw0, seperated by a space:"<<endl;
cout<<"Case1"<<endl;
break;
case 01:cout<<"Enter logic states of sw1 and sw0, seperated by a space:"<<endl;
cout<<"Case2"<<endl;
break;
case 10:cout<<"Enter logic states of sw1 and sw0, seperated by a space:"<<endl;
cout<<"Case3"<<endl;
break;
case 11:cout<<"Enter logic states of sw1 and sw0, seperated by a space:"<<endl;
cout<<"Case4"<<endl;
break;
default: cout<<"Wrong Input"<<endl;
break;
}
}
class Led
{
protected:
int led[8];
public:
Led();
void showLed();
void LED3();
};
Led::Led()
{
for(int i=0;i<8;i++)
led[i]=0;
led[7]=1;
}
void Led::showLed()
{
int i;
cout<<"Led Pattern: ";
for (i=0;i<8;i++)
cout<<" "<<led[i];
cout<<endl;
}
void Led::LED3()
{
int i;
cout<<"Led Pattern: ";
for(int i=0;i<8;i++)
cout<<" "<<led[i];
}
class Circuit : public Switch, public Led
{
public:
void showcircuit();
void rotateleft();
void rotateright();
};
void showcircuit();
void Circuit::rotateleft()
{
int b;
b=led[7];
led[7]=led[6];
led[6]=led[5];
led[5]=led[4];
led[4]=led[3];
led[3]=led[2];
led[2]=led[1];
led[1]=led[0];
led[0]=b;
int i;
cout<<"Led Pattern: ";
for (i=0;i<8;i++)
cout<<" "<<led[i];
cout<<endl;
}
void Circuit::rotateright()
{
int a;
a=led[0];
led[0]=led[1];
led[1]=led[2];
led[2]=led[3];
led[3]=led[4];
led[4]=led[5];
led[5]=led[6];
led[6]=led[7];
led[7]=a;
int i;
cout<<"Led Pattern: ";
for (i=0;i<8;i++)
cout<<" "<<led[i];
cout<<endl;
}
main()
{
Circuit Circuits;
Circuits.showLed();
Circuits.getSwitch();
Circuits.rotateright();
Circuits.rotateleft();
Circuits.LED3();
}