Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Examine the following code. Is there any problem according to design by contract? If yes, please list the problem(s). using System; using System.Collections.Generic; using System.Linq;

Examine the following code. Is there any problem according to design by contract? If yes, please list the problem(s).

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace DesignByContractDemo

{

class Program

{

static void Main(string[] args)

{

Console.WriteLine("Please input numerator:");

int numerator = int.Parse(Console.ReadLine());

Console.WriteLine("Please input denominator:");

int denominator = int.Parse(Console.ReadLine());

Division d = new Division(numerator, denominator);

if (denominator == 0)

Console.WriteLine("Result = {0} ", double.PositiveInfinity);

else

Console.WriteLine("Result = {0} ", d.Divid());

Console.ReadKey();

}

}

class Division

{

double numerator;

double denominator;

public Division(double _numerator, double _denominator)

{

numerator = _numerator;

denominator = _denominator;

}

public double Divid()

{

if (denominator != 0)

return numerator / denominator;

else

return double.PositiveInfinity;

}

}

}

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

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

Students also viewed these Databases questions

Question

Draw a schematic diagram of I.C. engines and name the parts.

Answered: 1 week ago