C# Code Snippet for Drawing Shapes with User Input, Assignments of Software Engineering

A C# code snippet that initializes variables for drawing shapes such as circles, rectangles, triangles, and polygons. The user can input parameters like radius, width, height, side length, and points to draw the desired shape. The code uses a MessageBox to display error messages for incorrect parameters.

Typology: Assignments

2019/2020

Uploaded on 05/14/2020

priti-yadav-1
priti-yadav-1 🇳🇵

2 documents

1 / 38

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ASSIGNMENT
Advance Software Engineering part 2
THE BRITISH COLLEGE
THAPATHALI
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26

Partial preview of the text

Download C# Code Snippet for Drawing Shapes with User Input and more Assignments Software Engineering in PDF only on Docsity!

ASSIGNMENT

Advance Software Engineering part 2

THE BRITISH COLLEGE

THAPATHALI

Here is the final output of the whole generated code. Every command has been run successfully

and it has been submitted with every screenshots in the provided document. The interface

here consist of panel ,textbox,button ,richtextbox,menubar and name of all these have

been assigned according to their working performance. As we can see ther is

run,clear,reset button.

RUN : to run the multi line command

EXECUTE: to run the multi line command

CLEAR:to clear the pannel,textbox.

RESET: as it will reset the point from Zero.

Fig:Loop for drawing circle

Fig:Circle created after method calling

Fig:Looping circle with passing variable

Fig:Version Control in Bit Bucket Fig: Commits in bitbucket Here the generated code Form1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO;

using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; namespace Assignment_ { ///

/// Loop for 10 /Circle 20 Radius + 10 Rectangle 10, width + 20 height + 30 EndLoop/ /// Class Form1 is created and it was inhreate to Form /// public partial class Form1 : Form { /// /// Inilizing the all the value /// public int x = 0; public int y = 0; int radius = 0, height = 0, width = 0, increase_r = 0, increase_h = 0, increase_w = 0, vbvalue = 0, tempvbvalue = 0, hyp = 0, adj = 0, tbase = 0; int increase_hyp = 0, increase_adj = 0, increase_base = 0; int count = 1; int increase_poly = 0; string cir = "", rect = "", methodname = "", vbname = "", tempvbname = "", tr = "", poly = ""; private void multi_line_cmnd_TextChanged(object sender, EventArgs e) { } private void eXITToolStripMenuItem_Click_1(object sender, EventArgs e) { { Application.Exit(); } }

multi_line_cmnd.Text = openStream.ReadToEnd(); // reads the fiel to end openStream.Dispose(); //clears the memmory } } } private void RESET_Click(object sender, EventArgs e) { x = 0; y = 0; radius = 0; height = 0; width = 0; increase_r = 0; increase_h = 0; increase_w = 0; vbvalue = 0; tempvbvalue = 0; hyp = 0; adj = 0; tbase = 0; int[] Points = { }; increase_hyp = 0; increase_adj = 0; increase_base = 0; count = 1; string message = "Reset the value"; string title = "Message"; MessageBox.Show(message, title); } private void CLEAR_Click(object sender, EventArgs e) { multi_line_cmnd.Clear(); single_line_cmnd.Clear(); panel1.Refresh(); string message = "Cleared!!"; string title = "Massage!!"; MessageBox.Show(message, title); } private void label3_Click(object sender, EventArgs e) { } int[] point1 = { }; private readonly char[] charsToTrim2 = { '<', '>' }; String command, command1; String[] command_store = new string[20]; Graphics g; ///

/// Constractor /// Initializeing the Componets ///

public Form1() { InitializeComponent(); g = panel1.CreateGraphics(); } ///

/// Reset all the Value /// /// Gets the User Input /// Gets the Events for //this method rest the position of pen private void reset_all_Click(object sender, EventArgs e) { } //This method clear command box and panel /// /// Button is created for clearing the Pannels and textboxs of the form /// /// /// //this menthod excute the multiline command /// /// Gets the data from Text editor and process it /// /// /// public void RUN_Click(object sender, EventArgs e) { Validate s = new Validate(); //storing the value in string string IdOrder = Convert.ToString(multi_line_cmnd.Text.Trim()); string IdOrder1 = Convert.ToString(multi_line_cmnd.Text.Trim()); //spliting the string by /n and storing it in array string[] ArrIdOrders = Regex.Split(IdOrder, "\n"); s.Test_shapes(IdOrder); String[][] words2 = { };

else if (words[0].Equals("Points", StringComparison.InvariantCultureIgnoreCase) && words[1].Equals("=")) { try { for (int j = 0; j < words.Length; j++) { point1[j] = Convert.ToInt32(words[j + 1]); } } catch (IndexOutOfRangeException ex) // CS { MessageBox.Show( "Missing Parameter"); Console.WriteLine(ex.Message); } catch (Exception ex) { MessageBox.Show("Points of Ploygon", "Error on Loop"); Console.WriteLine(ex.Message); } } else if (words[0].Equals("Width", StringComparison.InvariantCultureIgnoreCase) && words[1].Equals("=")) { try { int a = Convert.ToInt32(words[2]); width = a; } catch (IndexOutOfRangeException ex) // CS { MessageBox.Show( "Missing Parameter"); Console.WriteLine(ex.Message); } catch (Exception ex) { MessageBox.Show("Width of Rectangle", "Error on Loop"); Console.WriteLine(ex.Message);

else if (words[0].Equals("Radius", StringComparison.InvariantCultureIgnoreCase) && words[1].Equals("=")) { try { int a = Convert.ToInt32(words[2]); radius = a; } catch (IndexOutOfRangeException ex) // CS { MessageBox.Show("check programme", "Missing Parameter"); Console.WriteLine(ex.Message); } catch (Exception ex) { MessageBox.Show("Radius of Circle", "Error on Radius"); Console.WriteLine(ex.Message); } } else if (words[0].Equals("Count", StringComparison.InvariantCultureIgnoreCase) && words[1].Equals("=")) { try { int a = Convert.ToInt32(words[2]); count = a; } catch (IndexOutOfRangeException ex) // CS { MessageBox.Show("check programme", "Missing Parameter"); Console.WriteLine(ex.Message); } catch (Exception ex) { MessageBox.Show("Count", "Error on Count"); Console.WriteLine(ex.Message); } } else if (words[0].Equals("Loop", StringComparison.InvariantCultureIgnoreCase) && words[1].Equals("for", StringComparison.InvariantCultureIgnoreCase) && words1[arrcount1].Equals("EndLoop", StringComparison.InvariantCultureIgnoreCase)) { try {

else if (words[0].Equals("If", StringComparison.InvariantCultureIgnoreCase) && words[2].Equals("=")) { try { tempvbname = words[1]; tempvbvalue = Convert.ToInt32(words[3]); checkifmethod = true; checkmethod2 = true; } catch (IndexOutOfRangeException ex) // CS { MessageBox.Show("Parameter is missing"); Console.WriteLine(ex.Message); } catch (Exception ex) { MessageBox.Show("Error on If Statements", "Error"); Console.WriteLine(ex.Message); } } else if (words[0].Equals("EndIf", StringComparison.InvariantCultureIgnoreCase) && checkifmethod == true) { vbname = tempvbname; vbvalue = tempvbvalue; //MessageBox.Show("djdf",) checkifmethod1 = true; checkmethod2 = true; } else if (checkmethod1.Equals("Method", StringComparison.InvariantCultureIgnoreCase) && words[0].Equals("EndMethod", StringComparison.InvariantCultureIgnoreCase)) { methodname = localmethodname; } else if (words[0] == methodname) { string a = words.Length.ToString();

if (words.Length > 2) { try { for (int k = 0; k < (words.Length); k++) { string b = words[k]; methodvalue[k] = b; } } catch (Exception ex) { Console.WriteLine(ex.Message); } } checkmethod2 = true; } else if (words[0].Equals("moveto", StringComparison.InvariantCultureIgnoreCase)) { if (words.Length == 3) { //converting and setting the value try { int a = Convert.ToInt32(words[1].Trim(charsToTrim2)); int b = Convert.ToInt32(words[2].Trim(charsToTrim2)); x = a; y = b; string message = "Point is moved!!"; string title = "Message"; MessageBox.Show(message, title); } catch (Exception ex) { Console.WriteLine(ex.Message); } } else { string message = " Wrong Parameter entered: Please Enter Again" + "\nMoveto x,y "; string title = "Parameter Error Message";

height = Convert.ToInt32(methodvalue[1]); width = Convert.ToInt32(methodvalue[2]); } catch (Exception ex) { Console.WriteLine(ex.Message); } } if (words[1].Equals("Height", StringComparison.InvariantCultureIgnoreCase) && words[2].Equals("Width", StringComparison.InvariantCultureIgnoreCase)) { if (checkifmethod1 == true) { height = height + vbvalue; width = width + vbvalue; } rect = words[0]; } else { if (checkifmethod1 == true) { height = height + vbvalue; width = width + vbvalue; } try { rect = words[0]; int a = Convert.ToInt32(words[1]); int b = Convert.ToInt32(words[2]); height = a; width = b; } catch (Exception ex) { Console.WriteLine(ex.Message); } } } else {

string message = " Wrong Parameter entered: Please Enter Again" + "\nRectangle width,height "; string title = "Parameter Error Message"; MessageBox.Show(message, title); } } else if (words[0].Equals("Triangle", StringComparison.InvariantCultureIgnoreCase)) { if (words.Length == 4) { if (checkmethod2 == true && checkmethod1.Equals("Method", StringComparison.InvariantCultureIgnoreCase)) { if (checkifmethod1 == true) { hyp = hyp + vbvalue; tbase = hyp + vbvalue; adj = adj + vbvalue; } try { tbase = Convert.ToInt32(methodvalue[1]); adj = Convert.ToInt32(methodvalue[2]); hyp = Convert.ToInt32(methodvalue[3]); } catch (Exception ex) { Console.WriteLine(ex.Message); } } if (words[1].Equals("Height", StringComparison.InvariantCultureIgnoreCase) && words[2].Equals("Width", StringComparison.InvariantCultureIgnoreCase)) { if (checkifmethod1 == true) { hyp = hyp + vbvalue; tbase = hyp + vbvalue; adj = adj + vbvalue; } tr = words[0]; } else { if (checkifmethod1 == true)