// readwrite.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<ctime>
using namespace std;
int num=0;
int a[5];
void producer()
{
srand((unsigned)time(0));
a[num]=rand();
cout<<"the producer put "<< a[num] <<"into the buffer"<<endl;
}
void consumer()
{
cout << "The consumer got " << a[num] << " from the buffer." << endl;
num++;
}
int _tmain(int argc, _TCHAR* argv[])
{
for (int i=0; i<5; i++)
{
producer();
consumer();
num++;
}
system("pause");
return 0;
}
//
#include "stdafx.h"
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<ctime>
using namespace std;
int num=0;
int a[5];
void producer()
{
srand((unsigned)time(0));
a[num]=rand();
cout<<"the producer put "<< a[num] <<"into the buffer"<<endl;
}
void consumer()
{
cout << "The consumer got " << a[num] << " from the buffer." << endl;
num++;
}
int _tmain(int argc, _TCHAR* argv[])
{
for (int i=0; i<5; i++)
{
producer();
consumer();
num++;
}
system("pause");
return 0;
}
Dear Readers if you have any query/question feel free to ask me via comment box given below. Also Follow us on social media site and share that post with your friends. - See more at: http://onlinecomputercafe.blogspot.com
useful tutorial keep it up...
EmoticonEmoticon