Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Prompt: This assignment provides an opportunity to work with defining classes and creating objects (instantiating) from those classes. The exercise consists of source code that

Prompt: This assignment provides an opportunity to work with defining classes and creating objects (instantiating) from those classes. The exercise consists of source code that contains errors; therefore, it neither compiles nor runs correctly. It focuses on a console application, but the concepts translate across C# programming.

Consider the following C# console program that contains four programming errors. For the sake of simplicity and space, two classes are defined in the same file as opposed to the best practice of defining one class per file. ALSO PLEASE INDICATE CORRECTIONS MADE WITH COMMENTS:

namespace Classes { class Program { static void Main(string[] args) { Point origin = new Point(); Point bottomRight = another Point(1366, 768); double distance = origin.DistanceTo(bottomRight); Console.WriteLine("Distance is: {0}", distance); Console.WriteLine("Number of Point objects: {0}", Point.ObjectCount()); } }

class Point { private int x, y; private int objectCount = 0; public void Point() { this.x = -1; this.y = -1; objectCount++; } public Point(int x, int y) { this.x = x; this.y = y; objectCount++; }

public Point(int x, int y) { this.x = x; this.y = y; objectCount++; } private double DistanceTo(Point other) { int xDiff = this.x - other.x; int yDiff = this.y - other.y; double distance = Math.Sqrt((xDiff * xDiff) + (yDiff * yDiff)); return distance; } public static int ObjectCount() { return objectCount; } } }

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

Why should a business be socially responsible?

Answered: 1 week ago

Question

Discuss the general principles of management given by Henri Fayol

Answered: 1 week ago

Question

Detailed note on the contributions of F.W.Taylor

Answered: 1 week ago