i am getting this error can some one give me some directions

Error 1 'ShapesDemo.Rectangle' does not contain a constructor that takes 0 arguments

using System;

namespace ShapesDemo
{
   
    abstract class GeometricFigure
    {
       
         static void Main(string[] args)
        { Rectangle rectangle = new Rectangle(8,8);
            Square square = new Square(9,7);
            DisplayFigureResults(square);
            Triangle triangle = new Triangle();
            Console.WriteLine("The Area is:", rectangle.ToString()); }

         private static void DisplayFigureResults(Square square)
         {
             throw new NotImplementedException();
         }

        public int height ;
        public int width ;
        public readonly double area;

        public int heigth
        {
            get { return height; }
            set { height = value; }
        }

        public int Width
        {
            get { return width; }
            set { width = value; }
        }
       // public double area
       // { get { return area; } }


       public abstract double ComputeArea();

       private static void DisplayFigureDetails(GeometricFigure shape)
        { }
      
     
    }
    class Rectangle : GeometricFigure
    {
        private int p;
        private int p_2;

        public Rectangle(int p, int p_2)
        {
            this.p = p;
            this.p_2 = p_2;
        }
        
        public override double ComputeArea()
        {
           Console.WriteLine("The Area is" + width.ToString(), height.ToString());
           return width * height;
        }

    }
    class Square : Rectangle
    {
        private int p;
        private int p_2;

        public Square(int p, int p_2)
        {
            this.p = p;
            this.p_2 = p_2;
        }

        private static void DisplayFigureDetails(GeometricFigure Square) { }
        public void equal(int height, int width)
        {
            if (height.Equals(width))
                Console.WriteLine("{0} for {1} has the same measure " +
                    height, width);
        }
    }

    class Triangle : GeometricFigure
    {
       
        private static void DisplayFigureDetails(GeometricFigure Triangle){}
        public override double ComputeArea()
        {
            return width * (height / 2);

        }


    }
}

Recommended Answers

All 7 Replies

You didnt start the correct way. Check out this code, I only did a half of the code, which calculates the square area:

namespace Apr11Test2
{
    class Program
    {
        static void Main(string[] args)
        {           
            Rectangle r = new Rectangle();
            Square s = new Square(4, 5);
           
            Console.WriteLine("Computed are is {0}.", s.ComputeArea(r.Area));
            Console.ReadLine();
        }
    }

    abstract class GeometricFigure
    {
        public double Width { get; set; }
        public double Height { get; set; }        
        public readonly double Area;

        public abstract double ComputeArea(double _Area);
    }

    class Rectangle : GeometricFigure
    {
        public override double ComputeArea(double _Area)
        {
            return _Area = this.Width * this.Height;            
        }
    }

    class Square : Rectangle
    {
        public Square(int x, int y)
        {
            this.Width = x;
            this.Height = y;
            if (x != y)
                this.Height = this.Width;
        }

        public Square(int xy)
        {
            this.Width = xy;
            this.Height = this.Width;
        }

        public override double ComputeArea(double _Area)
        {
            return _Area = this.Width * this.Height;
        }
    }
}

thanks for that i tried to do the triangle class but i can't show the final result

class Triangle : GeometricFigure
    {

        private double length;
        private double height;

        public Triangle(double lenght, double height)//, int x, int y)//: base( x, y)
        {
            Length = length;
            Height = height;
        }

        public double Length
        {
            get { return length; }
            set { length = value; }
        }

        public double Height
        {
            get { return height; }
            set { height = value; }
        }

        public override double ComputeArea(double _Area)
        {
            double area = (Length * Height) / 2;
            return area;
        }

        /*public override string ToString()
        {
            return base.ToString() + "\t\t" + Length + "\t\t" + Height;
        }*/
    
    }

Error says that the class Rectangle haven't no argument constructor (zero parameter).

You could instantiate a Rectangle using,

Rectangle rect=new Rectangle(10,20);

thanks i did it, thats my final code can you verify it with me that thats what the requirement required

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ShapesDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            Rectangle r = new Rectangle();
            Square s = new Square(4,5);
            Triangle t = new Triangle(10,20);
            Console.WriteLine("Computed area is {0}" +"\n\n"+"Computed Triangle is: {1}"+"\n", s.ComputeArea(r.Area),t.ComputeArea(r.Area));
        }
    }
    abstract class GeometricFigure
    {
        public double Width { get; set; }
        public double Height { get; set; }        
        public readonly double Area;
 
        public abstract double ComputeArea(double _Area);
    }
 
    class Rectangle : GeometricFigure
    {
        public override double ComputeArea(double _Area)
        {
            return _Area = this.Width * this.Height;            
        }
    }
 
    class Square : Rectangle
    {
        public Square(int x, int y)
        {this.Width = x;
            this.Height = y;
            if (x != y)
            this.Height = this.Width;
        }
 
        public Square(int xy)
        {this.Width = xy;
            this.Height = this.Width;}

        public override double ComputeArea(double _Area)
        { return _Area = this.Width * this.Height; }

    }
    class Triangle : GeometricFigure
    { public Triangle( int x, int y)
        {this.Width = x;
        this.Height = y;}

        public override double ComputeArea(double _Area)
        { return _Area = (this.Width * this.Height) / 2;}
    }
}

On the 1st look, it looks ok to me. Even I cannot test the code atm.
Except the calculation of the triangle`s area. It has to be this way:

return _Area = this.Width * (this.Height / 2); }

return _Area = (this.Width * this.Height) / 2;
return _Area = this.Width * (this.Height / 2);
return _Area = this.Width * this.Height / 2;

All will produce the same result!

commented: Correct +5
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.