Answer to Question #333338 in C# for Xyz

Question #333338

1. Write a program to declare a structure and inside it is a non-static method that returns the area of a rectangle.

 

Test Data and Sample Output:

Input the dimensions of a rectangle:

Length: 60

Width: 30

Expected Output:

Length: 60

Width: 30

Area: 1800



1
Expert's answer
2022-04-25T13:37:22-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


class Program
{
    static void Main()
    {
        Console.Write("Enter length: ");
        double length = double.Parse(Console.ReadLine());


        Console.Write("Enter width: ");
        double width = double.Parse(Console.ReadLine());


        Rectangle rect = new Rectangle(length, width);
        Console.WriteLine($"Length: {length}");
        Console.WriteLine($"Width: {width}");
        Console.WriteLine($"Length: {rect.GetArea()}");
    }


  


}


struct Rectangle
{
    private double length;
    private double width;


    public Rectangle(double length, double width)
    {
        this.length = length;
        this.width = width;
    }


    public double GetArea()
    {
        return length * width;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS