Questions
General overview (In C++) In this program you will be reading sales information from a file...

General overview (In C++)

In this program you will be reading sales information from a file and writing out a bar chart for each of the stores. The bar charts will be created by writing out a sequence of * characters.

You will have to create input files for your program. You can use a text editor such as Notepad or Notepad++ to create this. There may also be an editor in your IDE that you can use. You can use the TextEdit program on macOS but you will need to change the format to Make Plain Text. You will not be uploading these text files to zyBooks/zyLabs. The submit tests will be using their own files. Make sure that some of your files contain a newline at the end of the last line of text in the file. You can do this by hitting the enter key after the last number of the last line in the file. This will match the type of file usually created by programs. This is the type of file that is used for the zyBooks tests. See the description below on reading in files.

Reading in files

When reading data from a file you need to make sure you are checking for end of file properly.

See Demo of file input and output of data in this unit for an explanation of how to properly check for end of file.

The general method shown in the Gaddis text book is:

ifstream inputFile;
inputFile.open("input.txt");
int num;
if (inputFile)
{
   // the file opened successfully
   while (inputFile >> num)
   {
      // process the num value
      cout << num << endl;
   }
   inputFile.close();
}
else
{
   cout << "The file could not be opened" << endl;
}

If you want to read in two values with every read you can simply replace inputFile >> num with something like inputFile >> num1 >> num2 as shown here:

   while (inputFile >> num1 >> num2)
   {
      // process the num1 and num2 values
      cout << num1 << " " << num2 <<  endl;
   }

Text files are more complicated that they seem. Different operating systems handle text files differently. On Windows lines of text end with \r followed by \n. On Unix (or Linux) the lines end with just \n. On old Macs lines ended with \r but now use the Unix convention. The use of the >> operator takes care of these line ending issues for you.

But it is still more complicated than that. Most text files have every line ending with either \r \n (for Windows) or \n (for Unix/Linux and MacOS) but it is also possible to create a text file where the last line does NOT have the line ending characters. The use of the following code will work for all line endings even when the last line of text input does not end with any line endings.

if (inputFile >> num1 >> num2)
{
   // executes only if the read worked
}

or

while (inputFile >> num1 >> num2)
{
   // executes while the read works
}

There are other ways to test for end of file but you have to make sure your code will work for all of the cases discussed above. It is STRONGLY recommended that you use the process outlined above.

General overview (continued)

Your program will read in a file name from cin. It will then open the input file.

Your program must also open an output file called saleschart.txt. You will write the bar char headings and data to this file.

Your program needs to have the following general flow:

prompt for the input file name with the prompt "Enter input file name"
read in the file name
open the input file for this file name
display a message if the input file does not open and quit your program 
open the output file ("saleschart.txt")
display a message if the output file does not open, close the input file,  and quit your program
while (readFile into store number and sales for store
    if store number or sales are invalid
         display an appropriate error message (see below)
   else
         output bar chart for this store to the output file
   end if
end while
close the input and output files

The processing loop will read the input data and process it until it gets and end of file indication from the file read operation

Assuming you have read in valid data AND this is the first sales data being processed your program should output some headings to the output file before processing the data. The headings are as follows:

SALES BAR CHART
(Each * equals 5,000 dollars)

Note: Your program must not output the headings to the output file if all of the data in the input file is invalid, or if there is not any valid data in the input file.

You need to come up with a way of keeping track if this is the first valid read or not. .

Assuming you have valid data the processing will consist displaying the output

Once the loop has completed you need to close the input file.

If the input file could not be opened your program should output an error message to cout. Assume the file we are reading in from is called sales.txt, and the file does not exist. The error message written to cout is:

File "sales.txt" could not be opened 

The store number is of type unsigned int. Your program must verify that the store number is in the range 1 to 99 (inclusive). If the store number is invalid display the following message:

If the store number is less than 1 or greater than 99 you need to output the following message to cout:

The store number xx is not valid 

Where xx is the store number.

If the sales data is read in as a long long int. If the sales value is less than 0 you need to output the following message to cout:

The sales value for store xx is negative

Where xx is the store number.

Don't forget to close both files, if they were opened.

Write the bar chart information to the file.

You will be outputting a string of * characters where each * represents $5,000 in sales for that store. For each 5,000 in sales you output one *. You do not round up the sales, so sales of $16,000 and sales of $16,999 would both output 3 * characters.

You will output the sales bar chart to the output file.

Assuming a store number of 9 and sales of $16,999. the display function will write the following to the output file:

Store  9: ***

Note that the store width is 2 characters, so the output is:

Store yy: *******

The yy has a width of 2 even if the store number is 1 through 9.

The format of the input file

The data in the input file is in the order store number followed by the store sales. There will be zero or more of these input pairs in the file.

Here is the contents of a sample input text file:

1 10000
2 25000
3 37000
4 29000
5 8000

Sample runs

Here is an example run. Assume the following input being read in from cin:

sales.txt

Assume that the content of the file sales.txt are as follows:

1 10000
2 25000
3 37000
4 29000
5 8000

The output (to file saleschart.txt) for this input would be:

SALES BAR CHART
(Each * equals 5,000 dollars)
Store  1: **
Store  2: *****
Store  3: *******
Store  4: *****
Store  5: *

You are reading from an input file and you are writing to an output file. Make sure you close both files after you are finished using them. You must do this in your program, you cannot just let the operating system close the files for you.

In this lab. and some future labs, you will be creating an output file. There could be output to cout as well.

For tests where there is output written to an output file the contents of the output file will determine if you passed that test or not. For cases where you have written out to cout the tests will check the output sent to cout.

Failure to follow the requirements for lab lessons can result in deductions to your points, even if you pass the validation tests. Logic errors, where you are not actually implementing the correct behavior, can result in reductions even if the test cases happen to return valid answers. This will be true for this and all future lab lessons.

Expected output

There are eight tests. Each test will have a new set of input data. You must match, exactly, the expected output.Tests 2, 5, 6, and 7 check the output sent to cout. Tests 1, 3, 4, and 8 check the output sent to file saleschart.txt.

You will get yellow highlighted text when you run the tests if your output is not what is expected. This can be because you are not getting the correct result. It could also be because your formatting does not match what is required. The checking that zyBooks does is very exacting and you must match it exactly. More information about what the yellow highlighting means can be found in course "How to use zyBooks" - especially section "1.4 zyLab basics".

Finally, do not include a system("pause"); statement in your program. This will cause your verification steps to fail.

Note: that the system("pause"); command runs the pause command on the computer where the program is running. The pause command is a Windows command. Your program will be run on a server in the cloud. The cloud server may be running a different operating system (such as Linux).

In: Computer Science

Maternal age at childbirth. How old are women when they have their first child? Here is...

Maternal age at childbirth. How old are women when they have their first child? Here is the distribution of the age of the mother for all firstborn children in the United States in a certain year:

NOTE: The numerical values in this problem have been modified for testing purposes.

AGE COUNT AGE COUNT
10 to 14 years 3632 30 to 34 years 300319
15 to 19 years 251381 35 to 39 years 105975
20 to 24 years 460595 40 to 44 years 23967
25 to 29 years 422101 40 to 49 years 1978

(a) For comparison with other years and with other countries, we prefer

a histogram of the counts in each age class
a histogram of the percents in each age class

(b) How many babies were there?


babies

(c) The distribution is:

right-skewed
left-skewed

(d) In which age classes do the median and quartiles fall?

Median fall in:

40 to 44 years
10 to 14 years
45 to 49 years
20 to 24 years
15 to 19 years
25 to 29 years
30 to 34 years
35 to 39 years

Q1 fall in:

20 to 24 years
30 to 34 years
10 to 14 years
35 to 39 years
25 to 29 years
15 to 19 years
45 to 49 years
40 to 44 years

Q3 fall in:

30 to 34 years
20 to 24 years
35 to 39 years
25 to 29 years
40 to 44 years
45 to 49 years
10 to 14 years
15 to 19 years

In: Math

Hi, someone please do every part. I'm desperate!! :( Using RStudio, Create an R-Script: (1) You...

Hi, someone please do every part. I'm desperate!! :(

Using RStudio, Create an R-Script:

(1) You will generate a numeric matrix of size 21 by 21 and will name it tmp. To do so, draw 21×21 = 441 random observations from the standard normal distribution. Before doing so, set the seed for the random number generator to 37. See help for set.seed().

(2) Change the diagonal elements of tmp to 1s.

(3) Calculate condition number of tmp. See help for cond().

(4) Calculate the inverse of tmp. See help for solve().

(5) Calculate the trace of tmp.

(6) Sort tmp across rows.

(7) Delete the last row and last column from tmp and name the submatrix as tmp again.

(8) Reshape tmp as 40 by 10 matrix and name it as tmp1.

(9) Repeat tmp1 four times to generate 40 by 40 array, and name it as tmp2.

(10) Calculate condition number of tmp2.

(11) Calculate the inverse of tmp2.

(12) Change all nonpositive (<= 0) elements of tmp2 to 0.5.

(13) Set the first row and first column element of tmp2 to its negative value.

(14) Now take the natural log of tmp2 and name it as tmp3.

(15) Find the indices for NaN values in tmp3.

In: Statistics and Probability

For the double-pipe heat exchanger of Problem 3.10, calculate the outlet temperatures of the two streams...

For the double-pipe heat exchanger of Problem 3.10, calculate the outlet temperatures of the
two streams when the unit is first placed in service.

Q:3.10
A hydrocarbon stream is to be cooled from 200◦F to 130◦F using 10,800 lb/h of water with
a range of 75–125◦F. A double-pipe heat exchanger comprised of 25 ft long carbon steel
hairpins will be used. The inner and outer pipes are 1.5- and 3.5-in. schedule 40, respectively.
The hydrocarbon will flow through the inner pipe and the heat-transfer coefficient for this
stream has been determined: hi = 200 Btu/h · ft2
·
◦F. Fouling factors of 0.001 h · ft2
·
◦F/Btu
for water and 0.002 h · ft2
·
◦F/Btu for the hydrocarbon are specified. How many hairpins will
be required?

In: Mechanical Engineering

Kyle’s Shoe Stores Inc. is considering opening an additional suburban outlet. An aftertax expected cash flow...

Kyle’s Shoe Stores Inc. is considering opening an additional suburban outlet. An aftertax expected cash flow of $120 per week is anticipated from two stores that are being evaluated. Both stores have positive net present values.
  

Site A Site B
Probability Cash Flows Probability Cash Flows
.2 70 .1 40
.3 120 .2 70
.3 130 .2 120
.2 155 .4 150
.1 180


a. Compute the coefficient of variation for each site. (Do not round intermediate calculations. Round your answers to 3 decimal places.)
  


  
b. Which store site would you select based on the distribution of these cash flows? Use the coefficient of variation as your measure of risk.
  

Site A
Site B

In: Finance

This project will require you to demonstrate proficiency in programming using TCP/IP sockets by writing both...

This project will require you to demonstrate proficiency in programming using TCP/IP sockets by writing both a client program and a server program to provide Roman numeral to Arabic number translation.

The client program must accept the –s servername flag and parameter to specify the hostname of the system running the server process, as well as accept the –p port-number flag and parameter indicating the port on which the server is listening. One (and only one) of the –r or –a flags will be provided by the user indicating Roman to Arabic or Arabic to Roman conversion, respectively. It is up to the client to check that a parameter to the –a flag is numeric and, conversely, a parameter to the –r flag is a string of only Roman numerals.

You will also write a program that runs as a server process and listens on a port specified by the user at execution time. It will read text input from its single network socket (indicated through the –p port-number flag and parameter), translate it and send back the results to the requester. The translation will be from Roman numeral to Arabic number or Arabic number to Roman numeral – the choice of which is indicated by the data sent by the client (numeric or character).

In: Computer Science

A computer operator at the local data processing center decides to visit work on a Monday...

A computer operator at the local data processing center decides to visit work on a Monday evening. She has a key to the outside door, and since there is no key required for the computer room, she simply walks into the computer room. The operator, who is really one of the nation’s most notorious computer programmer/hackers (having been convicted five time for manipulating various firms’ data files), opens the documentation bookcase, located in the corner of the computer room. In the bookcase she finds the procedural documentation, the systems documentation, user manuals, application documentation, and operator manuals. She examines the documentation to understand the payroll program and to find the location of the payroll files. She accesses the information systems library, which is available to all computer operators at all times, accesses the payroll program, reprograms it, and runs a payroll job that creates one electronic funds transfer (to a new account opened by the operator under an assumed name). On Tuesday, the operator transfers the funds to a Swiss bank account and does not show up for work.

        Required

Prepare a summary that details any internal controls violated in this situation.

In: Accounting

1. The pressure exerted by a force on an area is greater when the area is:...

1. The pressure exerted by a force on an area is greater when the area is:
reduced
increased
expanded
None of the above

2. When a fluid is in equilibrium, the vector sum of the vector forces of the vertical forces on the fluid element must be:
A scalar
different from zero
equal to zero
None of the above

3. When a body is submerged in a fluid the sum of forces gives us the force as an equivalence:
normal
tangential
buoyant
None of the above

4. The water runs towards a source filling all the tubes at a constant rate of 0.750 m ^ 3 / s, the speed with which it will come out of a 4.50 cm diameter hole is:
3.58m / s
4.72m / s
5.73m / s
None of the above

5. A barrel contains an oil layer of 0.120 over 0.250 of water. The density of the oil is 600 kg / m ^ 3. The gauge pressure at the oil-water interface is:
760Pa
50Pa
200Pa
None of the above

6. The water flows upwards from a hose in a patio leaving the nozzle at a speed of 15m / s. Using Bernoulli's equation, the height that the water reaches is:
8.50m
10.0m
11.5m
None of the above

7. The hydraulic jack of a car illustrates:
Hooke's Law
Newton's third law
Pascal's principle
None of the above

8. One hydraulic press has a 2.0cm diameter piston and another piston has a 8.0cm diameter. What force must be applied to the smallest piston to balance a 1600N force to the largest piston?
6.25N
25N
400N
None of the above

9. A spruce wood board floats in fresh water with 60% of its volume underwater. Its density in g / cm ^ 3 is:
0.6
0.5
0.4
None of the above

10. Bernoulli's equation is a derivation of the Conservation Law from:
mass
Energy
linear momentum
None of the above

In: Physics

Python Pierrette is at Legoland. She enjoys all the rides but hates to wait in lines....

Python

Pierrette is at Legoland. She enjoys all the rides but hates to wait in lines. Thanks to technology,

she has an app that tells her for each ride i a time ti when there is no line. However, she wants to

take the rides in increasing fun factor order. Pierrette assigns each ride i a fun factor fi . What is

the maximum number of rides she can take?

Make sure that your code runs in O(n2 ) time in order to pass all the test cases (n is the number of

rides)

# [last_name] [first_name], [student_ID]

from typing import List


def max_num_rides(rides: List[List[int]]) -> int:

    """Calculate the maximum number of rides one can take with given constraints.

    Pierrette is at Legoland. She enjoys all the rides but hates to wait in lines.

    Thanks to technology, she has an app that tells her for each ride a time when

    there is no line. However, she wants to take the rides in increasing fun factor

    order. Pierrette assigns each ride a fun factor. This function takes pairs of

    times and fun factors for all the rides, and returns the maximum number of

    rides Pierrette can take.

    Arguments:

        rides (list): A list of [time, fun factor] pairs. For each ride, the rides

            list contains a pair of time and fun factor. Both the time and the fun

            factor are integers. Assume that it takes no time to take a ride. You

            may further assume that all the time values are distinct and all the

            fun factor values are also distinct.

    Returns:

        int: The maximum number of rides Pierrette can take.

    Examples:

        >>> print(max_num_rides([[2, 5], [1, 3]]))

        2

        >>> print(max_num_rides([[4, 2], [42, 3], [59, 8], [12, 4], [1, 5], [5, 7]]))

        3

    """

    pass # FIXME

In: Computer Science

question 8 parts a-e a Returns on stocks X and Y are listed below: Period 1...

question 8 parts a-e

a

Returns on stocks X and Y are listed below:

Period 1 2 3 4 5 6 7
Stock X 8% 0% 3% -2% 5% 12% 7%
Stock Y 5% -2% 4% 7% 1% 12% -3%

What is the correlation of returns on the two stocks?

Please round your answer to the nearest hundredth.

Note that the correct answer will be evaluated based on the full-precision result you would obtain using Excel.

b

Returns on stocks X and Y are listed below:

Period 1 2 3 4 5 6 7
Stock X 6% 5% -2% 10% 3% 8% -4%
Stock Y 11% 7% 10% -2% 3% 5% -1%

Consider a portfolio of 70% stock X and 30% stock Y.

What is the mean of portfolio returns?

Please specify your answer in decimal terms and round your answer to the nearest thousandth (e.g., enter 12.3 percent as 0.123).

c

Returns on stocks X and Y are listed below:

Period 1 2 3 4 5 6 7
Stock X -5% 4% 3% 9% 1% -3% 4%
Stock Y 12% 7% -3% -2% 4% 6% -1%

Consider a portfolio of 60% stock X and 40% stock Y.

What is the (population) variance of portfolio returns?

Please round your answer to six decimal places.

Note that the correct answer will be evaluated based on the full-precision result you would obtain using Excel.

d

Summary statistics for returns on two stocks X and Y are listed below.

Mean Variance
Stock X 2.35% 0.007000
Stock Y 4.53% 0.003000

The covariance of returns on stocks X and Y is 0.002700. Consider a portfolio of 70% stock X and 30% stock Y.

What is the mean of portfolio returns?

Please specify your answer in decimal terms and round your answer to the nearest thousandth (e.g., enter 12.3 percent as 0.123).

e

Summary statistics for returns on two stocks X and Y are listed below.

Mean Variance
Stock X 3.41% 0.003000
Stock Y 5.25% 0.004000

The covariance of returns on stocks X and Y is 0.001800. Consider a portfolio of 20% stock X and 80% stock Y.

What is the variance of portfolio returns?

Please round your answer to six decimal places.

Note that the correct answer will be evaluated based on the full-precision result you would obtain using Excel.

In: Finance