Question #59538

Two production facilities create devices, each device is tested at the same location. The devices arrive at random times and are dealt with in order of their arrival. The testing facility then sorts them into collections of three types: Grade A, (top 10%), Grade B(next 60%), Grade C(lowest 30%). Use a uniform distribution to determine the quality of any particular device. Each of these are then sorted into sales bundles (lists), Grade A under their own label, Grade B are sold under a different, label and the last grade are sold as a discount brand. Create a simulation of this process.
1

Expert's answer

2016-05-20T09:06:03-0400

Answer on Question #59538, Programming & Computer Science / C++

Problem.

Two production facilities create devices, each device is tested at the same location. The devices arrive at random times and are dealt with in order of their arrival. The testing facility then sorts them into collections of three types: Grade A, (top 10%10\% ), Grade B(next 60%60\% ), Grade C(lowest 30%30\% ). Use a uniform distribution to determine the quality of any particular device. Each of these are then sorted into sales bundles (lists), Grade A under their own label, Grade B are sold under a different, label and the last grade are sold as a discount brand. Create a simulation of this process.

Solution.

#include<iostream>
#include <cstdlib>
#include <ctime>
#define TIME 1000
using namespace std;
int main() {
    int line1 = 0;
    int line2 = 0;
    int currTime = 0;
    int itemA = 0;
    int itemB = 0;
    int itemC = 0;
    srand(time(NULL));
    while (TIME >= line1 && TIME >= line2) {
        // Check which line should produce new item
        if (line1 == currTime) {
            line1 += rand() % 10 + 1;
            int item = rand() % 10 + 1; // Simulation of item type
            if (item <= 1) {
                cout << "Time: " << line1 << " Item: A" << endl;
                itemA++;
            } else if (item >= 2 && item <= 7) {
                cout << "Time: " << line1 << " Item: B" << endl;
                itemB++;
            } else {
                cout << "Time: " << line1 << " Item: C" << endl;
                itemC++;
            }
        }
        if (line2 == currTime) {
            line2 += rand() % 10 + 1;
            int item = rand() % 10 + 1; // Simulation of item type
            if (item <= 1) {
                cout << "Time: " << line2 << " Item: A" << endl;
                itemA++;
            } else if (item >= 2 && item <= 7) {
                cout << "Time: " << line2 << " Item: B" << endl;
                itemB++;
            } else {
                cout << "Time: " << line2 << " Item: C" << endl;
                itemC++;
            }
        }
        // Determine time when next event happens
        if (line1 < line2) {
            currTime = line1;
        } else {
            currTime = line2;
        }
    }
    cout << "A: " << itemA << " B: " << itemB << " C: " << itemC << endl;
}


https://www.AssignmentExpert.com

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS