Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON NOTE THE FOLLOWING SYNOMYMS: function = method = operation (UML) data member = variable = attribute (UML) (10 pts.) (1) Research the Unified Modeling

PYTHON

NOTE THE FOLLOWING SYNOMYMS: function = method = operation (UML)

data member = variable = attribute (UML)

(10 pts.)

(1) Research the Unified Modeling Language, specifically in reference to a class diagram and answer the following

questions. The following Unified Modeling Language diagram represents a class of objects called Emp.

Emp

-s: int

+d:bool

#t: string

+Emp( )

-z( ): void

#y( ): bool

+x( ): string

(a) Give the name of a private function/method for the object Emp. (a) _________________________

(b) Give the name of all methods that return a Boolean variable for the object Emp.

(b) _________________________

(c) Give the name of a protected variable for the object Emp. (c) _________________________

(d) Give the name of a public variable for the object Emp.

(d) _________________________

(e) How many constructors does the object Emp have? (e) _________________________

(10 pts.)

(2) Research the selection and insertion sort algorithms and answer the following question.

Circle the sorting algorithm below with the following description:

With this sorting algorithm, the 9th pass over the array searches for the 9th smallest element in the list and

places it into the 9th position of the array.

SELECTION SORT INSERTION SORT

(10 pts.)

(3) Write the necessary code that only refers to the variables p, q, and r shown below, that exchanges the

values stored in p and q. Write your code in the box below.

p = -44

q = 17

r = 0

# swap the values stored in p and q by writing code that only executes assignments involving

# variables p, q, and r.

# your code should not refer to the constants -44 or 17

# code your solution in the box below

(10 pts.)

(4) Write the method num_even_digits(n). This method takes an integer number n as a parameter and returns the

number of even digits in the number. Even digits are 0, 2, 4, 6, 8. For example, with the following method call:

num_even_digits(12345) would return 2, since there are 2 even digits in the number 12345.

def num_even_digits(n):

#Fill in the necessary code below

(10 pts.)

(5) Write the method is_digit_string(s) that returns true if all characters in the string s are digits, else it returns false.

A valid digit is a 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9. For example, with the following method call: is_digit_string(734a2)

would return false.

def is_digit_string(s):

#Fill in the necessary code below

(20 pts.)

(6) Write the method number_uppercase(m) that returns the number of uppercase characters in a two-dimensional

rectangular list or matrix m, whose elements are characters. For example, given the following two-dimensional

list

matrix = [ ['a','B'], ['F','K'], ['e','g'] ], the following function call number_uppercase(matrix) would return 3,

since there are three upper case characters in the matrix

def number_uppercase(m):

#Fill in the necessary code below

(30 pts.)

(7) Given the following class definition, implement the methods def perimeter(self), def diagonalLength(self), and

def display(self, length_horizontal = True, character = '*')

import math

class Rectangle:

# initializer with default length = 4 and default width = 3

def __init__(self, length = 4, width = 3):

self.length = length

self.width = width

# method that returns the area of the rectangle

def area(self):

return self.length * self.width

# method that prints the following information to the standard output terminal:

# length, width, area, perimeter, diagonal length

def printInfo(self):

print('Length is ' + str(self.length))

print('Width is ' + str(self.width))

print('Area is ' + str(self.area()))

print('Perimeter is ' + str(self.perimeter()))

print('Diagonal length is ' + str(self.diagonalLength()))

# method that returns the perimeter of the rectangle

def perimeter(self):

#Fill in the necessary code below

# method that returns the diagonal length of the rectangle

def diagonalLength(self):

#Fill in the necessary code below

# method that prints the rectangle to the standard output terminal

# default values for optional parameters are True and '*'

# length_horizontal determines if the rectangle should be printed so that the longer side (length) is

# horizontal vs. vertical, character is the type of character used to print the rectangle

# Sample output is shown for the following method calls

r1 = Rectangle()

r1.printInfo()

r1.display()

print()

r2 = Rectangle(10, 2)

r2.display(True)

print()

r2.display(False)

print()

r2.display(False,'g')

print()

Length is 4

Width is 3

Area is 12

Perimeter is 14

Diagonal length is 5.0

* * * *

* * * *

* * * *

* * * * * * * * * *

* * * * * * * * * *

* *

* *

* *

* *

* *

* *

* *

* *

* *

* *

g g

g g

g g

g g

g g

g g

g g

g g

g g

g g

def display(self, length_horizontal = True, character = '*'):

#Fill in the necessary code below

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2008 Comprehensive Concepts And Techniques

Authors: Gary B. Shelly, Corinne Hoisington

1st Edition

1423927168, 978-1423927167

More Books

Students also viewed these Databases questions

Question

LO1 Identify why performance management is necessary.

Answered: 1 week ago