Question

A simulation of a factory production line is to be written in C++. There are 3...

A simulation of a factory production line is to be written in C++. There are 3 workplaces named station1, station2, station 3, where components of the widget are produced Station 1 needs the screwdriver to complete its part, and updates parts[0] of the parts list array. Station 2 needs both the screwdriver and saw to complete its part, and updates parts[1]. Station 3 needs the saw and hammer to construct its part, and updates parts[2]. For this problem, it is your job to efficiently utilize the mutexes (hammer, screwdriver, and saw) to correctly coordinate the production of the parts. Be aware that we must be careful to avoid deadlock and your solution should not reduce the problem to sequential execution. This program is due no later than 5:30 PM on 10-12-2020. No late submissions will be accepted. This program will carefully be examined for comments, efficiency, and accuracy. Name the program factory.cpp and place it in your pgm directory.

Input: From command line:

The input for this program will be the total number of parts each thread must produce. We are assuming that each thread will produce the same number of parts.

./a.out <number>

Output: To console.

Contents of parts array are:

parts[0] is: <number>

parts[1] is: <number>

parts[2] is: <number>

Homework Answers

Answer #1

Answer :

include <bits/stdc++.h>

using namespace std;

// Function to find minimum cost

// to be incurred

int findMinCost(int arr[], int n, int choc_cost) {

  // To reach first station, initial

  // chocolates required

  int choc_buy = arr[0];

  int curr_choc = 0;

  // Start traversing

  for (int i = 0; i < n - 1; i++) {

    // Find no. of chocolates

    // lose or gain

    int choc = arr[i] - arr[i + 1];

    // Add into curr_coc

    curr_choc += choc;

    // if no. of chocolates becomes

    // negative that means we have

    // to buy that no. of chocolates

    if (curr_choc < 0) {

      choc_buy += abs(curr_choc);

      curr_choc = 0;

    }

  }

  // Return cost required

  return choc_buy * choc_cost;

}

// Drivers code

int main() {

  int arr[] = {10, 6, 11, 4, 7, 1};

  int n = sizeof(arr) / sizeof(arr[0]);

  // Price of each candy

  int p = 5;

  cout << findMinCost(arr, n, p);

  return 0;

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
A manufacturer produces a line of tableware made from sand casting a special alloy of several...
A manufacturer produces a line of tableware made from sand casting a special alloy of several metals. After casting, the pieces go through a series of shaping, grinding, buffing, and polishing steps. The manufacturer recently began a program to study the total time spent on the grinding, buffing, and polishing steps across their entire product line. The distribution surrounding the random variable representing the total time (in minutes) spent in grinding, buffing, and polishing can be modeled by a normal...
The Vice President for Sales and Marketing at Waterways Corporation is planning for production needs to...
The Vice President for Sales and Marketing at Waterways Corporation is planning for production needs to meet sales demand in the coming year. He is also trying to determine how the company’s profits might be increased in the coming year. This problem asks you to use cost-volume-profit concepts to help Waterways understand contribution margins of some of its products and decide whether to mass-produce any of them. Waterways markets a simple water control and timer that it mass-produces. Last year,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
*Note: 4 of the 5 questions are correct. I am having great trouble figuring out the...
*Note: 4 of the 5 questions are correct. I am having great trouble figuring out the 4th part of the question. What I have listed below is the problem in its entirety. Bob's Bumpers has a repetitive manufacturing facility in Kentucky that makes automobile bumpers and other auto body parts. The facility operates 280 days per year and has annual demand of 66,000 bumpers. They can produce up to 425 bumpers each day. It costs $61 to set up the...
QUESTION 1 Which of the following best exemplifies offshoring? A. A U.S. company employs foreign nationals...
QUESTION 1 Which of the following best exemplifies offshoring? A. A U.S. company employs foreign nationals at its U.S. based headquarters. B. A U.S. company translates novels originally written in foreign languages into English for distribution in the U.S. market. C. A U.S. company starts a chain of fusion restaurants to cater to the American public’s evolving palates. D. A U.S. company purchases footwear made in Europe to distribute to retailers in the United States. E. A U.S. company that...
Mattel Responds to Ethical Challenges Business Ethics This case was written by Debbie Thorne, John Fraedrich,...
Mattel Responds to Ethical Challenges Business Ethics This case was written by Debbie Thorne, John Fraedrich, O. C. Ferrell, and Jennifer Jackson, with the editorial assistance of Jennifer Sawayda. This case was developed for classroom discussion rather than to illustrate either effective or ineffective handling of an administrative, ethical, or legal discussion by management. All sources used for this case were obtained through publicly available material. Mattel, Inc. is a world leader in the design, manufacture, and marketing of family...
1. The failure of the new supply chain system affected Nike adversely. What were the reasons...
1. The failure of the new supply chain system affected Nike adversely. What were the reasons for the failure and how did the breakdown harm Nike? 2. What are the important elements to be kept in mind while implementing a new system in an organization? What is the importance of a good working relationship between partners and the sharing of responsibility in implementing critical projects? What mistakes did Nike and i2 make? 3. comment on the lessons learned and the...
3 SECURING THE WORKFORCE Diversity management in X-tech, a Japanese organisation This case is intended to...
3 SECURING THE WORKFORCE Diversity management in X-tech, a Japanese organisation This case is intended to be used as a basis for class discussion rather than as an illustration of the effective or ineffective handling of an administrative situation. The name of the company is disguised. INTRODUCTION In light of demographic concerns, in 2012, the Japanese government initiated an effort to change the work environment in order to secure the workforce of the future. Japan is world renowned for its...
Sign In INNOVATION Deep Change: How Operational Innovation Can Transform Your Company by Michael Hammer From...
Sign In INNOVATION Deep Change: How Operational Innovation Can Transform Your Company by Michael Hammer From the April 2004 Issue Save Share 8.95 In 1991, Progressive Insurance, an automobile insurer based in Mayfield Village, Ohio, had approximately $1.3 billion in sales. By 2002, that figure had grown to $9.5 billion. What fashionable strategies did Progressive employ to achieve sevenfold growth in just over a decade? Was it positioned in a high-growth industry? Hardly. Auto insurance is a mature, 100-year-old industry...
2. SECURING THE WORKFORCE Diversity management in X-tech, a Japanese organisation This case is intended to...
2. SECURING THE WORKFORCE Diversity management in X-tech, a Japanese organisation This case is intended to be used as a basis for class discussion rather than as an illustration of the effective or ineffective handling of an administrative situation. The name of the company is disguised. INTRODUCTION In light of demographic concerns, in 2012, the Japanese government initiated an effort to change the work environment in order to secure the workforce of the future. Japan is world renowned for its...