So, your "waching machine" is actually a washing machine!!!!!!!!
I think you want the code for your school project and not for microprocessor based application.
If this is the case, the following may help you:-
////////////////////////////////////////////////////
///////////////////WashingMachine.h///////////////////////////////////
#ifndef __WASHING_MACHINE__
#define __WASHING_MACHINE__
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
class WashingMachineContext;
class WashingMachine
{
public:
WashingMachine();
~WashingMachine();
void Process();
int GetRtxCounter() const {return iRtxCount;}
// Events
void Start();
void WashingDone();
void RinsingDone();
void SpinningDone();
void Fault();
void DiagnoseSuccess();
// Actions
void Print(const string& message);
private:
WashingMachineContext& GetContext();
WashingMachineContext *m_pContext;
int iRtxCount;
int iCounter;
};
#endif
/////////////////////////////////////////////////////
//////////////////////WashingMachine.cpp///////////////////////////////
#include <stdexcept>
#include <ObserverStd.h>
#include "WashingMachine.h"
#include "WashingMachineFsm.h"
#include <iostream>
using namespace std;
WashingMachine::WashingMachine()
{
m_pContext = new WashingMachineContext(*this);
m_pContext->SetObserver(fsm::ObserverStd::GetInstance());
m_pContext->EnterInitialState();
}
WashingMachine::~WashingMachine()
{
delete m_pContext;
}
WashingMachineContext& WashingMachine::GetContext()
{
if(m_pContext != NULL){
return *m_pContext;
} else {
throw std::runtime_error("context is not set");
}
}
void WashingMachine::Start()
{
GetContext().Start();
}
void WashingMachine::WashingDone()
{
GetContext().WashingDone();
}
void WashingMachine::RinsingDone()
{
GetContext().RinsingDone();
}
void WashingMachine::SpinningDone()
{
GetContext().SpinningDone();
}
void WashingMachine::Fault()
{
GetContext().Fault();
}
void WashingMachine:
iagnoseSuccess()
{
GetContext().DiagnoseSuccess();
}
void WashingMachine:
rint(const string& message)
{
cout << message << endl;
}
///////////////////////////////////////////////////////////
/////////////////////main.cpp//////////////////////////////////
#include <iostream>
#include <cstdlib>
#include <iostream>
#include "main.h"
#include "WashingMachine.h"
using namespace std;
int main(int, char **)
{
App app;
return app.Main();
}
App::App()
{
}
int App::Main()
{
cout << "WashingMachine" << endl;
try {
WashingMachine washingMachine;
cout << "WashingMachine has been created" << endl;
cout << "Send Start" << endl;
washingMachine.Start();
cout << "Send WashingDone" << endl;
washingMachine.WashingDone();
cout << "Send Fault" << endl;
washingMachine.Fault();
cout << "Send DiagnoseSuccess" << endl;
washingMachine.DiagnoseSuccess();
cout << "Send RinsingDone" << endl;
washingMachine.RinsingDone();
cout << "Send Fault" << endl;
washingMachine.Fault();
cout << "Send DiagnoseSuccess" << endl;
washingMachine.DiagnoseSuccess();
cout << "Send SpinningDone" << endl;
washingMachine.SpinningDone();
cout << "Done with events" << endl;
}
catch (std::exception& e)
{
std::cerr << "Exception: " << e.what() << "\n";
return -1;
}
cout << "WashingMachine should have been destroyed by this time" << endl;
return 0;
}
///////////////////////////////
This is for idea only.
you can see this site for more (xml files etc)
WashingMachine
If want a console based program, the class structure will give you idea.