The bounded buffer problem is a producer-consumer problem where a producer process adds new items to a shared buffer and a consumer process consumes items from that buffer (in the first-in-first-out (FIFO) order). When a producer adds a new item, the buffer size grows by one, and whenever a consumer consumes an item from the buffer, the size is reduced by one. The producer process must wait when the buffer is full likewise the consumer process must wait when the buffer is empty. You are to implement the bounded buffer (bb) problem using semaphores using POSIX APIs.
Use the following code:
// Synchronization tools
// Bounded buffer program with semaphores
// Author name: _______________________
// Author email: ___________________
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/shm.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <semaphore.h>
#include <unistd.h>
#include <sys/wait.h>
const int SIZE = 4;
int __item = 1001;
int IN;
int OUT;
int *count;
int *buffer;
void init() {
// TODO: Create semaphores
// Creating shared memory
int shm_fd = shm_open("PROD_CONS", O_CREAT | O_RDWR, 0666);
ftruncate(shm_fd, 4096);
int *sbuf = (int *)mmap(0, 4096, PROT_WRITE, MAP_SHARED, shm_fd, 0);
count = sbuf;
buffer = sbuf + 1;
*count = 0;
IN = OUT = 0;
}
/* Generate a new item */
int generate_new_item() {
return __item++;
}
void write_buffer() {
//TODO: Put new_item into the buffer
int new_item = generate_new_item();
printf("Writing value, current buffer size %d\n",*count);
}
void read_buffer() {
// TODO: read an item from the buffer
printf("Reading value, current buffer size %d\n", *count);
}
void producer() {
for (int i = 0; i < 10; i++) {
printf("PRODUCER:: ");
write_buffer();
sleep(2);
}
}
void consumer() {
for (int i = 0; i < 10; i++) {
printf("\t\tCONSUMER:: ");
read_buffer();
sleep(1);
}
}
int main(void) {
printf("Bounded buffer program\n");
init();
int pid = fork();
if (pid < 0) {
exit(0);
}
else if (pid == 0) {
consumer();
exit(0);
}
else if (pid > 0) {
producer();
wait(NULL);
// Unlink shared memory
shm_unlink("PROD_CONS");
// TODO: unlink the semaphores
exit(0);
}
return 0;
}
The skeleton code starts two processes (one as a producer and the other one as a consumer). A shared buffer (called "buffer") is created and the shared variable "count" counts the number of items in the buffer (the maximum allowed buffer size is defined by a const int SIZE, set to 4). Your task is to complete read_buffer() and write_buffer() functions (marked by TODO).
NOTE that you need to update IN, OUT, and count variables as items are added and removed from the buffer. You also need to add appropriate semaphore calls around those updates for proper synchronization.
Refer to Figure 7.1 (producer process) and Figure 7.2 (consumer process) in the textbook for details.
In: Computer Science
python program
You are going to write a program that takes two inputs: A string representing a list of names of the following form: first name 1, last name 1, (nick name 1); first name 2, last name 2, (nick name 2); ... A string representing part of or the complete family name. You are going to output all nick names for those names where there is a partial or complete match of the family name. If no match was found you should output: Not found! Here a few examples.
Names: Chun Kit, Chui (Kit gor); Dirk, Schnieders (Dirk); Jun-fan, Lee (Bruce); Rowan Sebastian, Atkinson (Bean)
Family name: Schni
Dirk
In: Computer Science
The code following is what I have so far. It does not meet my requirements. My problem is that while this program runs, it doesn't let the user execute the functions of addBook, isInList or compareLists to add, check, or compare. Please assist in correcting this issue. Thank you!
Write a C++ program to implement a singly linked list of books. The book details should include the following: title, author, and ISBN. The program should include the following functions:
#include <iostream>
#include <string>
using namespace std;
struct Book {
string title;
string author;
string isbn;
Book(string t, string a, string is)
{
title = t;
author = a;
isbn = is;
}
Book* next;
};
class BookList {
private:
Book* head;
public:
BookList();
void addBook(Book* b);
bool isInList(string isbn);
bool compareLists(BookList& other);
};
BookList::BookList()
{
head = NULL;
}
void BookList::addBook(Book* b)
{
b->next = head;
head = b;
}
bool BookList::isInList(string isbn)
{
Book* temp = head;
while (temp != NULL) {
if (temp->isbn == isbn) {
return true;
}
temp = temp->next;
}
return false;
}
bool BookList::compareLists(BookList& other)
{
Book* temp = head;
while (temp != NULL) {
if (!other.isInList(temp->isbn)) {
return false;
}
temp = temp->next;
}
return true;
}
int main()
{
BookList list1, list2;
list1.addBook(new Book("title1", "author1", "isbn1"));
list1.addBook(new Book("title2", "author1", "isbn2"));
list1.addBook(new Book("title1", "author2", "isbn3"));
list1.addBook(new Book("title3", "author3", "isbn4"));
list2.addBook(new Book("title1", "author1", "isbn1"));
list2.addBook(new Book("title2", "author1", "isbn2"));
list2.addBook(new Book("title1", "author2", "isbn3"));
list2.addBook(new Book("title4", "author4", "isbn5"));
cout << "list1.isInList(\"isbn4\")" <<
list1.isInList("isbn4") << endl;
cout << "list1.isInList(\"isbn5\")" <<
list1.isInList("isbn5") << endl;
cout << "list1.isInList(\"isbn2\")" <<
list1.isInList("isbn2") << endl;
cout << "list1.compareLists(list2)" <<
list1.compareLists(list2) << endl;
return 0;
}
In: Computer Science
1.The below code has some errors, correct the errors and post the working code.
Scanner console = new Scanner(System.in);
System.out.print("Type your name: ");
String name = console.nextString();
name = toUpperCase();
System.out.println(name + "
has " + name.Length() + " letters");
Sample Ouptut:
Type your name: John
JOHN has 4 letters
2. Write a code that it reads the user's first and last name (read in the entire line as a single string), then print the last name followed by a comma and the first initial.
Sample output:
Type your name: John Smith
Smith, J.
In: Computer Science
At a university, students are assigned a system user name, which is used to log into the campus computer network system. As part of your internship with the university's IT department, your assignment is to write the code that generates system user names for students.
You will use the following logic to generate a user name:
Get the first three characters of the student's first name. (If the first name is less than three characters use the entire first name.)
Get the first three characters of the student's last name. (If the last name is less than three characters use the entire last name)
Get the last three characters of the student's ID number. (If the ID number is less than three characters, use the entire ID number.)
Concatenate the three sets of characters to generate the user name.
For example, if a student’s name is Yogi Bear, and his ID number is T0017258, his login name would be YogBear721.
In main, obtain the student’s first name, last name and ID number, then call a function named get_login_name that accepts the student's first name, last name, and ID number as arguments and returns the student's login name as a string.
Next, in main, ask the student to generate a password then call a function to verify that it is correct. Passwords must adhere to the following rules:
A valid password must be at least seven characters in length,
Must have at least one uppercase letter, one lowercase letter, and one digit.
python programme
In: Computer Science
Constructing and Assessing Income Statements Using
Cost-to-Cost Method
Assume General Electric Company agreed in May 2016 to construct a
nuclear generator for NSTAR, a utility company serving the Boston
area. General Electric Company estimated that its construction
costs would be $360 million. The contract price of $450 million is
to be paid as follows: $150 million at the time of signing; $150
million on December 31, 2016; and $150 million at completion in May
2017. General Electric incurred the following costs in constructing
the generator: $144 million in 2016 and $216 million in 2017.
a. Compute the amount of General Electric's revenue, expense, and
income for both 2016 and 2017, and for both years combined, under
the cost-to-cost revenue recognition method.
Enter dollar amounts in millions.
| Cost-to-Cost Method | ||||
|---|---|---|---|---|
|
Year |
Costs incurred |
% of total excepted costs |
Revenue recognized |
Income |
| 2016 | Answer | Answer | Answer | Answer |
| 2017 | Answer | Answer | Answer | Answer |
| Total | Answer | Answer | Answer | |
In: Accounting
Bethesda Mining Company reports the following balance sheet
information for 2015 and 2016.
Prepare the 2015 and 2016 common-size balance sheets for Bethesda
Mining. (Do not round
intermediate calculations and enter your answers as a percent
rounded to 2 decimal places, e.g.,
32.16.)
|
BETHESDA MINING COMPANY Balance Sheets as of December 31, 2015 and 2016 |
|||||||||||||||||||||||
| 2015 | 2016 | 2015 | 2016 | ||||||||||||||||||||
| Assets | Liabilities and Owners’ Equity | ||||||||||||||||||||||
| Current assets | Current liabilities | ||||||||||||||||||||||
| Cash | $ | 55,526 | % | $ | 70,205 | % | Accounts payable | $ | 188,922 | % | $ | 196,611 | % | ||||||||||
| Accounts receivable | 63,281 | % | 83,639 | % | Notes payable | 84,020 | % | 135,588 | % | ||||||||||||||
| Inventory | 121,382 | % | 186,805 | % | Total | $ | 272,942 | % | $ | 332,199 | % | ||||||||||||
| Total | $ | 240,189 | % | $ | 340,649 | % | Long-term debt | $ | 235,000 | % | $ | 171,750 | % | ||||||||||
| Owners’ equity | |||||||||||||||||||||||
| Common stock and paid-in surplus | $ | 220,000 | % | $ | 220,000 | % | |||||||||||||||||
| Fixed assets | Accumulated retained earnings | 170,594 | % | 206,478 | % | ||||||||||||||||||
| Net plant and equipment | $ | 658,347 | % | $ | 589,778 | % | Total | $ | 390,594 | % | $ | 426,478 | % | ||||||||||
| Total assets | $ | 898,536 | % | $ | 930,427 | % | Total liabilities and owners’ equity | $ | 898,536 | % | $ | 930,427 | % | ||||||||||
|
|
|||||||||||||||||||||||
In: Finance
Depreciation by Three Methods; Partial Years
Razar Sharp Company purchased equipment on July 1, 2014, for $86,670. The equipment was expected to have a useful life of three years, or 6,480 operating hours, and a residual value of $2,430. The equipment was used for 1,200 hours during 2014, 2,300 hours in 2015, 1,900 hours in 2016, and 1,080 hours in 2017.
Required:
Determine the amount of depreciation expense for the years ended December 31, 2014, 2015, 2016, and 2017, by (a) the straight-line method, (b) units-of-output method, and (c) the double-declining-balance method.
Note: FOR DECLINING BALANCE ONLY, round the multiplier to four decimal places. Then round the answer for each year to the nearest whole dollar.
a. Straight-line method
|
Year |
Amount |
|
2014 |
$ |
|
2015 |
$ |
|
2016 |
$ |
|
2017 |
$ |
b. Units-of-output method
|
Year |
Amount |
|
2014 |
$ |
|
2015 |
$ |
|
2016 |
$ |
|
2017 |
$ |
c. Double-declining-balance method
|
Year |
Amount |
|
2014 |
$ |
|
2015 |
$ |
|
2016 |
$ |
|
2017 |
$ |
In: Accounting
t is now July 2016. Consider the following Futures Market for 1,000 barrels of Crude Oil:
|
Crude Oil Market (price per barrel, for 1,000 bbls.) |
|||
|
Date |
Jul-16 |
Nov-16 |
Feb-16 |
|
Spot Price |
35.00 |
35.00 |
39.00 |
|
December 2016 Futures Price |
33.00 |
34.25 |
exp. |
|
March 2017 Futures Price |
37.00 |
38.00 |
39.75 |
Suppose you are the CFO of an independent oil refiner. You will need to purchase 500,000 barrels of Crude Oil in November 2015 and February 2016 on the spot market. Please devise a hedging strategy for the company, assuming you are only allowed to use ‘front month’ contracts – meaning that in July 2015 (now) you can only hedge with the December 2016 futures contract. When that position is closed at the price indicated, then you can use the March 2016 Futures contract.
What would the average price have been if you simply purchased the oil in the spot market?
In: Finance
Matt Broderick Company began operations on January 2, 2013. It employs 9 individuals who work 8-hour days and are paid hourly. Each employee earns 10 paid vacation days and 6 paid sick days annually. Vacation days may be taken after January 15 of the year following the year in which they are earned. Sick days may be taken as soon as they are earned; unused sick days accumulate. Additional information is as follows.
Actual Hourly wage rate 2016 2017 Vacation days used by each employee 2016 2017 Sick days used by each employee 2016 2017
$10 $11 0 9 4 5
(a)Prepare journal entries to record transactions related to
compensated absences during 2016 and 2017.
(b) Compute the amounts of any liability for compensated absences
that should be reported on the balance sheet at December 31, 2016,
and 2017. Please explain each step with each calculation
In: Accounting