I must write code for my classes which simulates multi-layers production line. But I don't even know how to check if it's good. Can anyone take a look at my code, please? First machine works in random frequency putting integer into first queue. Then, second machine puts out this number at freq2, adding 100 and so on...
#include <stdio.h>
#include <iostream>
#include <queue>
#include <time.h>
#include <cstdlib>
using namespace std;
int main()
{
queue<int> k1;
queue<int> k2;
queue<int> k3;
int max1=5;
int max2=10;
int max3=2;
int freq1=5;
int freq2=3;
int freq3=4;
int loop=0;
float interwal=0.5;
while (1)
{
loop++;
int tmp=rand()%100;
int tmp2=rand()%5+1;
if (loop%tmp2==0 && k1.size()<max1) k1.push(tmp);
if (k1.empty()==false && k2.size()<max2 && loop%freq1==0)
{
k2.push(k1.front()+100);
k1.pop();
}
if (k2.empty()==false && k3.size()<max3 && loop%freq2==0)
{
k3.push(k2.front()*100);
k2.pop();
}
if (k3.empty()==false && loop%freq3==0)
{
cout<<k3.front()<<endl;
k3.pop();
}
clock_t ticks, ticks2;
ticks=clock();
ticks2=ticks;
while((ticks2/(float)CLOCKS_PER_SEC-ticks/(float)CLOCKS_PER_SEC)<interwal)
ticks2=clock();
}
}