Question

In: Computer Science

Use a swift language in xcode software for the following code? 20 pts Create a class...

Use a swift language in xcode software for the following code?

20 pts Create a class called Polygon, this class will have:

a. Properties:

i. Number of sides

ii. Interior angles

b. Method

i. sides(), this will print to the console how many sides the polygon has

ii. interiorAngle(), this will calculate the interior angles and set it to the interior angles property

Create another class named Triangle that inherits from Polygon. This class will have to:

a. Properties:

i. Area

ii. Side length

b. Method i. calculateArea

Solutions

Expert Solution


class Polygon
{
var NoOfSides : Int = 0
var InteriorAngle : Int = 0

func sides(NoOfSides:Int)
{
print("Number of sides of polygon are :\(NoOfSides)")
}
func interiorAngle()
//calculate sum of interior angles of a polygon
{
InteriorAngle=(NoOfSides-2)*(-180)
print("Sum of interior angles of polygon are :\(InteriorAngle)")
}
  
}

let counter = Polygon()
counter.sides(NoOfSides:4)
//input the number of sides of the polygon example:4
counter.interiorAngle()

class Triangle : Polygon
//inheritance
{
var Area : Float = 0
var SideLength1 : Float = 0
var SideLength2: Float = 0
var SideLength3 :Float = 0

func calculateArea(SideLength1:Float,SideLength2:Float,SideLength3:Float)
//function to calculate the area of Triangle
{
var p:Float=0
var s:Float=0
p=(0.5)*(SideLength1+SideLength2+SideLength3)
s=p*(p-SideLength1)*(p-SideLength2)*(p-SideLength3)
Area=s.squareRoot()
print("Area of Triangle is :\(Area)")
}
  
}

let show = Triangle()
show.calculateArea(SideLength1:3,SideLength2:4,SideLength3:5)
//input the values of the sides of the triangle example:3,4,5


Related Solutions

hot use blutooth on your app stimulation to connect to a device. xcode swift. please inclide...
hot use blutooth on your app stimulation to connect to a device. xcode swift. please inclide a code if possible.
swift language declare a Swift array variable that can hold instances of any class type
swift language declare a Swift array variable that can hold instances of any class type
IN SWIFT LANGUAGE In this lab we are going to create a game that uses all...
IN SWIFT LANGUAGE In this lab we are going to create a game that uses all the different types of control flow operators that exist in SWIFT LANGUAGE. The game will be a choose your own adventure game. The user will have to answer a series of questions and this will change the path of a story. This must be done by using if/else statements that are nested within other if/else statements. Your story must have four (4) different possible...
Code in C++ Objectives Use STL vector to create a wrapper class. Create Class: Planet Planet...
Code in C++ Objectives Use STL vector to create a wrapper class. Create Class: Planet Planet will be a simple class consisting of three fields: name: string representing the name of a planet, such as “Mars” madeOf: string representing the main element of the planet alienPopulation: int representing if the number of aliens living on the planet Your Planet class should have the following methods: Planet(name, madeOf, alienPopulation) // Constructor getName(): string // Returns a planet’s name getMadeOf(): String //...
Q2. Update the given code 2 to implement the following problem: Create a class triangle Use...
Q2. Update the given code 2 to implement the following problem: Create a class triangle Use dynamic memory allocation to create 10 objects of the class triangle Set default height and base of all created objects (triangle) to 5 and 10 respectively using a constructor Ask user to change only the height of the 5th triangle Print height and base of all (10) triangles to demonstrate that you did the task correctly Deallocate the 5th object Print height and base...
language is java Use method overloading to code an operation class called CircularComputing in which there...
language is java Use method overloading to code an operation class called CircularComputing in which there are 3 overloaded methods as follows: computeObject(double radius)-compute area of a circle computeObject(double radius, double height)-compute area of a cylinder computeObject(double radiusOutside, double radiusInside, double height)-compute volume of a cylindrical object These overloaded methods must have a return of computing result in each Then override toString() method so it will return the object name, the field data, and computing result Code a driver class...
Problem 2: (20 pts) Create a Patient class which has private fields for patientid, lastname, firstname,...
Problem 2: (20 pts) Create a Patient class which has private fields for patientid, lastname, firstname, age, and email. Create public data items for each of these private fields with get and set methods. The entire lastname must be stored in uppercase. Create a main class which instantiates a patient object and sets values for each data item within the class. Display the data in the object to the console window
"Write in swift code only please, Create a SwiftUI project named DogBreeds based on the Contacts...
"Write in swift code only please, Create a SwiftUI project named DogBreeds based on the Contacts app. The app should be named DogBreeds. The app will display 10 dog images and names in a list"
(20 pts) In the following code inside a try block, what kind of object is passed...
(20 pts) In the following code inside a try block, what kind of object is passed to the Scanner constructor? Scanner file = new Scanner ( new File (“test.txt”)); (20 pts) What is the output of this code sequence? Scanner parse = new Scanner (“A 1 B 2 C 3 D”); while (parse.hasNext())     System.out.print(parse.next()); (20 pts) What is wrong with following code? try { Scanner file = new Scanner(new File(“c:\docs\data.txt”)); int n = 0; while (file.hasNext()) { String s...
Swift code import Foundation protocol TaksPerformer { func doAThing() } class Employee: TaksPerformer { let name:...
Swift code import Foundation protocol TaksPerformer { func doAThing() } class Employee: TaksPerformer { let name: String var boss: Boss? init(name: String) { self.name = name } func doAThing() { print("\(name) is doing a thing") } } class Boss { var employee: Employee let name: String init(name: String, employee: Employee) { self.name = name self.employee = employee employee.boss = self } func actLikeABoss() { employee.doAThing() } } // 1) // A) What is wrong with the current implementation of Boss...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT