Write a program in c++ that merges numbers from two files and writes all the numbers into a third file in ascending order. Each input file contains a list of 50 sorted double floating-point numbers from the smallest to largest. After the program is run, the output file will contain all 100 numbers between in the two input files, also sorted from smallest to largest. Format the output into two columns – the first column contains the numbers 1-100, and the second column contains the appropriate number from the text file. Also print the results to the screen.
Specifications:
The input file names are called “numbers1.txt” and “numbers2.txt”, and can be found at the bottom of the page. Copy and paste the numbers from each text file into a “numbers1.txt” and “numbers2.txt” within your project directory. This can be done by creating a project with a main.cpp source file, compiling it, launching a terminal window, and using nano to create a text file where the numbers can be copied into (separately for each file). Once the numbers are copied into a generic text file, save it with the appropriate filename and exit nano.
The program should use two functions with the following function prototypes:
void checkFailure(ifstream &fin1, ifstream &fin2, ofstream &fout);
void sortNumbers(ifstream &fin1, ifstream &fin2, ofstream &fout);
The checkFailure() function should accept the two input-file streams and the output-file stream as call-by-reference arguments. The function should make sure that the files were opened properly and exit the program with EXIT_FAILURE if necessary.
If a file fails to open, the error should read:
Input file “[filename]” failed to open.
[filename] represents the file that failed to open. For instance, if numbers2.txt fails to open, the error message to be printed to the screen is:
Input file “numbers2.txt” failed to open.
The sortNumbers() function should also accept the two input-file streams and the output-file stream as call-by-reference arguments. The function should read in the values from the input files (without using an array) and compare values one at a time to determine the smallest value between any pair of numbers. As a new number is read in, the smallest value should be written to the output file.
The first column written to the output file should be an integer between 1-100, representing which value is being represented, since there are a 100 numbers total. The integer values 1 - 100 should be printed with a width of 3 and right justified.
The second column written to the output file should be the appropriate double floating-point number. Print each number with a precision of 8 values after the decimal point. The two columns should be separated by a tab.
The final output should print the results to the screen, and to a file called “sorted.txt”.
NOTE: When you first read in the first two numbers, one of them is the absolute minimum, and is the first number written to the file. If that number came from numbers1.txt, then the next number to be read in should also be from numbers1.txt. If the new number read in is still smaller than the other number from numbers2.txt, write it to the file and repeat the process until the next number read in from numbers1.txt is no longer the smallest number. Then write the number from numbers2.txt to the file and read in a new value from numbers2.txt. Repeat the process as necessary (i.e., read in a new number one at a time from the appropriate data file) to ensure each value is written to the data file in the correct order. If/When you run out of numbers from one of the input data files, any remaining numbers in the second input data file should be read in and written to the output file directly, since comparisons are no longer necessary.
As an example, if you execute the program with the following underlined inputs, the output will be:
~> main.o
1 0.00476587
2 0.00952649
3 0.01107230
4 0.01862460
5 0.02598610
...
99 0.98603100
100 0.99549800
~> more sorted.txt
1 0.00476587
2 0.00952649
3 0.01107230
4 0.01862460
5 0.02598610
...
99 0.98603100
100 0.99549800
~>
numbers1.txt
0.00476587
0.00952649
0.0110723
0.0186246
0.0259861
0.0328688
0.0861446
0.0948271
0.112295
0.159563
0.184204
0.244189
0.248323
0.293049
0.308473
0.34332
0.407723
0.408518
0.417362
0.421145
0.456012
0.485628
0.585623
0.600914
0.610335
0.621299
0.651852
0.658051
0.673929
0.680218
0.689137
0.693944
0.705223
0.710375
0.726621
0.741053
0.7481
0.761997
0.788303
0.795886
0.812099
0.832322
0.848749
0.870877
0.928862
0.945333
0.962629
0.96473
0.971811
0.986031
numbers2.txt
0.00476587
0.00952649
0.0110723
0.0186246
0.0259861
0.0328688
0.0861446
0.0948271
0.112295
0.159563
0.184204
0.244189
0.248323
0.293049
0.308473
0.34332
0.407723
0.408518
0.417362
0.421145
0.456012
0.485628
0.585623
0.600914
0.610335
0.621299
0.651852
0.658051
0.673929
0.680218
0.689137
0.693944
0.705223
0.710375
0.726621
0.741053
0.7481
0.761997
0.788303
0.795886
0.812099
0.832322
0.848749
0.870877
0.928862
0.945333
0.962629
0.96473
0.971811
0.986031
In: Computer Science
Suppose demand for a product is determined by its price, consumers’ income, and the price of a related good. Use Q for demand, P for price, M for income, and PR for price of related good. The demand function is estimated using regression analysis.
The results are reported below:
|
SUMMARY OUTPUT |
||||
|
Regression Statistics |
||||
|
Multiple R |
0.814752135 |
|||
|
R Square |
0.663821042 |
|||
|
Adjusted R Square |
0.159552605 |
|||
|
Standard Error |
530.2842631 |
|||
|
Observations |
66 |
|||
|
Coefficients |
Standard Error |
t Stat |
P-value |
|
|
Intercept |
125.56 |
15.87 |
||
|
P |
-5.39 |
2.19 |
??? |
|
|
M |
0.069 |
0.046 |
||
|
PR |
-10.98 |
2.73 |
||
What is the R2 of this regression?
What is the degrees of freedom of this regression?
What is the effect of a one-dollar increase in price (P) on demand (Q)?
What is the effect of a one-dollar increase in income (M) on demand (Q)?
What is the effect of a one-dollar increase in price of related good (PR) on demand (Q)?
Calculate the t Stat (or t ratio marked with “???” in the table) for the coefficient on P?
Test whether the effect of P on Q is significant at the 5% significance level. Show your work.
Using the p-value 0.046 in the table, test if the effect of M on Q is significant at the 5% significance level.
Using the values P=100, M=35,000, and PR=40, predict the demand (Q)?
Using the value of predicted Q you just calculated for part 9), calculate the estimates of
The price elasticity of demand. Show your work.
The income elasticity of demand. Show your work.
The cross-price elasticity of demand. Show your work.
In: Statistics and Probability
Consider an economy described by the following short-run aggregate demand, aggregate supply and long-run aggregate supply curve:
(short-run aggregate demand curve) P = 200 – Y
(short-run aggregate supply curve) P = 40 + Y
(long-run aggregate supply curve) Y *= 120
where P = Price Level (price index with base period’s index = 100) and Y = Quantity of Output
Find new equilibrium price (P**) and output level (Y**): P**=_____________ Y **=____________
The output of the economy falls from Y* to Y** falling output experiencing ( a)______________
And the price level rises from P* to P** experiencing (b)________________, such an event is called (c)__________________. According to the (d)_______________ theory, the key issue is how nominal wages are affected by price changes.
Key words: (1) full employment (2) stagflation (3) inflation (4) deflation (5) unemployment
In: Economics
Perpetual Inventory Using FIFO
Beginning inventory, purchases, and sales for Item Zeta9 are as follows:
Oct. 1 Inventory 200 units at $30
7 Sale 160 units
15 Purchase 180 units at $33
24 Sale 150 units
Assuming a perpetual inventory system and using the first-in, first-out (FIFO) method, determine (a) the cost of goods sold on October 24 and (b) the inventory on October 31.
a. Cost of goods sold on October 24
b. Inventory on October 31
In: Accounting
Assume the required reserve ratio at The First Bank of Idaho is 10%. The First Idaho Bank is a primary dealer, which means that it is a financial institution that is able to buy and sell securities directly to the U.S. Federal Reserve (Fed). Remember any bank in the U.S. can borrow from the Fed.
Provided below is the balance sheet for The First Bank of Idaho:
|
Type of Asset |
Asset Amount |
Type of Liability |
Bank Capital |
|
Reserves |
$50,000 |
Checkable Deposits |
$200,000 |
|
Loans |
$120,000 |
Savings Deposits |
$100,000 |
|
Securities |
$150,000 |
||
|
Bank Capital |
$20,000 |
||
Use the information as well as the balance sheet for The First Bank of Idaho provided above to complete and answer the following:
What is the amount of excess reserves held by The First Bank of Idaho?
The Fed buys $50,000 of securities from The First Bank of Idaho and pays for those securities by increasing The First Bank of Idaho’s bank deposits at the Fed. Show the effect of this transaction on The First Bank of Idaho’s balance sheet.
When completing this part of your answer, remember that reserves equal bank deposits held at the Fed, plus vault cash.
What happens to excess reserves when the Fed buys securities from The First Bank of Idaho?
What happens to the amount of loans The First Bank of Idaho can create after the Fed buys securities? What will happen to the money supply if The First Bank of Idaho makes additional loans?
Go back to the original balance sheet. Suppose The First Bank of Idaho borrows $25,000 from the Fed. Show the effect of that transaction on The First Bank of Idaho’s balance sheet.
What happens to excess reserves at The First Bank of Idaho after the discount loan? What will happen to the money supply?
What happens to the amount of loans The First Bank of Idaho can create after the discount loan?
Go back to the original balance sheet. The Fed has a new tool that can pay interest on reserves held at the Fed. If the interest rate on reserves increases, will The First Bank of Idaho be more- or less-likely to hold excess reserves? What will happen to the amount of loans The First Bank of Idaho will make if the interest rate on reserves increases? What will happen to the money supply?
The Fed is currently using three tools: open market operations, interest rate on reserves, and forward guidance. Define each tool and explain how the Fed uses that tool to increase and decrease the money supply.
In: Economics
|
Series I |
Series II |
|
1.72 |
7.03 |
|
1.81 |
6.94 |
|
1.93 |
7.02 |
|
1.96 |
6.89 |
|
1.96 |
7.06 |
|
2.00 |
6.97 |
|
2.06 |
6.95 |
|
2.07 |
6.98 |
|
2.13 |
6.98 |
|
2.16 |
7.04 |
In: Statistics and Probability
In: Chemistry
Xbar in the first sample: 1.5
Standard Deviation in the first sample: 1.7
Size of the first sample (n1): 13
Xbar in the second sample: 3.5
Standard Deviation in the second sample: 2.3
Size of the second sample (n2): 17
Use the conservative t-test to test the null hypothesis of equality of means. Submit the p-value of your test of significance.
In: Statistics and Probability
First, show all work for determining the mass of the planar lamina region in the first quadrant bounded by the circle ? 2 + ? 2 = 4 and the lines ? = 0 and ? = ? √3 with a density of ?(?, ?) = ? 2 . (Hint: You may want to use a double angle formula if using polar coordinates) Second, set up the double integrals for finding the moments My and Mx. Finally, use Wolfram Alpha to determine the center of mass of the planar lamina rounded to the hundredths place.
In: Physics
Explore the overall market for First Solar.
a) Discuss the market share of First Solar and its top competitors by providing details on current percentages for each firm and describing the trend over time. You might consider presenting the data graphically.
b) Analyze the barriers to entry in this market to illustrate the potential for new competition and its impact on First Solar's future in the market.
c) Describe the market structure for First Solar and analyze how this affects the firm’s ability to influence the market.
In: Economics