Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions