Need Help! in English
Can not get program to run plz include detailed steps as comments of what i did not do
what I have done so far
class Point:
def __init__(self):
self._x = 0
self._y = 0
def getX(self):
return self._x
def setX(self, val):
self._x = val
def getY(self):
return self._y
def setY(self, val):
self._y = val
def __init__(self, initX = 0, initY = 0):
self._x = initX
self._y = initY
def __str__(self):
return '<'+str(self._x)+', '+str(self._y)+ '>'
def scale(self, factor):
self._x *= factor
self._y *= factor
def distance(self, other):
dx = self._x - other._x
dy = self._y - other._y
return sqrt(dx*dx + dy*dy)
def normalize(self):
mag = self.distance(Point())
if mag > 0: #don't scale if point is at originself.scale(1/mag)
def __add__(self, other):
return Point(self._x +other._x, self._y+other._y)
def __mul__(self, val):
if isinstance(val, (int, float)):
#performs regular multiplication operation.
return Point(self._x*val, self._y*val)
elif isinstance(val, Point):
#performs dot product operation.
return self._x*val._x + self._y*val._y
corner = Point()
corner.setX(8)
corner.setY(6)
c1=corner.getX()
c2=corner.getY()
print('Result: print corner values:<", c1,',',c2, '>‘)
c1=corner._x
c2=corner._y
print ("Result: print corner values: <", c1,',',c2, '>')
point1 = Point(5,20)
point2 = Point(10,30)
point1 = Point(5, 20)
print (point1 )
point1.scale(2)
print (point1)
apartAmt = point1.distance(point2)
new = Point(3, 5)
old = Point(4, 7)
total = new + oldprint (total)
print (total)
<7, 12>
import math # import the math module
class Point:
def __init__(self):
self._x = initX
self._y = initY
def __init__(self, initX = 0, initY = 0):
self._x = initX
self._y = initY
def getX(self):
return self._x
def setX(self, val):
self._x = val
def getY(self):
return self._y
def setY(self, val):
self._y = val
def __str__(self):
return '<'+str(self._x)+', '+str(self._y)+ '>'
def scale(self, factor):
self._x *= factor
self._y *= factor
def distance(self, other):
dx = self._x - other._x
dy = self._y - other._y
return math.sqrt(dx*dx + dy*dy) # sqrt is the function inside math module
def normalize(self):
mag = self.distance(Point())
if mag > 0: #don't scale if point is at origin
self.scale(1/mag) # this will be inside if block
def __add__(self, other):
return Point(self._x +other._x, self._y+other._y)
def __mul__(self, val):
if isinstance(val, (int, float)):
#performs regular multiplication operation.
return Point(self._x*val, self._y*val)
elif isinstance(val, Point):
#performs dot product operation.
return self._x*val._x + self._y*val._y
else:
return None
corner = Point()
corner.setX(8)
corner.setY(6)
c1=corner.getX()
c2=corner.getY()
print("Result: print corner values:<", c1,',',c2, '>')
c1=corner._x
c2=corner._y
print("Result: print corner values: <", c1,',',c2, '>')
point1 = Point(5,20)
point2 = Point(10,30)
point1 = Point(5, 20)
print (point1 )
point1.scale(2)
print (point1)
apartAmt = point1.distance(point2)
new = Point(3, 5)
old = Point(4, 7)
total = new + old
print (total)
Code Screenshot:
Output:
#import module for sqrt function
import math
class Point:
#constructor, assign values 0 to x and
y variables
def __init__(self):
self._x = 0
self._y = 0
#method that return x cordinate
def getX(self):
return self._x
#method that set x cordinate
def setX(self, val):
self._x = val
#method that return y cordinate
def getY(self):
return self._y
#method that set the value of y
cordinate
def setY(self, val):
self._y = val
#paremetized constructor to set values
of x and y cordinates
def __init__(self, initX = 0, initY = 0):
self._x = initX
self._y = initY
#return cordinate of points
def __str__(self):
return '<'+str(self._x)+', '+str(self._y)+ '>'
#scale points of the cordinates
def scale(self, factor):
self._x *= factor
self._y *= factor
#calculate distance from other
point
def distance(self, other):
dx = self._x - other._x
dy = self._y - other._y
return math.sqrt(dx*dx + dy*dy)
def normalize(self):
mag = self.distance(Point())
if mag > 0: #don't scale if point is at originself.scale(1/mag)
return
#Add cordinates of points
def __add__(self, other):
return Point(self._x +other._x, self._y+other._y)
#multiply points
def __mul__(self, val):
if isinstance(val, (int,
float)):
#performs regular multiplication operation.
return Point(self._x*val, self._y*val)
elif isinstance(val, Point):
#performs dot product
operation.
return self._x*val._x + self._y*val._y
#create object
#add x and y cordinates
corner = Point()
corner.setX(8)
corner.setY(6)
#get x and y cordinates
c1=corner.getX()
c2=corner.getY()
#print values
print("Result: print corner values:<", c1,",",c2, ">")
c1=corner._x
c2=corner._y
print ("Result: print corner values: <", c1,",",c2, ">")
#create another object
point1 = Point(5,20)
point2 = Point(10,30)
point1 = Point(5, 20)
print (point1 )
#scale point with factor 2
point1.scale(2)
print (point1)
#calculate distance
apartAmt = point1.distance(point2)
#add two points
new = Point(3, 5)
old = Point(4, 7)
total = new + old
print (total)
===========================
Output
Code
Need Help! in English Can not get program to run plz include detailed steps as comments of...
Python3 programming help needed LAB*: Program: Online shopping cart (continued) Need the below code edited to run properly for the lab.. class ItemPurchase: def __init__(self, nameitem='none', item_prc=0, item_quntity=0, item_descrp = 'none'): self.nameitem = nameitem self.item_prc = item_prc self.item_quntity = item_quntity self.item_descrp = item_descrp def print_itemvaluecost(self): string = '{} {} @ ${} = ${}'.format(self.nameitem, self.item_quntity, self.item_prc(self.item_quntity * self.item_prc)) valuecost = self.item_quntity * self.item_prc return string, valuecost def print_itemdescription(self): string = '{}: {}'.format(self.nameitem, self.item_descrp) print(string , end='\n') return string class Shopping_Cart: #Parameter...
Need help doing program In bold is problem E2 #include<iostream> #include<string> #include<vector> using namespace std; //Car class //Defined enum here enum Kind{business,maintenance,other,box,tank,flat,otherFreight,chair,seater,otherPassenger}; //Defined array of strings string KIND_ARRAY[]={"business","maintenance","other,box","tank,flat","otherFreight","chair","seater","otherPassenger"}; class Car { private: string reportingMark; int carNumber; Kind kind; //changed to Kind bool loaded; string destination; public: //Defined setKind function Kind setKind(string knd) { for(int i=0;i<8;i++) //repeat upto 8 kinds { if(knd.compare(KIND_ARRAY[i])==0) //if matched in Array kind=(Kind)i; //setup that kind } return kind; } //Default constructor Car() { } //Parameterized constructor...
What is the role of polymorphism? Question options: Polymorphism allows a programmer to manipulate objects that share a set of tasks, even though the tasks are executed in different ways. Polymorphism allows a programmer to use a subclass object in place of a superclass object. Polymorphism allows a subclass to override a superclass method by providing a completely new implementation. Polymorphism allows a subclass to extend a superclass method by performing the superclass task plus some additional work. Assume that...