Question: Using C# .Fix the code used to to draw shapes shown below to show: public static string drawsquare( int height, int width) - If the

Using C# .Fix the code used to to draw shapes shown below to show:

public static string drawsquare( int height, int width) - If the size is undrawable (if the height or width is less than 1), the method should instead return a string that says "Cannot draw that shape."

public static string drawisocelestriangle( int size) - If the size is undrawable (if it less than 2), the method should instead return a string that says "Cannot draw that shape."

Code:

using System.IO; using System;

public class ShapeDrawer {

public static string DrawSquare(int height, int width) { // Write your code to draw the square here string s =""; for(int i=1;i<=height;i++) { for(int j=1;j<=width;j++) { if(i==1|j==1||i==height||j==width) { s=s+"$"; } else { s=s+" "; } } s = s + " "; } return s; }

public static string DrawIsoscelesTriangle(int size) { // Write your code to draw the triangle here string s =""; for(int i=1;i<=size;i++) { for(int j=1;j<=i;j++) { s=s+"-"; } s = s + " "; } for(int i=size-1;i>=1;i--) { for(int j=1;j<=i;j++) { s=s+"-"; } s = s + " "; } return s; }

}

class Program { static void Main() { Console.WriteLine(ShapeDrawer.DrawSquare(4,5)); Console.WriteLine(ShapeDrawer.DrawIsoscelesTriangle(3)); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!