// I want to make a program having Queue class where message class instances are being used as messages. Later I want to use another class exchange that takes the messages and distribute to the Queue according to messageID.
if message id is "111" the Queue named Q11 should be created and message with ID-111 routed to this queue. Please HELP! am I using the right concept of friend's classes. Suggest please.....
#include "stdafx.h"
#include<iostream>
#include<stdlib.h>
using namespace System;
using namespace System::Collections::Generic;
using namespace System::Linq;
int someSize=2000;
# define SIZE 20
class message
{
int MsgId;
friend class queue;
public:
message();
message(int Id);
int getMessageId();
viod setMessageId(int id);
};
message::message(int Id)
{
MsgId=Id;
}
int message::getMessageId()
{
return MsgId;
}
void message::setMessageId(int id)
{
MsgId=id;
}
class queue
{
message aMsg[SIZE];
int front;
int rear;
public:
queue();
void insertMessage(message i);
message removeMessage();
bool isempty();
bool isfull();
void Displayitem();
};
queue::queue()
{
front=0;
rear=0;
}
void queue::insertMessage(int i)
{
if(isfull())
{
Console::WriteLine("******Queue is FULL !!!No insertion allowed further.******");
return;
}
aMsg[rear].MsgId = i ;
rear++;
}
int queue::removeMessage()
{
if(isempty())
{
return -1;
}
return(aMsg[front++].MsgId);
}
bool queue::isempty()
{
return(front == rear);
}
bool queue::isfull()
{
return(rear == SIZE);
}
//void queue::Displayitem()
//{
// if(isempty())
// Console::WriteLine("****Empty*****");
// else
// for(int i=front; i!=rear; i++)
// Console::WriteLine("the queue is having item {0}", aMsg[i]);
// }
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
queue q;
return 0;
}