Questions
Given the declaration                         char table[7][9];              &nb

  1. Given the declaration

           

            char table[7][9];

           

                which of the following stores the character 'B' into the fifth row and second column of the array?

            A) table[5] = 'B';

            B)   table[2][5] = 'B';

            C)   table[5][2] = 'B';

            D) table[1][4] = 'B';

            E)   table[4][1] = 'B';

  1. This program fragment is intended to zero out a two-dimensional array:

int arr[10][20];

            int i, j;

           

            for (i = 0; i < 10; i++)

                  for (j = 0; j < 20; j++)

                      // Statement is missing here

           

                What is the missing statement?

            A) arr[j+1][i+1] = 0;

            B)   arr[i-1][j-1] = 0;

            C)   arr[i+1][j+1] = 0;

            D) arr[i][j] = 0;

            E)   arr[j][i] = 0;

3. Given this nested For loops

  for (i = 0; i < M; i++)

                  for (j = 0; j < N; j++)

                      cout << arr[i][j];

           

                what is the appropriate declaration for arr?

            A) int arr[M+N];

            B)   int arr[M+1][N+1];

            C)   int arr[M][N];

            D) int arr[N][M];

            E)   int arr[N+1][M+1];

  1. Given the declarations

           

            float alpha[5][50];

            float sum = 0.0;

           

                which one computes the sum of the elements in row 2 of alpha?

            A) for (i = 0; i < 50; i++)

                           sum = sum + alpha[2][i];

            B)   for (i = 0; i < 5; i++)

                           sum = sum + alpha[2][i];

            C)   for (i = 0; i < 50; i++)

                           sum = sum + alpha[i][2];

            D) for (i = 0; i < 5; i++)

                           sum = sum + alpha[i][2];

  1. Look at the following array definition.

int numberArray[9][11];

Write a statement that assigns 130 to the first column of the second row of this array.

  1. Write a statement which will assign 18 to the last column of the last row of this array.

Values is a two-dimensional array of floats that include 10 rows and 20 columns. Write a

code that sums all the elements in the array and stores the sum in the variable named total.

In: Computer Science

What are some tips and best practices on how to use sets and maps properly in...

What are some tips and best practices on how to use sets and maps properly in C++? Please provide two examples.

In: Computer Science

Includes you will need: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <signal.h> #include <sys/wait.h> Create a...

Includes you will need:

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <signal.h>

#include <sys/wait.h>

Create a .c file that does the following:

1. Use fork() to create a 2nd process, using the if checks we’ve seen to determine if you’re the child or the parent. Print a message from each process saying who is who. (APUE chapter 1/7)

• Note: The parent should save the pid_t of the child (returned from fork()) for later.

2. Have the child register a signal handler for SIGTERM using the method we saw. Have your SIGTERM handler print a message and then call exit(). (APUE chapter 10)

• Hint: functions in C need to be declared before they are used. Normally this happens in a header file, but within your .c file you have two options: •Implement the function above main().

• Put a function signature above main, such as static void mySignalHandler(int);, and then implement the function below main.

3. Have the child go to sleep using this code (which will keep it asleep indefinitely): for ( ; ; ) { pause(); }

4. Have the parent sleep for 5 seconds sleep(5); (an imperfect way to ensure that the child has time to register its signal handler), then use the kill() command to send SIGTERM to the child. Note that SIGTERM is a defined constant; you don’t need to look up the number. (APUE chapter 10)

5. Have the parent do a waitpid(…) on the child’s pid (which should come back quickly since we just asked him to exit). Print a message saying that the child has exited. (APUE chapter 8)

6. Have the parent register an atexit() function that prints a message as you exit. (APUE chapter 7)

7. Let the parent exit (fall out of main, return from main, or call exit()).

What should happen when you run the program:

• The parent and child will print who is who (in either order, or even with characters overlapping—this is okay).

• After 5 seconds, you should see the message from the child’s signal handler (#2 above).

• Right after that you should see the message saying that the child has exited (#5 above).

• Right after that you should see the message from atexit() (#6 above).

In: Computer Science

I'm supposed to create a c++ program which is supposed to take a sentence as an...

I'm supposed to create a c++ program which is supposed to take a sentence as an input and then output a sorted list of the occurrence of each letter.

ex.

Enter a phrase: It's a hard knock life

A2

I2
K2

C1

D1

E1

F1

H1

L1

N1

O1

R1

S1

T1

I was also given a recommended code to use as a bubble sort

procedure bubbleSort( A : list of sortable items )

n = length(A)
repeat

swapped = false

for i = 1 to n-1 inclusive do

/* if this pair is out of order */ if A[i-1] > A[i] then

/* swap them and remember something changed */ swap( A[i-1], A[i] )
swapped = true

end if end for

until not swapped

end procedure

In: Computer Science

*Python Stock Exchange Data Problem Expected Duration: 3-6 hours A comma-separated value file stocks_data.csv contains historical...

*Python

Stock Exchange Data

Problem

Expected Duration: 3-6 hours

A comma-separated value file stocks_data.csv contains historical data on the Adjusted Closing Price for 3 stocks daily from Jan 2, 2009 to Dec 31,2018. The stocks are Apple (APPL), Microsoft (MSFT) and IBM (IBM).

A snippet from the data file looks like the following:

Symbol Date Adj. Close
MSFT 4/16/2014 35.807358
MSFT 6/21/2010 20.752356
IBM 2/10/2009 68.930023
AAPL 2/14/2018 164.227203
IBM 6/13/2017 141.24379
IBM 12/26/2017 142.835663
MSFT 4/1/2009 15.053272
AAPL 4/17/2009 15.445643

You can see that each row has a symbol, date and closing price, but the stock data is not sorted by symbol, date or price.

Your task has two main parts:

Part I

For each stock, print the following information to the console and to a text file called stock_summary.txt:

  1. the max price and date it occurs
  2. the min price and date it occurs
  3. the average (mean) price

Part 2

Print to the console and append to the output file stock_summary.txt:

  1. The stock among the 3 with the highest overall closing price and its date
  2. The stock among the 3 with the lowest overall closing price and its date

Example output looks like the following. Your output must match the format, but replace the placeholders with specific values.

AAPL
----
Max: price date
Min: price date
Ave: mean

IBM
----
Max: price  date
Min: price date
Ave: mean

MSFT
----
Max: price  date
Min: price date
Ave: mean

Highest: Symbol price date
Lowest: Symbol price date

Tests

This project has a rubric that matches these test cases, and is used for grading.
Your instructor may also use automated unit test code and/or pylint for grading.

  1. load data from csv input file
  2. if the input file does not exist, print "file does not exist." and exit.
  3. generate summary data for each stock (counts as 1 test case, all correct for this to count)
  4. compute the highest of all stocks and compute the lowest of all the stocks
  5. use functions to minimize obvious repeated code
  6. write same correct output to file stock_summary.txt and console
  7. use loops in code to eliminate repeated code
  8. use appropriate modules and builtin functions to simplify code
  9. Code has a main function with conditional execution.
  10. File has a module docstring with required information in it.
  11. Code follows PEP8 Python Style guide for code style (not your book's Java style)
  12. Thonny's Assistant or pylint says your code is OK, no warnings.

I am really hoping that you can leave a lot of comments on how you do this because I want to learn how to do it. If you can, can you focus on #5 above? use functions to minimize obvious repeated code. Thanks for your help!

In: Computer Science

Write the RE for identifiers that can consist of any sequence of letters (l) or digit...

Write the RE for identifiers that can consist of any sequence of letters (l) or digit (d) or "_" but the first char must be a letter and the last char cannot be a "_"

In: Computer Science

Intro to Python I'm getting trouble obtaining the solution for the following questions: "How many babies...

Intro to Python

I'm getting trouble obtaining the solution for the following questions:

"How many babies were born with names starting with that least-common letter?" For the file used it is "U"

"How many babies were born with names starting with that-common letter"? For the file used it is "A"

"How many people have that name?" (This follows the question "By default, the Social Security Administration's data separates out names by gender. For example, Jamie is listed separately for girls and for boys. If you were to remove this separation, what would be the most common name in the 2010s regardless of gender?" And the file I used it is "Isabella")

"What name that is used for both genders has the smallest difference in which gender holds the name most frequently? In case of a tie, enter any one of the correct answers."

This is the problem:

#-----------------------------------------------------------
#The United States Social Security Administration publishes
#a list of all documented baby names each year, along with
#how often each name was used for boys and for girls. The
#list is used to see what names are most common in a given
#year.
#
#We've grabbed that data for any name used more than 25
#times, and provided it to you in a file called
#babynames.csv. The line below will open the file:

names_file = open('../resource/lib/public/babynames.csv', 'r')

#We've also provided a sample subset of the data in
#sample.csv.
#
#Each line of the file has three values, separated by
#commas. The first value is the name; the second value is
#the number of times the name was given in the 2010s (so
#far); and the third value is whether that count
#corresponds to girls or boys. Note that if a name is
#given to both girls and boys, it is listed twice: for
#example, so far in the 2010s, the name Jamie has been
#given to 611 boys and 1545 girls.
#
#Use this dataset to answer the questions below.


#Here, add any code you want to allow you to answer the
#questions asked below over on edX. This is just a sandbox
#for you to explore the dataset: nothing is required for
#submission here.

//

This is the format of the file but this is not file the problem is based on:

Isabella,42567,Girl
Sophia,42261,Girl
Jacob,42164,Boy
Emma,35951,Girl
Ethan,34523,Boy
Mason,34195,Boy
William,34130,Boy
Olivia,34128,Girl
Jayden,33962,Boy
Ava,30765,Girl

I found the solution and it's this:

baby_list=[]

for line in names_file:
line=line.strip().split(",")
name=line[0]
count=int(line[1])
gender=line[2]
baby_list.append([name,count,gender])

#How many total names are listed in the database?
print('Total names:',len(baby_list))

#How many total births are covered by the names in the database?
births=0
for data in baby_list:
births=births+data[1]

print('total births:',births)

#How many different boys' names are there that begin with the letter Z?
#(Count the names, not the people.)
names_with_z=0
for data in baby_list:
if data[0][0]=='Z' and data[2]=='Boy':
names_with_z=names_with_z+1

print('Different boys names are there that begin with the letter Z:',names_with_z)

#What is the most common girl's name that begins with the letter Q?
names_with_Q=0
for data in baby_list:
if data[0][0]=='Q' and data[2]=='Girl' and data[1]> names_with_Q:
girl_name=data[0]
names_with_Q=data[1]

print('The most common girl\'s name that begins with the letter Q:',names_with_Q)

#How many total babies were given names that both start and end with vowels (A, E, I, O, or U)?
vowels='AEIOUaeiou'
total_names=0
for data in baby_list:
if data[0][0] in vowels and data[0][-1] in vowels:
total_names=total_names+ data[1]

print('The total babies were given names that both start and end with vowels(A,E,I,O,or U):'\
,total_names)

#Here, add any code you want to allow you to answer the
#questions asked below over on edX. This is just a sandbox
#for you to explore the dataset: nothing is required for
#submission here.

#What letter is the least common first letter of a baby's name
name_list = {}
for i in range(len(baby_list)):
fl = list(baby_list[i][0])[0]
if fl not in name_list.keys():
name_list[fl] = 1
else:
name_list[fl] = int(name_list[fl]) + 1
#What letter is the least common first letter of a baby's name
leastKey = 9999
mostKey = 0
least=''
most=''
print(name_list.keys())
for key in name_list.keys():
if name_list[key] < leastKey:
least = key
leastKey = name_list[key]
if name_list[key] > mostKey:
most = key
mostKey = name_list[key]
print('\nThe letter is the least common first letter of a baby\'s name is: ',least)
#How many babies were born with names starting with that least-common letter?
print('\nNumber of babie names starting with that least-common letter',name_list[least])
#What letter is the most common first letter of a baby's name
print("\nThe letter is the most common first letter of a baby's name is: ",most)
#How many babies were born with names starting with that most-common letter?
print('\nNumber of babie names starting with that most-common letter: ',name_list[most])

'''
#By default, the Social Security Administration's data separates out names by gender.
#For example, Jamie is listed separately for girls and for boys.
#If you were to remove this separation, what would be the most common name
in the 2010s regardless of gender?
'''
name_list = {}
for i in range(len(baby_list)):
name = baby_list[i][0]
ctr = baby_list[i][1]
gndr = baby_list[i][2]
if name in name_list.keys():
name_list[name] = int(name_list[name]) + 1
else:
name_list[name] = 1
mostKey = 0
most=''
for key in name_list.keys():
if name_list[key] > mostKey:
most = key
mostKey = name_list[key]
print('\nThe most common name in the 2010s regardless of gender: ',most)

#How many people would have that name?
print('\nThe number of people have most common name regardless of gender: ',mostKey)

'''
What name that is used for both genders has the smallest difference in
which gender holds the name most frequently? In case of a tie,
enter any one of the correct answers.
'''
mini = name_list[most]
name_list = {}
for i in range(len(baby_list)):
name = baby_list[i][0]
ctr = baby_list[i][1]
gndr = baby_list[i][2]
if name in name_list.keys() and gndr != name_list[name][1]:
name_list[name] = [int(name_list[name][0]) -1, gndr, 1]
else:
name_list[name] = [1, gndr, 0]

for x in name_list.keys():
if name_list[x][2] == 1 and name_list[x][0] < mini:
mini = name_list[x][0]
nme = x
print('Name that is used for both genders has the smallest difference: ',x)

In: Computer Science

What is the role of software security testing in the process of finding solutions to system...

What is the role of software security testing in the process of finding solutions to system vulnerabilities

In: Computer Science

Write a function bracket_by_len that takes a word as an input argument and returns the word...

Write a function bracket_by_len that takes a word as an input argument and returns the word bracketed to indicate its length. Words less than five characters long are bracketed with << >>, words five to ten letters long are bracketed with (* *), and words over ten characters long are bracketed with /+ +/. Your function should require the calling function to provide as the first argument, space for the result, and as the third argument, the amount of space available.

Program: C

In: Computer Science

One way to determine how healthy a person is by measuring the body fat of the...

One way to determine how healthy a person is by measuring the body fat of the person.
The formulas to determine the body fat for female and male are as follows:

Body fat formula for women:

  • A1 = Body Weight * 0.732 + 8.987
  • A2 = Wrist Measurement At Fullest Point / 3.140
  • A3 = Waist Measurement At Navel * 0.157
  • A4 = Hip Measurement At Fullest Point * 0.249
  • A5 = Forearm Measurement At Fullest Point * 0.434
  • B = A1 + A2 - A3 - A4 + A5
  • Body Fat = Body Weight - B
  • Body Fat Percentage = Body Fat * 100 / Body Weight

Body fat formula for men:

  • A1 = Body Weight * 1.082 + 94.42
  • A2 = Waist Measurement At Fullest Point * 4.15
  • B = A1 - A2
  • Body Fat = body Weight - B;
  • Body Fat Percentage = Body Fat * 100 / body Weight

In C program

Write a program that asks for the gender and the all the input appropriate to the gender, then calculate and display the Body Fat and Body Fat Percentage.

Example (Numbers and symbols with underscore indicate an input):

This program determines the body fat of a person.

Enter your gender (f|F|m|M): F

Enter body weight (in pounds): 120

Enter wrist measurement at fullest point (in inches): 5

Enter waist measurement at navel (in inches): 32

Enter hip measurement at fullest point (in inches): 36

Enter forearm measurement at fullest point (in inches): 23

Body fat: 25.586643
Body fat percentage: 21.322203

--------------------------------------------

This program determines the body fat of a person.

Enter your gender (f|F|m|M): m

Enter body weight (in pounds): 120

Enter waist measurement at fullest point (in inches): 5

Body fat: -83.510000
Body fat percentage: -69.591667

In: Computer Science

please write a C program that implements Quick Sort algorithm.

please write a C program that implements Quick Sort algorithm.

In: Computer Science

Prove the following Closure Properties with respect to Context Free Languages. 1. Show that Context Free...

Prove the following Closure Properties with respect to Context Free Languages.

1. Show that Context Free Languages are Closed under union(∪), concatenation(·), kleene star(*).

(Hint: If L1 and L2 are Context Free languages then write Context Free grammar equivalent to L1 ∪ L2, L1 · L2, L∗ 1 )

2. Show that if L1 and L2 are Context Free Languages, then L1 ∩ L2 is not necessarily Context Free.

(Hint: Use Proof by Counter Example)

In: Computer Science

1.1 Describe the Marching Cubes algorithm using pseudo-code. What are potential issues of Marching Cubes. (I...

1.1 Describe the Marching Cubes algorithm using pseudo-code. What are potential issues of Marching Cubes.
(I need pseudo code explaination)

In: Computer Science

JAVA MASTERMIND The computer will randomly select a four-character mastercode. Each character represents the first letter...

JAVA MASTERMIND

The computer will randomly select a four-character mastercode. Each character represents the first letter of a color from the valid color set. Our valid color choices will be: (R)ed, (G)reen, (B)lue and (Y)ellow. Any four-character combination from the valid color set could become the mastercode. For example, a valid mastercode might be: RGBB or YYYR.

The game begins with the computer randomly selecting a mastercode. The user is then given up to 6 tries to guess the mastercode. The user must guess the correct color sequence in the correct order. After each user guess, the computer responds indicating how many colors the user guessed correctly and how many of those were in the correct position. This information helps the user make a better (and hopefully more accurate) guess. If the user correctly guesses the code in 6 tries or less, the user wins the round. Otherwise, the user loses the round. After each round, the user is given the option to play another round, at which point the game either continues or ends. When the game is completely finished, some overall playing statistics should be displayed. This includes how many rounds the user won as well as lost, in addition to the user's overall winning percentage.

Sample Run

WELCOME TO MASTERMIND

<-- blank line

How to Play:

1. I will pick a 4 character color code out of the following colors: Yellow, Blue, Red, Green.

2. You try to guess the code using only the first letter of any color. Example if you type YGBR that means you guess Yellow, Green, Blue, Red.

3. I will tell you if you guessed any colors correct and whether or not you guess them in the right order.

<-- blank line

LET'S PLAY!

<-- blank line

Ok, I've selected my secret code. Try and guess it.

<--- Blank line

Enter guess #1 (e.g., YBRG ): ZZZZZ

Please enter a valid guess of correct length and colors

<--- Blank line

Enter guess #1 (e.g., YBRG ): YYYY

You have 2 colors correct

2 are in the correct position

<--- Blank line

Enter guess #2 (e.g., YBRG ): YBYY

You have 3 colors correct

3 are in the correct position

Enter guess #3 (e.g., YBRG ): YBYR

You have 3 colors correct

3 are in the correct position

Enter guess #4 (e.g., YBRG ): YBYG

You have 3 colors correct

3 are in the correct position

Enter guess #5 (e.g., YBRG ): YBYR

You have 3 colors correct

3 are in the correct position

Enter guess #6 (e.g., YBRG ): YBYB

That's correct! You win this round. Bet you can't do it again!

Play again (Y/N)? k

Please enter a valid response (Y/N):

Y

<--- Blank line

Ok, I've selected my secret code. Try and guess it.

<--- Blank line

Enter guess #1 (e.g., YBRG ): GBYG

That's correct! You win this round. Bet you can't do it again!

Play again (Y/N)? N

<--- Blank line

YOUR FINAL STATS:

Rounds Played: 2

Won: 2 Lost: 0

Winning Pct: 100.00%

Sample Run (user does not win)

<-- user makes several bad guesses before the output below

Enter guess #6 (e.g., YBRG ): yyyy

You have 1 colors correct

1 are in the correct position

No more guesses. Sorry you lose. My sequence was YRRR

Play again (Y/N)?

Required Decomposition

  1. displayInstructions() - Displays the welcome message and game instructions.
  2. getRandomColor() - Accepts a random object as a parameter and returns a single character representing the first letter of the valid color set (R, G, B or Y). You can accomplish this by generating a random number 1-4 and then having each number correlate to a character representing a color.
  3. buildMasterCode() - Accepts a random object as a parameter and returns a String representing the random 4-character mastercode selected by the computer. There is one important caveat. You are not allowed to return a masterCode of YYYY from this method. Should such a mastercode be generated, you must re-generate a different mastercode until you have one that is not equal to YYYY. This methods calls getRandomColor() multiple times to assist in building the string.
  4. displayStats() - Accepts two int parameters representing how many rounds were played as well as how many times the user won the round. Displays number of times the user the won and lost as well as the user's winning percentage. For the winning percentage, it should be displayed using a printf with two decimal places and accommodate printing up to a possible perfect winning percentage of 100%.
  5. isValidColor() - Accepts a char parameter and returns true if the character represents the first letter of a valid color set (R, G, B, Y) and false otherwise.
  6. isValidGuess() - Accepts a String parameter representing the user's guess at the mastercode. Returns true if the user's guess is a valid guess of correct length with valid values from the color set and false otherwise. Note that being a valid guess has nothing to do with the guess being correct. We are strictly talking about validity with respect to the length and color choices. A valid guess is any string of four characters long containing valid color codes after all spaces have been removed (in other words, "Y B R G" is a valid guess once the spaces have been removed). This method will call isValidColor() to assist in validating the user's guess.
  7. getValidGuess() -- Accepts two parameters, a Scanner object for reading user input and an int value representing which number guess this is for the user (the user only gets 6 guesses). This method reads the user guess and validates it (uppercase or lowercase is acceptable). If the guess is not a valid guess, an error message is displayed and the user prompted again for a valid guess. This method calls isValidGuess() to assist in validating the user's input and removing whitespace. This method returns a validated String representing the user's guess to the calling method.
  8. countCorrectColors() - Accepts two String parameters representing the mastercode and the guess. Returns an int value representing the number of colors guessed correctly by the user as compared to the mastercode irrespective of whether or not those colors are in the correct position.
  9. countCorrectPositions() - Accepts two String parameters representing the mastercode and the guess. Returns an int value representing the number of colors guessed correctly in their correct position by the user as compared to the mastercode.
  10. checkGuess() - Accepts two String parameters representing the mastercode and the guess. Returns a boolean value indicating whether or not the user won the round based upon their guess. If the user did not win the round, the user should be informed how many colors they guessed correctly and whether any of those were in the correct position. This method calls countCorrectColors() and countCorrectPositions() to assist in determining what information to display to the user.
  11. playOneRound() - Accepts a Scanner object and a String representing the masterCode. Returns a boolean indicating whether or not the user won this round. Allows the user up to 6 guesses before the user automatically loses the round. This method calls getValidGuess() and checkGuess() to assist in processing the user's guess.
  12. getUserChoice() - Accepts a Scanner object and returns a character representing a valid user's choice as to whether or not they would like to play another round. Valid choices are Y or N, but naturally you should let the user enter this in lower or uppercase.
  13. main() - The main is the controlling method or manager of the game, continuing to play a new round of mastermind until the user decides to quit the game. Once the game has ended, the stats should be displayed.

In: Computer Science

You are implementing a brand new type of ATM that provides exact amounts of cash (bills...

You are implementing a brand new type of ATM that provides exact amounts of cash (bills only, no coins). In order to maximize potential revenue an algorithm is needed that will allow for using different denomination amounts as needed by the local currency (value of bills will vary, but are integers).

  1. The program shall graphically prompt the user for a file.

  2. The program shall read the selected file of which the first line will be a space separated list of the

    bill denomination sizes.

  3. The program shall then read each line in the rest of the file containing an integer and output the

    number of different ways to produce that value using the denominations listed in the first line.

  4. The program shall indicate after that the number of milliseconds the program spent calculating

    the answer.

  5. The program shall implement 2 different forms of the algorithm: 1 recursive and 1 using dynamic

    programming.

  6. The program shall have 2 sets of output, 1 for each implementation.

  7. The program shall write the output to a file in the same directory as the input file.

  8. The program must be written in Java.

In: Computer Science