C++ Pie bakery
our bakery makes 8 kinds of pie, and receives orders for these pies from on-line buyers. The program you’ll write for this lab knows the price of each pie, so as each new order is received, it’s possible to know how much money the bakery should be receiving.
The program must read in lines of input which have two fields: a pie type and a quantity. With this, the program needs to update the quantity of that type of pie, adding the new order to those already received. You already have code that you’ve written for previous labs that uses getline() and splits the line read in into two separate parts: you get to re-use that here, since you have the same work to do – breaking an input string into two substrings, the first is the name of a kind of pie string and the second is the quantity int.
The program you are writing would be part of a larger system used by the bakery to track and schedule its baking. That’s good for you because it means that the input your program reads is guaranteed not to have bogus order numbers or pie types. A sample input line looks like:
raspberry 10
When the program reaches the end of input it prints out, for each type of pie, the quantity ordered and the total price of that number of those pies. After that it prints out the grand total of all orders (total number of pies, total price).
One problem you face is mapping pie types as strings (how you read them in) to the int index of the array element holding the struct for that pie type. For example, you might read in ”apple” and need to figure out that it’s in array element 3. You must use a function to handle this.
To make life a bit easier, you should initialize an array of struct with these pie types and prices:
peach lemon pumpkin blueberry apple raspberry strawberry cherry
$3.75 $4.50 $5.75 $4.25 $3.70 $6.35 $5.65 $5.20
Of course, you’ll need more than just these two fields in your
struct.
A sample run with 100 individual pie orders might produce output
like this.
Orders for peach: Orders for lemon: Orders for pumpkin: Orders for blueberry: Orders for apple: Orders for raspberry: Orders for strawberry: Orders for cherry:
115 value is $ 431.25 128 value is $ 576.00 75 value is $ 431.25 75 value is $ 318.75 71 value is $ 262.70 89 value is $ 565.15 122 value is $ 689.30 53 value is $ 275.60
Grand total: 728 pies for $3550.00
You can test your program with data you type in, or on a test data file you create.
In: Computer Science
Substantial uncertainty exists regarding the causal effect of health insurance on the utilization of care. Most studies cannot determine whether the large differences in healthcare utilization between the insured and the uninsured are due to insurance status or to other unobserved differences between the two groups. In this paper, we exploit a sharp change in insurance coverage rates that results from young adults “aging out” of their parents’ insurance plans to estimate the effect of insurance coverage on the utilization of emergency department (ED) and inpatient services. [In the US, children are eligible for insurance coverage through their parents’ insurance only up to their 23rd birthday, at which point they lose eligibility.] Using the National Health Interview Survey (NHIS) and a census of emergency department records and hospital discharge records from seven states, we find that aging out results in an abrupt 5 to 8 percentage point reduction in the probability of having health insurance. We find that not having insurance leads to a 40 percent reduction in ED visits and a 61 percent reduction in inpatient hospital admissions.
In: Economics
The table lists foreign exchange rates for August 30, 2018. On that day, how many dollars would be required to purchase 1,200 units of each of the following: British pounds, Canadian dollars, EMU euros, Japanese yen, Mexican pesos, and Swedish kronas? Use the direct quotation for your calculations. Round your answers to the nearest cent.
| Sample Exchange Rates: Thursday, August 30, 2018 | ||
| Direct Quotation: U.S. Dollars Required to Buy One Unit of Foreign Currency (1) |
Indirect Quotation: Number of Units of Foreign Currency per U.S. Dollar (2) |
|
| Australian dollar | 0.7264 | 1.3767 |
| Brazilian real | 0.2409 | 4.1504 |
| British pound | 1.3009 | 0.7687 |
| Canadian dollar | 0.7702 | 1.2984 |
| Chinese yuan | 0.1461 | 6.8448 |
| Danish krone | 0.1565 | 6.3889 |
| EMU euro | 1.1670 | 0.8569 |
| Hungarian forint | 0.00357015 | 280.10 |
| Israeli shekel | 0.2767 | 3.6136 |
| Japanese yen | 0.00901 | 110.99 |
| Mexican peso | 0.0523 | 19.1133 |
| South African rand | 0.0679 | 14.7205 |
| Swedish krona | 0.1096 | 9.1200 |
| Swiss franc | 1.0317 | 0.9693 |
| Venezuelan bolivar fuerte | 0.00000403 | 248409.0001 |
| Note: Column 2 equals 1.0 divided by Column 1. However, rounding differences do occur. | ||
| Source: Adapted from The Wall Street Journal (www.wsj.com), August 30, 2018. | ||
| 1,200 British pounds | = | $ |
| 1,200 Canadian dollars | = | $ |
| 1,200 EMU euros | = | $ |
| 1,200 Japanese yen | = | $ |
| 1,200 Mexican pesos | = | $ |
| 1,200 Swedish kronas | = | $ |
In: Finance
Drosophila (Pty) Ltd is currently forecasting its short-term
financing needs and it requires your assistance in determining
these needs and the possible costs of financing. The following
information has been gathered and passed on to you.
The bookkeeper extracted an aging report from the system and
determined that 40% of sales were paid for in the same month that
the sales were made and the remainder was paid 1 month later (all
sales were on credit).
The company has access to a R1 000 000 revolving credit facility
(line of credit) at a cost of 12% interest per year, assuming 365
days per year. No administrative fees are applicable.
All purchases and other expenses are paid in cash.
Sales from March, April and May were as follows:
| March | April | May |
| R500 000 | R600 000 | R400 000 |
Expected sales for June, July and August are as follows:
| June | July | August |
| R300 000 | R400 000 | R800 000 |
Additionally, purchases amount to 50% of sales and other costs amount to R200 000 per month but exclude a depreciation expense of R5 000 per month.
REQUIRED:
Draw up a cash budget for this company for June, July and August
and determine how much the requisite short-term financing by way of
the revolving credit facility will cost (in rand terms) if
utilised. Use the space below to make your preliminary calculations
and present your cash budget in the space provided below where
indicated
In: Accounting
Onta Enterprises is seeking to expand operations and is considering increasing production capacity by purchasing the latest plant and equipment. The following two plants are being considered for acquisition as they are technically superior to the current plant and will enable higher production volumes with lower cost inputs. The finance department has projected the cash flows for the life of the plant and has asked you as the investment manager to advise the Board on which of these plants to acquire. Onta’s current cost of capital is 12%.
The following information relates to the two plants that are being considered:
|
Plant Alpha |
Plant Beta |
||
|
Initial cost |
R550 000 |
R 400 000 |
|
|
Expected useful life |
4 years |
4 years |
|
|
Depreciation |
R137 500 p.a. |
R100 000 p.a. |
|
|
Net cash inflows |
Net cash inflows |
Net profit |
|
|
Expected net cash inflows |
R |
R |
R |
|
1st year 2nd year 3rd year 4th year |
180 000 190 000 210 000 160 000 |
130 000 130 000 130 000 130 000 |
30 000 30 000 30 000 30 000 |
Calculate the:
2.1 Payback Period for both plants. (Answers must be expressed in years, months and days.) (6)
2.2 Accounting Rate of Return for Plant Beta on initial investment. (4)
2.3 Net Present Value of each plant. (Round off amounts to the nearest Rand.) (9)
2.4 Based on your results in 2.1.3 which plant should be accepted? (1)
In: Accounting
Onta Enterprises is seeking to expand operations and is considering increasing production capacity by purchasing the latest plant and equipment. The following two plants are being considered for acquisition as they are technically superior to the current plant and will enable higher production volumes with lower cost inputs. The finance department has projected the cash flows for the life of the plant and has asked you as the investment manager to advise the Board on which of these plants to acquire. Onta’s current cost of capital is 12%.
The following information relates to the two plants that are being considered:
|
Plant Alpha |
Plant Beta |
||
|
Initial cost |
R550 000 |
R 400 000 |
|
|
Expected useful life |
4 years |
4 years |
|
|
Depreciation |
R137 500 p.a. |
R100 000 p.a. |
|
|
Net cash inflows |
Net cash inflows |
Net profit |
|
|
Expected net cash inflows |
R |
R |
R |
|
1st year 2nd year 3rd year 4th year |
180 000 190 000 210 000 160 000 |
130 000 130 000 130 000 130 000 |
30 000 30 000 30 000 30 000 |
Calculate the:
2.1 Payback Period for both plants. (Answers must be expressed in years, months and days.)
2.2 Accounting Rate of Return for Plant Beta on initial investment.
2.3 Net Present Value of each plant. (Round off amounts to the nearest Rand.)
2.4 Based on your results in 2.1.3 which plant should be accepted?
Note: All workings must be showed and answers must be typed in.
In: Accounting
The purpose of this question is to practice the pthread built in functions.
The following c program is a simple program to make a matrix of integers and print it.
//File name: a.c
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int** a;
int main(){
time_t t;
int m, n, i, j; //m is the numbers of rows and n is the number of columns.
printf("Enter the number of rows, and columns: ");
scanf("%d%d", &m, &n);
printf("%d, %d\n", m, n);
srand((unsigned) time(&t));
a=(int**) malloc(m*sizeof(int*));
for(j = 0; j < n; j++)
a[j] = (int*) malloc(n * sizeof(int*));
for(i = 0; i < m; i++)
for(j = 0; j < n; j++)
a[i][j] = rand() % 1000;
for(i = 0; i < m; i++){
for(j = 0; j < n; j++)
printf("%d,", a[i][j]);
printf("\n");
}
return 0;
}
Your project uses pthread built-in functions based on the following conditions:
1. The program reads from the console the number of rows and the number of columns (like the above program). Therefore, the matrix has m rows and n columns.
2. The program creates m threads.
3. Each thread assigns random numbers to one row of the matrix.
4. The function main, sorts each row.
5. Each thread displays its sorted row.
6. The function: main displays the entire matrix.
Answer: ?
In: Computer Science
QUESTION TWO [20]
Onta Enterprises is seeking to expand operations and is considering increasing production capacity by purchasing the latest plant and equipment. The following two plants are being considered for acquisition as they are technically superior to the current plant and will enable higher production volumes with lower cost inputs. The finance department has projected the cash flows for the life of the plant and has asked you as the investment manager to advise the Board on which of these plants to acquire. Onta’s current cost of capital is 12%.
The following information relates to the two plants that are being considered:
|
Plant Alpha |
Plant Beta |
||
|
Initial cost |
R550 000 |
R 400 000 |
|
|
Expected useful life |
4 years |
4 years |
|
|
Depreciation |
R137 500 p.a. |
R100 000 p.a. |
|
|
Net cash inflows |
Net cash inflows |
Net profit |
|
|
Expected net cash inflows |
R |
R |
R |
|
1st year 2nd year 3rd year 4th year |
180 000 190 000 210 000 160 000 |
130 000 130 000 130 000 130 000 |
30 000 30 000 30 000 30 000 |
Calculate the:
2.1 Payback Period for both plants. (Answers must be expressed in years, months and days.) (6)
2.2 Accounting Rate of Return for Plant Beta on initial investment. (4)
2.3 Net Present Value of each plant. (Round off amounts to the nearest Rand.) (9)
2.4 Based on your results in 2.1.3 which plant should be accepted? (1)
In: Finance
REQUIRED
5.1 Calculate the Payback Period of Project G (expressed in years, months and days). (3)
5.2 Calculate the Accounting Rate of Return (on average investment) of Project F (expressed to two decimal places). (5)
5.3 Calculate the Net Present Value of Project F (with amounts rounded off to the nearest Rand). (4)
5.4 Calculate the Internal Rate of Return (IRR) of Project G (expressed to two decimal places). (6)
5.5 Comment on the IRR calculated above. (2)
INFORMATION
Nascar Limited has the option to invest in machinery in Projects F and G but finance is only available to invest in one of them. The following projected data is available:
|
Project F |
Project G |
||
|
R |
R |
||
|
Initial cost |
250 000 |
250 000 |
|
|
Depreciation per year |
50 000 |
50 000 |
|
|
Net cash inflows: |
|||
|
Year 1 |
70 000 |
82 000 |
|
|
Year 2 |
75 000 |
82 000 |
|
|
Year 3 |
82 000 |
82 000 |
|
|
Year 4 |
85 000 |
82 000 |
|
|
Year 5 |
90 000 |
82 000 |
|
Additional information
1. Project F is expected to have a scrap value of R20 000 (not included in the figures above). No scrap value is expected for Project G.
2. The cost of capital is 15%. Additional information
1. Project F is expected to have a scrap value of R20 000 (not included in the figures above). No scrap value is expected for Project G.
2. The cost of capital is 15%.
In: Accounting
The purpose of this project is to practice the pthread built in functions.
The following c program is a simple program to make a matrix of integers and print it.
//File name: a.c
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int** a;
int main(){
time_t t;
int m, n, i, j; //m is the numbers of rows and n is the number of columns.
printf("Enter the number of rows, and columns: ");
scanf("%d%d", &m, &n);
printf("%d, %d\n", m, n);
srand((unsigned) time(&t));
a=(int**) malloc(m*sizeof(int*));
for(j = 0; j < n; j++)
a[j] = (int*) malloc(n * sizeof(int*));
for(i = 0; i < m; i++)
for(j = 0; j < n; j++)
a[i][j] = rand() % 1000;
for(i = 0; i < m; i++){
for(j = 0; j < n; j++)
printf("%d,", a[i][j]);
printf("\n");
}
return 0;
}
Your project uses pthread built-in functions based on the following conditions:
1. The program reads from the console the number of rows and the number of columns (like the above program). Therefore, the matrix has m rows and n columns.
2. The program creates m threads.
3. Each thread assigns random numbers to one row of the matrix.
4. The function main, sorts each row.
5. Each thread displays its sorted row.
6. The function: main displays the entire matrix.
Answer:
In: Computer Science