Write a class to add two numbers together then square the re

Write a class to add two numbers together, then square the result, and write the result to the debug port. Name the method Square_Two. Format the numbers to have 1 decimal point.

Solution

hey heres the c# code..
using System;
namespace SquareApplication
{
   class Square
   {
      private double sum;
     //sum variable declared will be used in below Sum() function..
     //to store the result of two given numbers in sum.
      public void Sum( double x,double y )
      {
         sum = x+y;
      }
     
     //This returns the square of the sum.
      public double Square_two()
      {
         return sum*sum;
      }
   }
   class SquareTester
   {
      static void Main(string[] args)
      {
         Square s = new Square();   // Declare object s of type Square
        
         double result;
        
        
         s.Sum(5.0,6.0);
        
         // store the value of square of added sum of two given values.
         result = s.Square_two();
         //prints the result with one decimal point
         Console.WriteLine(\"result = {0:0.0}\" ,result);
        
        
         Console.ReadKey();
      }
   }
}
 Write a class to add two numbers together, then square the result, and write the result to the debug port. Name the method Square_Two. Format the numbers to ha

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site