0% found this document useful (0 votes)
15 views

Using Using Using Using Using Using Using Using Namespace Public Partial Class

The document describes code for a 1D array program with functions to add elements to the array, add elements at a specific location, sort the array, search the array, and display array elements. The program uses an integer array of size 6, tracks the number of elements added, and includes validation on array bounds and input fields.

Uploaded by

Ajay Mankotia
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Using Using Using Using Using Using Using Using Namespace Public Partial Class

The document describes code for a 1D array program with functions to add elements to the array, add elements at a specific location, sort the array, search the array, and display array elements. The program uses an integer array of size 6, tracks the number of elements added, and includes validation on array bounds and input fields.

Uploaded by

Ajay Mankotia
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

using using using using using using using using

System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.Forms;

namespace MCAWindows { public partial class frm1DArrays : Form

{ public frm1DArrays() { InitializeComponent(); } int[] num = new int[6]; int ind = 0; private void btnAdd_Click(object sender, EventArgs e) { if (ind < 6) { num[ind] = Convert.ToInt32(txtData.Text); ind++; MessageBox.Show("One Element Added Successfully"); txtData.Text = ""; txtData.Focus(); } else MessageBox.Show("Array Full"); } private void btnAddAtLoc_Click(object sender, EventArgs e) { int loc=0; if ((txtData.Text == "") && (txtLoc.Text == "")) MessageBox.Show("Please Input Data or Location"); else

{ loc = Convert.ToInt32(txtLoc.Text); if ((loc>=0)&&(loc < ind)) { for (int i = ind - 1; i >= loc; i--) { num[i + 1] = num[i]; } num[loc] = Convert.ToInt32(txtData.Text); MessageBox.Show("One Element Added Successfully"); ind++; } else MessageBox.Show("Please enter Location Between 0 and " + (ind-1).ToString()); } } private void btnShow_Click(object sender, EventArgs e) { for(int i=0;i<ind;i++) MessageBox.Show("num["+i.ToString()+"] = " + num[i].ToString()); } private void btnSort_Click(object sender, EventArgs e)

{ int temp = 0; for (int i = 0; i < ind; i++) { for (int j = 0; j < ind - i - 1; j++) { if (num[j] > num[j + 1]) { temp = num[j]; num[j] = num[j + 1]; num[j + 1] = temp; } } } MessageBox.Show("Sorting Complete, Press Show Button to display array elements."); } private void btnSearch_Click(object sender, EventArgs e) { int loc = 0, data = 0; if ((txtData.Text == "") && (txtLoc.Text == "")) { MessageBox.Show("Please Enter either Data or Location to search"); } else if ((txtData.Text != "") &&(txtLoc.Text !="")) {

Location");

data = Convert.ToInt32(txtData.Text); loc = Convert.ToInt32(txtLoc.Text); if (num[loc] == data) MessageBox.Show("Data Found at " + loc.ToString() + " else MessageBox.Show("Data not Available in array");

} else if (txtLoc.Text == "") { int flag = 0; data = Convert.ToInt32(txtData.Text); for (int i = 0; i < ind; i++) { if (num[i] == data) { MessageBox.Show("Data Found at " + i.ToString() + " Location"); } flag = 1; } if(flag!=1) MessageBox.Show("Data not Available in array"); } else if(txtData.Text =="") { loc=Convert.ToInt32 (txtLoc.Text); if((loc>=0) &&(loc<6))

{ MessageBox.Show("Valid Location, but Input data also"); txtData.Focus(); } else {

MessageBox.Show("InValid Location and Data field empty. Input data and Location"); txtData.Focus (); } } } private void btnTextbox_Click(object sender, EventArgs e) { TextBox objtb = new TextBox(); objtb.Location = new Point(200, 200); objtb.Size = new Size(50, 50); this.Controls.Add(objtb); } }

You might also like