Questions
Section 6.9 of your textbook ("Debugging") lists three possibilities to consider if a function is not...

Section 6.9 of your textbook ("Debugging") lists three possibilities to consider if a function is not working.

Breaking a large program into smaller functions creates natural check points for debugging. If a function is not working, there are three possibilities to consider:
• There is something wrong with the arguments the function is getting; a precondition is violated.
• There is something wrong with the function; a postcondition is violated.
• There is something wrong with the return value or the way it is being used.

1. Describe each possibility in your own words.

2. Define "precondition" and "postcondition" as part of your description.

3. Create your own example of each possibility in Python code. List the code for each example, along with sample output from trying to run it.

In: Computer Science

Python: Using Inheritance to Create a Derived Class in Python In this lab, you create a...

Python: Using Inheritance to Create a Derived Class in Python

In this lab, you create a derived class from a base class, and then use the derived class in a Python program. The program should create two Motorcycle objects, and then set the Motorcycle’s speed, accelerate the Motorcycle object, and check its sidecar status.

Instructions

  1. Open the file named Motorcycle.py.
  2. Create the Motorcycle class by deriving it from the Vehicle class. Use a public derivation.
  3. In the Motorcycle class, create an attribute named sidecar.
  4. Write a public set method to set the value for sidecar.
  5. Write a public get method to retrieve the value of sidecar.
  6. Write a public accelerate method. This method overrides the accelerate method inherited from the Vehicle class. Change the message in the accelerate method so the following is displayed when the Motorcycle tries to accelerate beyond its maximum speed: "This motorcycle cannot go that fast".
  7. Open the file named MyMotorcycleClassProgram.py.
  8. In the MyMotorcycleClassProgram, there are two Motorcycle objects named motorcycleOne and motorcycleTwo.
  9. Set the sidecar value of motorcycleOne to true and the sidecar value of motorcycleTwo to false.
  10. Set motorcycleOne’s maximum speed to 90 and motorcycleTwo’s maximum speed to 85.
  11. Set motorcycleOne’s current speed to 65 and motorcycleTwo’s current speed to 60.
  12. Accelerate motorcycleOne by 30 mph, and accelerate motorcycleTwo by 20 mph.
  13. Print the current speed of motorcycleOne and motorcycleTwo.
  14. Determine if motorcycleOne and motorcycleTwo have sidecars. If yes, display the following: "This motorcycle has a sidecar". If not, display the following: "This motorcycle does not have a sidecar".
  15. Execute the program.

In: Computer Science

Create properly formatted script file (Initials_Final_pb_02.m) that will prompt the user to input a 1-D array...

Create properly formatted script file (Initials_Final_pb_02.m) that will prompt the user to input a 1-D array of numbers (positive, negative, zero) and then use loop and conditional statement to find the number of all non-zero elements in this array and their products

Do NOT use the built-in commands such as sum, prod, length, size, … etc.

-        Use proper names for input and output variables.

Use the following 3 vectors to test your function and include the results as a commented text at the end of your script file. [3 -1 0 -4 2], [10 -15 20 -15 0], [1 0 -2 5 -2 3]

Format the output using fprintf similar to the following:

There are 4 non-zero numbers and their product is 24

In: Computer Science

1. What is output by the following C++ code segment? Assume myList is an initially empty...

1. What is output by the following C++ code segment? Assume myList is an initially empty linked list that can store floats. Draw the linked list (with head, nodes, and pointers) to show how it looks conceptually by the time the code completes executing.

FloatList myList;

myList.insertNode(5.25);

myList.insertNode(2.14);

myList.appendNode(9.11);

for (int x = 1; x < 4; x++)

   myList.insertNode(x * 0.1);

myList.deleteNode(2.14);

myList.displayList();

Output:

Linked list drawing:

In: Computer Science

Exercise3: GuessingGame.cpp Write a program that plays a game where the computer generates a random number...

Exercise3: GuessingGame.cpp

  • Write a program that plays a game where the computer generates a random number between 1 and 100, and then lets the computer guess the right number.
  • For each guess the program should display “too high” or “too low”, and then adjust the min and max of the next guess accordingly until either the correct number is guessed (game won) or 10 guesses are made without finding the right number (game lost).
  • When a game is won, display the number of guesses that were made to arrive at the correct answer.
  • Allow the user to determine how many games are played.
  • When the user wants to stop, display the total number of games played, the number of games won, the number of games lost, and the average number of guesses it took to find the correct number.

In: Computer Science

Search online to find an incident of cybercrime (not included in the readings) or create one...

Search online to find an incident of cybercrime (not included in the readings) or create one yourself. Please describe the event and explain which theory from the week’s readings can be used to explain the cybercrime. Why do you think so? Write a 1 to 2 page paper answering these questions. Choose a cybercrime with a real-world example of a cybercrime and use either the routine activities or rational choice theory to examine the facts of the crime.

In: Computer Science

Consider the following substitution block cipher: Plain-text 000 110 001 100 010 111 011 001 100...

Consider the following substitution block cipher:

Plain-text

  1. 000 110

  2. 001 100

  1. 010 111

  2. 011 001

  1. 100 101

  2. 101 000

  1. 110 010

  2. 111 011

Cipher-text

[10]

                 

Compute the cipher-text belonging to plaintext 001 110 000 101 110 (using a block size of 3 bits) for the Electronic Code Book (ECB) mode and Cipher Block Chaining (CBC) mode taking IV = 111. Show the intermediate steps.

In: Computer Science

Using Python 3 Write a program that reads the 4letterwords.txt file and outputs a file called...

Using Python 3

Write a program that reads the 4letterwords.txt file and outputs a file called 4letterwords.out that has every word found in 4letterwords.txt but each word on one line. Any leading and trailing blank spaces must be removed in the output file.

In: Computer Science

What is Classless Inter-Domain Routing (CIDR) in IP address design? What is Variable-Length Subnet Masking (VLSM)...

  1. What is Classless Inter-Domain Routing (CIDR) in IP address design?

  1. What is Variable-Length Subnet Masking (VLSM) in IP address design?

  1. You are given IP address block: 192.168.10.0/26. Identify Network and Host addresses.

  1. What is the difference between IP addresses 172.16.10.22 / 255.255.255.224, and 172.16.10.22/224?

  1. You are given an IP address 172.16.10.22 / 255.255.255.224.
    1. What is the network portion of 172.16.10.22 / 255.255.255.224 ?

  

  1. How many valid Host IP addresses are available?
  2. What’s the valid host IP address range of 172.16.10.22 / 255.255.255.224 ?
    1. What is the valid start or the first address of the subnet
    2. What is the valid last IP address of the subnet
    3. What is broadcast address for all Hosts?

In: Computer Science

Write a procedure of bubble sort to sort the array of byte. This procedure receives two...

Write a procedure of bubble sort to sort the array of byte. This procedure receives
two arguments, firstly it receives the offset of array in SI register, secondly BX
contains number of elements. Write a program that user Enter a single digit
number, these numbers have one space between them, call bubble sort procedure
for sorting the numbers

8086 assembly code

In: Computer Science

The following 32-bit binary word written in hexadecimal format represents a single RISC-V assembly instruction. What...

The following 32-bit binary word written in hexadecimal format represents a single RISC-V assembly instruction. What is the RISC-V instruction format and specific assembly language instruction?

0x40158a33

In: Computer Science

[P∧¬P]→Q is a tautology and is a valid argument. A valid argument can be sound or...

[P∧¬P]→Q is a tautology and is a valid argument. A valid argument can be sound or unsound. An invalid argument, however, can not be sound. Would the above argument be sound or sound? Why or why not?

In: Computer Science

in java Write program that draws out a path based on the user input. The starting...

in java

Write program that draws out a path based on the user input. The starting coordinates for the path is the middle of the DrawingPanel. Ask the user to enter an x and a y coordinate for a DrawingPanel. Your program will draw a line from the last coordinates to the current coordinates the user enters. If the user enters an x value or y value out of bounds of the DrawingPanel, then end the program.

In: Computer Science

Assuming binding priority (¬, ∧, ∨, →), are these sequents valid or not? If they are...

Assuming binding priority (¬, ∧, ∨, →), are these sequents valid or not? If they are valid, how do you prove it? If they are not valid, what would the truth table be?

  1. A → B, C → D ⊢ A ∨ C → B ∧ D
  2. A ∧ ¬A ⊢ ¬(B → C) ∧ (B → C)
  3. (A ∧ B) → C, C → D, B ∧ ¬D ⊢ ¬A

In: Computer Science

1. What is the ouput (what are in the Bag) when the 2 below lines are...

1. What is the ouput (what are in the Bag) when the 2 below lines are executed? Please show the steps. String[] items = {"Z", "Y", "Y", "X", "S", "C", "A", "E", "M"}; testAdd(aBag, items);

2.

What is the output (what are in the Bag) when the 3 below lines are executed? Please show the steps.

String[] testString = { "X", "Y", "Z" };

aBag.removeAllOccurences(testString);

displayBag(aBag);

In: Computer Science