Questions
Please do this operation in "R studio" Please recall the vectors that we created for the...

Please do this operation in "R studio"

Please recall the vectors that we created for the topic "Data Frames".

name = c('Nikola','Albert', 'Marie','Isaac','Graham','Lise', 'Rosalind')
surname = c('Tesla','Einstein','Curie', 'Newton', 'Bell', 'Meitner', 'Franklin')
gender = c('Male','Male','Female','Male','Male','Female','Female')
years = c(87,76,75,84,77,89,81)
field_of_study = c('Engineering','Physics','Chemistry','Physics','Engineering','Physics','Chemistry')

Please check for the function "cut" and use it to create a data frame named "scientists" which has the values

name surname gender years field_of_study years_bin
1 Nikola Tesla Male 87 Engineering (80,90]
2 Albert Einstein Male 76 Physics (70,80]
3 Marie Curie Female 75 Chemistry (70,80]
4 Isaac Newton Male 84 Physics (80,90]
5 Graham Bell Male 77 Engineering (70,80]
6 Lise Meitner Female 89 Physics (80,90]
7 Rosalind Franklin Female 81 Chemistry (80,90]

where "years_bin" attribute is the bin of "years", either "70 to 80" or "80 to 90".

Then please check the function "tapply" to get the averages of the bins like

(70,80] (80,90]
76.00 85.25

Note : Use of functions and methods (such as loops, conditionals) that are not covered yet is forbidden

In: Computer Science

Fill in needed code to finish Mastermind program in Python 3.7 syntax Plays the game of...

Fill in needed code to finish Mastermind program in Python 3.7 syntax

Plays the game of Mastermind.
The computer chooses 4 colored pegs (the code) from the colors
Red, Green, Blue, Yellow, Turquoise, Magenta.
There can be more than one of each color, and order is important.

The player guesses a series of 4 colors (the guess).

The computer compares the guess to the code, and tells the player how
many colors in the guess are correct, and how many are in the correct
place in the code. The hint is printed as a 4-character string, where
* means correct color in correct place
o means correct color in incorrect place
- fills out remaining places to make 4

The player is allowed to make 12 guesses. If the player guesses the colors
in the correct order before all 12 guesses are used, the player wins.

'''

import random


def genCode(items, num):
'''
Generates a random code (a string of num characters)
from the characters available in the string of possible items.
Characters can be repeated

items - a string of the possible items for the code
num - the number of characters in the code
returns the code string
'''
# write function body here

def valid(guess, items, num):
'''
Checks a guess string to see that it is the correct length and composed
of valid characters.

guess - a string representing the guess
items - a string of the possible items for the code
num - the number of characters in the code
returns True if the guess is valid, False otherwise
'''
# write function body here

def getGuess(items, num):
'''
Gets a guess string from the user. If the guess is not valid length and
characters, keeps asking until the guess is valid.

items - a string of the possible items for the code
num - the number of characters in the code
returns the valid guess
'''
# write function body here

def matched(code, guess):
'''
Checks to see that the code and the guess match.

code - the string with the secret code
guess - the string with the player's guess
returns True if they match, False otherwise
'''
# write function body here

def genHint(code, guess, items, num):
'''
Generates a string representing the hint to the user.
Tells the player how many colors in the guess are correct,
and how many are in the correct place in the code.
The hint is printed as a num-character string, where
* means correct color in correct place
o means correct color in incorrect place
- fills out remaining places to make num

code - the string with the secret code
guess - the string with the player's guess
items - a string of the possible items for the code
num - the number of characters in the code/hint
returns the valid hint as a string
'''
# write function body here

# Main program starts here

# colors for the code
colors = 'RGBYTM'
# length of the code
num = 4
# maximum number of guesses allowed
maxGuesses = 12

print('Plays the game of Mastermind.')
print()
print('The computer chooses', num, 'colored pegs (the code) from the colors')
print(colors)
print('There can be more than one of each color, and order is important.')
print()
print('The player guesses a series of', num, 'colors (the guess).')
print()
print('The computer compares the guess to the code, and tells the player how')
print('many colors in the guess are correct, and how many are in the correct')
print('place in the code. The hint is printed as a', num, '-character string, where')
print(' * means correct color in correct place')
print(' o means correct color in incorrect place')
print(' - fills out remaining places to make', num)
print()
print('The player is allowed to make', maxGuesses, 'guesses. If the player guesses the colors')
print('in the correct order before all', maxGuesses, 'guesses are used, the player wins.')

gameOver = False
guesses = 0

code = genCode(colors, num)

while not gameOver:
guess = getGuess(colors, num)
guesses = guesses + 1
  
if matched(code, guess):
print('You win!')
gameOver = True
continue
  
hint = genHint(code, guess, colors, num)
print(hint)

if guesses == maxGuesses:
print('You took to many guesses. The code was', code)
gameOver = True

In: Computer Science

Q1. a. Given a schema R (A, B, C, D, E, F) and a set F...

Q1.
a. Given a schema R (A, B, C, D, E, F) and a set F of functional
dependencies {A → B, A → D, CD → E, CD → F, C → F, C → E, BD → E}, find the closure of the set of functional dependencies ?+

b. Given a schema R = CSJDPQV and a set FDs of functional dependencies FDs = {C → CSJDPQV, SD → P, JP → C, J → S}
1. Find the Canonical (Minimal) Cover set ? ?
2. Check whether the decomposition obtained by computing ? in step 1
in 3NF or not. Justify your answer.

c. Given R = (A, B, C, D) and F = {AB→C, AB→D, C→A, D→B} 1. Is R in 3NF, why? If it is not, decompose it into 3NF
2. Is R in BCNF, why? If it is not, decompose it into BCNF

In: Computer Science

Discover why the conventional routing in wired networks is not suitable for wireless networks? Substantiate your...

Discover why the conventional routing in wired networks is not suitable for wireless networks? Substantiate your answer with suitable examples.

(20marks)
Learning Outcome
Demonstrate the architecture and principle of computer networks with wired and wireless communication.

In: Computer Science

C++ When an object is falling because of gravity, the following formula can be used to...

C++ When an object is falling because of gravity, the following formula can be used to determine the distance that object falls in a specific time period: d = 1/2 g t*t The variables in the formula are as follows: d is the distance in meters g is 9.8 t is the amount of time, in seconds that the object has been falling. Design a function called fallingDistance() that accepts an object's falling time (in seconds) as an argument. The function should return the distance, in meters, that the object has fallen during that time interval. Design a program that calls the function in a loop that passes the values 1 through 10 as arguments and displays the return value. 5 Falling Distance (5 points) Seconds Meters 1.0 4.9 2.0 19.6 3.0 44.1 4.0 78.4 5.0 122.5 6.0 176.4 7.0 240.10000000000002 8.0 313.6 9.0 396.90000000000003 10.0 490.0

In: Computer Science

Instructions: program in C++, add pseudocode and comment throughout the program. Assignment: Create a program to...

Instructions: program in C++, add pseudocode and comment throughout the program.

Assignment:

Create a program to keep track of the statistics for a kid’s soccer team. The program will have a structure that defines what data the program will collect for each of the players.

The structure will keep the following data:

  • Players Name (string)
  • Players Jersey Number (integer)
  • Points scored by Player (integer)

The program will have an array of 12 players (use less for testing and development, use a constant for the size). Each element in the array is a different player on the team.

The program will ask the user to enter information for each player. The program will also display the team information in a table format. After the table, the total points scored by a team will be displayed.

The program will also determine which player scored the most points on the team.

Validation:

  • Do not accept negative value for player’s number
  • Do not accept negative value for player’s score

Required Methods:

  • void GetPlayerInfo(Player &);
  • void ShowPlayerInfo(const Player);
  • int GetTotalPoints(const Player[ ], int);
  • void ShowHighest(Player [ ], int);

In: Computer Science

The following matrix is stored in an array with variable name matrixTest. (? −? ? ?...

The following matrix is stored in an array with variable name matrixTest.

(? −?

? ?

? ? ) i. Write the code to initialize the array.

ii. Write the code to display the content of matrixTest.

*IN C++

In: Computer Science

Using C++: Write a function that recursively calculates the sum of an array. The function should...

Using C++: Write a function that recursively calculates the sum of an array. The function should have 2 parameters, the array and an integer showing the number of elements (assume they are all integers) in the array. The function will use a recursive call to sum the value of all elements.

You must prompt for a series of integers to be entered in the array. As your program reads the numbers in, increment a count so it knows how many elements the array has. Use a symbol for users to indicate when they are done with entering numbers (choose any letter you think is proper, but you need to print it on screen at the beginning to let users know which one to enter). Then your program will print the sum of the array elements on the screen.

In: Computer Science

Which of the following statements describes Data most accurately in its relationship to Information and Knowledge?...

Which of the following statements describes Data most accurately in its relationship to Information and Knowledge?

Data is highly personal to the source

Data is hard to capture electronically

Data has less human contribution

Data has greater value

In: Computer Science

the previous one I saw it, I wonder how to do the last one. Read carefully...

the previous one I saw it, I wonder how to do the last one.

Read carefully
See the photo of the algorithm below after reading these instructions: write a program in Python 3 which uses a list. Your program will use a list to store the names and exam scores of students. The program starts by asking how many results will be entered. Then a loop will be used to enter the name and score for each student. As each name and score is entered it is appended to a list (which was initially empty). When the loop is finished (i.e. all scores are entered) the program ends by printing the list.

Make a copy of your Lab6A.py file to Lab6B.py. Amend the comments accordingly for these instructions. Send the list you created in Lab 6A to a function which returns a list of names of all above average students.

In: Computer Science

WE ARE USING PYTHON TO COMPLETE THIS ASSIGNMENT :) THANK YOU! In this programming assignment, you...

WE ARE USING PYTHON TO COMPLETE THIS ASSIGNMENT :) THANK YOU!

In this programming assignment, you will write functions to encrypt and decrypt messages using simple substitution ciphers. Your solution MUST include:

  • a function called encode that takes two parameters:
    • key, a 26-character long string that identifies the ciphertext mapping for each letter of the alphabet, in order;
    • plaintext, a string of unspecified length that represents the message to be encoded.

    encode will return a string representing the ciphertext.

  • a function called decode that takes two parameters:
    • key, a 26-character long string that identifies the ciphertext mapping for each letter of the alphabet, in order;
    • ciphertext, a string of unspecified length that represents the message to be decoded.

    decode will return a string representing the plaintext.

Copy and paste the following statements into your file as the first two statements of your main program. These lines represent Python lists of messages for you to encode and decode to test the functions you write.

    plaintextMessages = [
        ["This is the plaintext message.",
         "bcdefghijklmnopqrstuvwxyza"],
        ["Let the Wookiee win!",
         "epqomxuagrdwkhnftjizlcbvys"],
        ["Baseball is 90% mental. The other half is physical.\n\t\t- Yogi Berra",
         "hnftjizlcbvysepqomxuagrdwk"],
        ["I used to think I was indecisive, but now I'm not too sure.",
         "mqncdaigyhkxflujzervptobws"],
        ["Einstein's equation 'e = mc squared' shows that mass and\n\t\tenergy are interchangeable.",
         "bludcmhojaifxrkzenpsgqtywv"] ]

    codedMessages = [
        ["Uijt jt uif dpefe nfttbhf.",
         "bcdefghijklmnopqrstuvwxyza"],
        ["Qnhxgomhqm gi 10% bnjd eho 90% omwlignh. - Zghe Xmy",
         "epqomxuagrdwkhnftjizlcbvys"],
        ["Ulj njxu htgcfj C'gj jgjm mjfjcgjt cx, 'Ep pej jyxj veprx rlhu\n\t\t uljw'mj tpcez jculjm'. - Mcfvw Zjmghcx",
         "hnftjizlcbvysepqomxuagrdwk"],
        ["M 2-wdme uxc yr kylc ua xykd m qxdlcde, qpv wup cul'v gmtd mlw\n\t\t vuj aue yv. - Hdeew Rdyladxc",
         "mqncdaigyhkxflujzervptobws"] ]

You may alter the spacing or indentation of the two lines to conform to the rest of your code, but you are not allowed to change the strings or structure of the lists.

plaintextMessages is a list consisting of five items. Each item is a list of two strings corresponding to a plaintext message and a key. For each of these five items, you should:

  • print the plaintext message.
  • encode the message and print the ciphertext.
  • decode the ciphertext message you just calculated and print the plaintext message again. The purpose of this is to demonstrate that your encode and decode functions work properly as inverses of each other.

If you have done this correctly, the output from your program for the first data item should look like the following:

plaintext:   This is the plaintext message.
encoded:     Uijt jt uif qmbjoufyu nfttbhf.
re-decoded:  This is the plaintext message.

Then print a blank line to separate this block of three lines from the next block.

codedMessages is a list consisting of four items. Each item is a list of two strings corresponding to a ciphertext message and a key. For each of these four items, you should:

  • print the ciphertext message.
  • decode the message and print the ciphertext.

If you have done this correctly, the output from your program for the first data item should look like the following:

encoded:  Uijt jt uif dpefe nfttbhf.
decoded:  

Then print a blank line to separate this block of two lines from the next block.

Special notes:

  • Encrypted and decrypted lower-case letters should map to lower-case letters, as defined by the key.
  • Encrypted and decrypted upper-case letters should map to upper-case letters. Note that upper-case letters do not appear in the key! (Look at the first character in the expected output shown above: the upper-case "T" maps to an upper-case "U" in the encoded message.) Your program must detect when an upper-case letter appears in the data, and figure out how to convert it to the correct upper-case letter based on the corresponding lower-case letters in the key.
  • Non-alphabetic characters, such as numbers, spaces, tabs, punctuation, etc. should not be changed by either encode() or decode().

In: Computer Science

LP3.1 Assignment: Using Advanced SQL This assignment will assess the competency 3. Construct advanced SQL queries....

LP3.1 Assignment: Using Advanced SQL

This assignment will assess the competency 3. Construct advanced SQL queries.

Directions: Using the sample dataset, create three queries including a search, outer join and subquery. Create a table on how to use the query optimizer with these queries. Include screenshots and an explanation on why and when to use the optimizer.

.

In: Computer Science

You are given two arrays A1 and A2, each with n elements sorted in increasing order....

You are given two arrays A1 and A2, each with n elements sorted in increasing order. For simplicity, you may assume that the keys are all distinct from each other. Describe an o(log n) time algorithm to find the (n/2) th smallest of the 2n keys assuming that n is even.

In: Computer Science

You are to modify the Pez class so that all errors are handled by exceptions. The...

You are to modify the Pez class so that all errors are handled by exceptions. The constructor must be able to handle invalid parameters. The user should not be able to get a piece of candy when the Pez is empty. The user should not be able to put in more candy than the Pez can hold. I would like you to do 3 types of exceptions. One handled within the class itself, one handled by the calling method and one custom made exception. Be sure to comment in the program identifying each type of exception. You have the freedom of choosing which exception style you use where. You will need to submit 3 files, the Pez class, the custom exception class, and a tester program demonstrating that all of your exceptions work properly.

public class Pez
{
  private int candy;
  private final int MAX_PIECES = 12;
  
  public Pez()
  {
    candy = 0;
  }
  
  public Pez(int pieces) //this will need to be error-proofed
  {
    candy = pieces;
  }
  
  public int getCandy() 
  {
    return candy;
  }
  
  public void setCandy(int pieces) //this will need to be error-proofed
  {
    candy = pieces;
  }
  
  public void getAPieceOfCandy() //this will need to be error-proofed
  {
    candy = candy - 1;
  }
  
  public int fillPez() 
  {
    int piecesNeeded = MAX_PIECES - candy;
    candy = MAX_PIECES;
    return piecesNeeded;
  }
  
  public int emptyPez()
  {
    int currentPieces = candy;
    candy = 0;
    return currentPieces;
  }
  
  public void addPieces(int pieces) //this will need to be error-proofed
  {
      candy = candy + pieces;
  }
 
  public String toString()
  {
    String thisPez = "This Pez has " + candy + " pieces of candy";
    return thisPez;
  }
  
  public boolean equals(Pez pez2)
  {
    if(this.candy == pez2.candy)
      return true;
    return false;
  }
      
}

In: Computer Science

This code must be written in Java. This code also needs to include a package and...

This code must be written in Java. This code also needs to include a package and a public static void main(String[] args)

Write a program named DayOfWeek that computes the day of the week for any date entered by the user. The user will be prompted to enter a month, day, and year. The program will then display the day of the week (Sunday..Saturday). The following example shows what the user will see on the screen:

This program calculates the day of the week for any dates.

Enter month (1-12): 9

Enter day (1-31): 25

Enter year: 1998

The day of the week is Friday.

Hint: Use Zeller's congruence to compute the day of the week. Zeller's congruence relies on the following quantities:

J is the century (19, in our example)

K is the year within the century (98, in our example)

m is the month (9, in our example)

q is the day of the month (25, in our example)

The day of the week is determined by the following formula:

h = (q + 26(m + 1) / 10 + K + K / 4 + J / 4 + 5J) mod 7

where the results of the divisions are truncated. The value of h will lie between 0 (Saturday) and 6 (Friday).

Note: Zeller's congruence assumes that January and February are treated as months 13 and 14 of the previous year; this affects the values of K and m, and possibly the value of J. Note that the value of h does not match the desired output of the program, so some adjustment will be necessary. Apply Exception Handling.

In: Computer Science