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';
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];
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];
int numberArray[9][11];
Write a statement that assigns 130 to the first column of the second 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 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 .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 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 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:
Part 2
Print to the console and append to the output file stock_summary.txt:
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.
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 (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 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 vulnerabilities
In: Computer Science
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 person.
The formulas to determine the body fat for female and male are as
follows:
Body fat formula for women:
Body fat formula for men:
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.
In: Computer Science
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 need pseudo code explaination)
In: Computer Science
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
In: Computer Science
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).
The program shall graphically prompt the user for a file.
The program shall read the selected file of which the first line will be a space separated list of the
bill denomination sizes.
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.
The program shall indicate after that the number of milliseconds the program spent calculating
the answer.
The program shall implement 2 different forms of the algorithm: 1 recursive and 1 using dynamic
programming.
The program shall have 2 sets of output, 1 for each implementation.
The program shall write the output to a file in the same directory as the input file.
The program must be written in Java.
In: Computer Science