1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Tju [1.3M]
4 years ago
9

Create a base class named rectangle that contains lenght and width data members.

Computers and Technology
1 answer:
kumpel [21]4 years ago
4 0

Answer:

class Rectangle:  

   

   def __init__(self, length, width):

       self.length = length

       self.width = width

       

   

   def area(self):

       area = self.length*self.width

       return area

   

   

class Box (Rectangle):

   

   def __init__(self, length, width, height):

       super().__init__(length, width)

       self.height = height

       

   def volume(self):

       volume = self.length * self.width * self.height

       return volume

   

   def area(self):

       area = 2*(self.length*self.width) + 2*(self.length*self.height) + 2*(self.width*self.height)

       return area

rec_1 = Rectangle(2,4)

box_1 = Box(2,2,6)

print(box_1.length)

print(box_1.area())

   

print(rec_1.length)

print(rec_1.area())

Explanation:

The programming language used is python.

class Rectangle

The class Rectangle is created with attributes length and width.

The class attributes are initialized using the __init__ constructor.

In the rectangle class, a method/function is declared to return the area of the rectangle.

class Box

This class is a child of rectangle and it inherits all its attributes and methods,

It has an additional attribute of depth and its constructor is used to initialize it.

The class contains a volume function, that returns the volume and an override function 'area()' that displaces the area from the parent class.

Finally, some instances of both classes are created.

You might be interested in
Write a function called word_count that takes a string and returns a dictionary that maps every case-insensitive word in the str
Taya2010 [7]

Solution :

We need to write a function named ''$\text{word}$_$\text{count}$". The program takes a string and then returns a dictionary which maps the case insensitive word.

def $\text{word}$_$\text{count}$(s):

   $\text{words}$ = $\text{s.lower}$().split()

   $\text{result}$ = {}

   for $x$ in words:

       if $x$ in $\text{result}$.keys():

           $\text{result}$[x] += 1

       else:

           $\text{result}$[x] = 1

   return $\text{result}$

5 0
3 years ago
The term that describes the connection of all kinds of devices; computers, phones, laptops, appliances, cars, etc. to the intern
Kryger [21]
This is hyped as the Internet of Things (IoT). Sometimes also called IoE, the Internet of Everything.
4 0
3 years ago
Match the vocabulary to the appropriate definition.
Allisa [31]

Answer:

Pulling related code together in objects is Arrays

Helps programmers when they revisit code or are new to code-- Documentation

Explanation:

This is all I know

3 0
2 years ago
The _______ move the fabric forward in the machine. A. pressure plates B. zipper feet C. hem guides D. feed dogs
Lyrx [107]
The equipment that move the fabric forward are called "Hem guides"
8 0
4 years ago
How can i clip a picture to a question on the computer?
Varvara68 [4.7K]

Here you are, its that button.

4 0
3 years ago
Read 2 more answers
Other questions:
  • Consider the following JavaScript program:
    8·1 answer
  • Paying attention to the trends that might impact your future career is called
    15·2 answers
  • ____________ is a widely accepted international best practices framework for implementing information systems security.
    12·1 answer
  • What is the main role of LDAP?
    14·1 answer
  • A={a,b,c,d} B={p,q,r,s} find the value of A-B and B-A​
    13·1 answer
  • A network technician has created a network consisting of an external internet connection, a DMZ,
    14·1 answer
  • What is jcl language on the mainframe?
    10·1 answer
  • The NFiPA 704 system uses a numerical value between _____ and _____ to indicate the level of hazard for that particular chemical
    6·2 answers
  • What are the services offered by web-based email?​
    12·1 answer
  • Similarities between incremental and<br> prototyping models of SDLC
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!