C++ Progamming
This lab gives you a little practice with stacks and queues
·In “stackfib.cpp”, write a non-recursive function fib() which:
·Takes a single int parameter n
·Returns the nth Fibonacci number. We will start with fib(0) == fib(1) == 1, then fib(n) = fib(n-1) + fib(n-2)
·To compute this without using recursion, we use a stack to store the numbers we need to compute
(1) Initialize your result to be 0
(2) Push the parameter n onto the stack
(3) While the stack is not empty,
(a) Get the top value on the stack (use top()) and pop it off
(b) If this value is less than 2, add 1 to the result. Do not push anything onto the stack
(c) Otherwise, push the top value - 1 and the top value – 2. Do not modify the result
(4) When the stack is finally empty, return the result
·Write main() to test this function – output the values of fib(0) through fib(9)
·Here is some sample final output:
Computing Fibonacci numbers without recursion
fib(0) = 1
fib(1) = 1
fib(2) = 2
fib(3) = 3
fib(4) = 5
fib(5) = 8
fib(6) = 13
fib(7) = 21
fib(8) = 34
fib(9) = 55
·In a different file “sched_sim.cpp”, define classes Process and Sched to simulate an operating system alternating among processes, giving each a “time slice”. You will use a queue to manage the processes.
·The Process class should include: (you can add more functions)
(1) Integer fields for id and time left (number of cycles left to finish execution) – these must be private
(2) A constructor to initialize the id and time left
(3) runPeriod() to “run” the process for 5 cycles. We only care about the scheduling, so output the process being run and how many cycles are left after the 5 cycles are over
(4) done() to return true if the process has nothing left to do (0 time left)
·The Sched class should include:
(1) A private queue of Process’s – you can make it a queue of pointers to Process if you prefer
(2) A function addProcess() that takes a Process parameter and adds it to the queue
(3) A function exec() that:
(a) If the queue is empty, output a message for that
(b) Otherwise, take the first process off the queue and
(i) call runPeriod() for that process
(ii) if the process is not done, add it back to the queue
·Write a main() to test your code. Sample output for the final program (process 0 needs 14 cycles, process 1 needs 3 cycles, process 2 needs 7 cycles. Processes 0 and 1 are added first, then the Sched exec()’s once before process 2 is added.)
Simulating timesharing among processes
Running process 0
9 cycles left
Running process 1
0 cycles left
Running process 0
4 cycles left
Running process 2
2 cycles left
Running process 0
0 cycles left
Running process 2
0 cycles left
No waiting processes
In: Computer Science
| Part 2: Budget Completion | Indicate your | ||||||
| Fill in the missing information where indicated. | answers below: | ||||||
| Cash Collections Budget | 1 | ||||||
| 2 | |||||||
| • Accounts receivable, beginning balance | $25,000 | 3 | |||||
| • Sales collected in the quarter sales are made | 60% | 4 | |||||
| • Sales collected in the quarter after sales are made | 40% | 5 | |||||
| 6 | |||||||
| Qtr. 1 | Qtr. 2 | Qtr. 3 | Qtr. 4 | 7 | |||
| Total sales | $250,000 | $300,000 | $400,000 | $325,000 | 8 | ||
| 9 | |||||||
| Construct the schedule of expected cash collections | 10 | ||||||
| Qtr. 1 | Qtr. 2 | Qtr. 3 | Qtr. 4 | 11 | |||
| Beginning balance accounts receivable | $ 25,000 | 12 | |||||
| First-quarter sales | 1 | 2 | |||||
| Second-quarter sales | 3 | 4 | |||||
| Third-quarter sales | 5 | 6 | |||||
| Fourth-quarter sales | $ 195,000 | ||||||
| Total cash collections | ? | ? | ? | ? | |||
| Production Budget | |||||||
| • Desired ending finished goods inventory is | 15% | of the budgeted unit sales of the next quarter | |||||
| Qtr. 1 | Qtr. 2 | Qtr. 3 | Qtr. 4 | ||||
| Budgeted unit sales | 12500 | 15000 | 20000 | 16250 | |||
| Add desired ending finished goods inventory | 7 | 8 | 9 | 5000 | |||
| Total needs | ? | ? | ? | 21250 | |||
| Less beginning finished goods inventory | 2000 | 10 | 11 | 12 | |||
| Required production in units | ? | ? | ? | ? | |||
| Cash Budget | Indicate your | ||||||
| Note: Your cash collections will come from the Cash Collections Budget completed above. | answers below: | ||||||
| • Line of credit interest rate | 6% | ||||||
| • Minimum cash balance that must be on hand | $12,000 | 13 | |||||
| • Must borrow in increments of | $5,000 | 14 | |||||
| 15 | |||||||
| Qtr. 1 | Qtr. 2 | Qtr. 3 | Qtr. 4 | 16 | |||
| Beginning cash balance | $ 18,000 | 19 | 26 | 33 | 17 | ||
| Add: Cash collections | 13 | 20 | 27 | 34 | 18 | ||
| Total cash available | 14 | 21 | 28 | 35 | 19 | ||
| Less: Cash disbursements | 20 | ||||||
| Materials | $ 75,000 | $ 73,000 | $ 90,000 | $ 65,000 | 21 | ||
| Direct labor | $ 32,000 | $ 42,000 | $ 42,000 | $ 34,000 | 22 | ||
| Manufacturing overhead | $ 42,000 | $ 57,000 | $ 62,000 | $ 52,000 | 23 | ||
| Selling and administrative | $ 43,000 | $ 52,000 | $ 57,000 | $ 46,000 | 24 | ||
| Equipment purchase | $ 30,000 | $ 50,000 | $ 125,000 | $ 65,000 | 25 | ||
| Total disbursements | $ 222,000 | $ 274,000 | $ 376,000 | $ 262,000 | 26 | ||
| Excess (deficiency) | 15 | 22 | 29 | 36 | 27 | ||
| Financing | 28 | ||||||
| Borrowing | 16 | 23 | 30 | 37 | 29 | ||
| Repayments | 38 | 30 | |||||
| Interest | 39 | 31 | |||||
| Total financing | 17 | 24 | 31 | 40 | 32 | ||
| Ending cash balance | 18 | 25 | 32 | 41 | 33 | ||
| 34 | |||||||
| 35 | |||||||
| 36 | |||||||
| 37 | |||||||
| 38 | |||||||
| 39 | |||||||
| 40 | |||||||
| 41 | |||||||
In: Accounting
Partnerships should report information regarding QBI in order to
1. reduce ordinary income on page 1 form 1065
2. provide information to the partners of their share so they may benefit from a deduction on their form 1040
3. make adjustments on the partnerships balance sheet on page 5 form 1065
4. provide information on the partnerships schedule K page 4 that will reduce ordinary income by 20%
In: Accounting
A stock was trading at $21.85 at the end of year 1. It was trading at the end of year 2 at $22.18 immediately after giving a dividend of $0.30. At the end of year 3. it was trading at $21.54 immediately after giving a dividend of $0.32. Finally, it was trading at $23.36 at the end of year 4 without giving out any dividend. What was the geometric average annual return of this stock for the three years between years 1 and 4?
In: Finance
Give the value of x (x is an integer and assume integer arithmetic for all operations).
________ 1. x = 12 - 4 * 2 - 8;
________ 2. x = 24 / 2 + 1 * 4;
________ 3. x = 12 - 9 + 4 * 2 + 3 ^ 4;
________ 4. x = 24/(3 + 2) * 4;
________ 5. x = 2 * (5 - 3) + 7;
________ 6. x = 12 - (15/5 - 2) * 5;
________ 7. x = 20 - 15/((5 - 2) * 5);
________ 8. x = 13 % 5;
Evaluate the following equations, given A = 12, B = 3, C = 6, D = 2 ,A, B, C, and D are integers, and all operations are integer
________ 9. x = A + B/C - D^2.;
________ 10. x = A + B/(C - D^2);
________ 11. x = (A + B) % C;
________ 12. x = (A + B)/C - D^2;
Assume the following order of operations:
!
&&
||
Give the value of x,
given A = FALSE, B = FALSE, C = FALSE, D = TRUE. E = 10, F = 15
________ 13. x = A && B
________ 14. x = C || D
________ 15. x = !C
________ 16. x = !(A && D)
________ 17. x = !C && B
________ 18. x = ( E < 10) && (E == F)
________ 19. x = A && B || C && D
________ 20. x = !(A && B) || !(D && C)
Write c++ statements for each of the following (no declarations necessary here):
In: Computer Science
A rookie quarterback is negotiating his first NFL contract. His opportunity cost is 9%. He has been offered three possible 4-year contracts. Payments are guaranteed, and they would be made at the end of each year. Terms of each contract are as follows:
| 1 | 2 | 3 | 4 |
| Contract 1 | $2,500,000 | $2,500,000 | $2,500,000 | $2,500,000 |
| Contract 2 | $2,500,000 | $3,500,000 | $4,000,000 | $5,000,000 |
| Contract 3 | $6,500,000 | $1,000,000 | $1,000,000 | $1,000,000 |
As his adviser, which contract would you recommend that he accept?
Select the correct answer.
|
|||
|
|||
|
|||
|
|||
|
In: Finance
A rookie quarterback is negotiating his first NFL contract. His opportunity cost is 10%. He has been offered three possible 4-year contracts. Payments are guaranteed, and they would be made at the end of each year. Terms of each contract are as follows:
1 2 3 4
Contract 1 $2,500,000 $2,500,000 $2,500,000 $2,500,000
Contract 2 $2,500,000 $3,500,000 $4,000,000 $5,500,000
Contract 3 $6,500,000 $1,500,000 $1,500,000 $1,500,000
As his adviser, which contract would you recommend that he accept? Select the correct answer.
a. Contract 3 gives the quarterback the highest future value; therefore, he should accept Contract 3.
b. Contract 2 gives the quarterback the highest present value; therefore, he should accept Contract 2.
c. Contract 1 gives the quarterback the highest future value; therefore, he should accept Contract 1.
d. Contract 3 gives the quarterback the highest present value; therefore, he should accept Contract 3.
e. Contract 1 gives the quarterback the highest present value; therefore, he should accept Contract 1.
In: Finance
5.20 A rookie quarterback is negotiating his first NFL contract. His opportunity cost is 6%. He has been offered three possible 4-year contracts. Payments are guaranteed, and they would be made at the end of each year. Terms of each contract are as follows:
| 1 | 2 | 3 | 4 |
| Contract 1 | $3,500,000 | $3,500,000 | $3,500,000 | $3,500,000 |
| Contract 2 | $2,000,000 | $3,000,000 | $4,000,000 | $5,500,000 |
| Contract 3 | $7,000,000 | $1,500,000 | $1,500,000 | $1,500,000 |
As his adviser, which contract would you recommend that he accept?
Select the correct answer.
|
|||
|
|||
|
|||
|
|||
|
In: Finance
rookie quarterback is negotiating his first NFL contract. His opportunity cost is 8%. He has been offered three possible 4-year contracts. Payments are guaranteed, and they would be made at the end of each year. Terms of each contract are as follows:
| 1 | 2 | 3 | 4 |
| Contract 1 | $3,500,000 | $3,500,000 | $3,500,000 | $3,500,000 |
| Contract 2 | $2,000,000 | $3,500,000 | $4,000,000 | $5,500,000 |
| Contract 3 | $6,500,000 | $1,000,000 | $1,000,000 | $1,000,000 |
As his adviser, which contract would you recommend that he accept?
Select the correct answer.
|
|||
|
|||
|
|||
|
|||
|
In: Finance
Problem #2: Schooling Bill lives for four periods. He is currently considering the following alternative education work options.
A) He starts working immediately, earning $200,000 in period 1 (today), $250,000 in period 2, $280,000 in period 3, and $300,000 in period 4. 1
B) He spends $100,000 to attend college in period 1 (and does not work), earns $300,000 in periods 2, $450,000 in period 3, and $550,000 in period 4.
C) After completing college in period 1 (which costs $100,000), he attends graduate school in period 2 (and does not work), which costs another $100,000. After receiving his graduate degree, he will earn $600,000 in period 3, and $800,000 in period 4.
Assume Bill’s discount rate is 10% per period and answer the following questions.
1. Calculate the present value of Bill’s earnings associated with each of these alternatives (using a calculator). What education path maximizes Bill’s net present value of his lifetime earnings?
2. Now assume that the graduate program offers a research assistantship which covers his graduate school expenses in period 2 for alternative c. What education path maximizes Bill’s net present value of his lifetime earnings now?
3. Suppose Ann has the same alternatives as Bill but her discount rate is 30%. What education path maximizes Ann’s net present value of his lifetime earnings? (assume that she also receives an assistantship for grad school so that her direct schooling cost in period 2 is zero for alternative c)
In: Economics