






























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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
1 / 38
This page cannot be seen from the preview
Don't miss anything!































Here is the final output of the whole generated code. Every command has been run successfully
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_ { ///
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; ///
public Form1() { InitializeComponent(); g = panel1.CreateGraphics(); } ///
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)