Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C# write a Windows application that maintains an address book. This address b

ID: 3837458 • Letter: I

Question

In C# write a Windows application that maintains an address book. This address book should hold up to 20 entries. You must store your data with either arrays classes or a text file. Make sure to use methods, try-catch, and at least two classes, and comment often to show what you are doing.

Each entry will have the following:

Last Name, First Name
Street Address
City
State
Zip Code


Your program must have menu items and functionality for:

Open Address Book File
Save Address Book File
Display the address book (names only in alphabetical order by last name)
Display all information about an individual entry (allow the user to select this)
Add address entry
Delete address entry
To increase the speed of your program, the only times that you should be using the data files is: when the user first chooses to open an address book and when the user chooses to save an address book or closes the program

Explanation / Answer

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

namespace UNIT10_Astolfo_Rios_IT25
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}
public struct Address
{
public string first;
public string last;
public string address;
public string city;
public string state;
public string zip;

}
const int MAX_SIZE = 20;
Address[] contactArray = new Address[MAX_SIZE];
int counter;
private void button1_Click(object sender, EventArgs e)
{
// addinput values to structure
Address temp;
temp.first = txtFirstName.Text;

temp.last = txtLastName.Text;

temp.address = txtStreetAddress.Text;

temp.city = txtCity.Text;

temp.state = txtState.Text;

temp.zip = txtZipCode.Text;

contactArray[counter] = temp;

counter++;

UpdateTheList();

}
private void ContactsList_SelectedIndexChanged(object sender, EventArgs e)
{

string selected = ContactsList.SelectedItem.ToString();

//" "right here I get an erro message   


//loop


string contactname;

int i = 0;

for(i = 0; i < contactArray.Length; i++)

{

contactname = contactArray[i].last +" "+ contactArray[i].first;

if(contactname == selected)

{

break;

}

txtFirstName.Text = contactArray[i].first;

txtLastName.Text = contactArray[i].last;

txtStreetAddress.Text = contactArray[i].address;

txtCity.Text = contactArray[i].city;

txtState.Text = contactArray[i].state;

txtZipCode.Text = contactArray[i].zip;

}

}
privatevoidbtnDelete_Click(objectsender, EventArgse)

{

stringselected = ContactList.SelectedItem.ToString();

  

// "ContactList"erro message


  

//loop


  

stringcontactname;

  

inti = 0;

contactname = contactArray[i].last +

" "+ contactArray[i].first;

  

boolfoundInList = (contactname == selected);

  

while((i < counter) && (!foundInList))

{

i++;

contactname = contactArray[i].last +

" "+ contactArray[i].first;

foundInList = (contactname == selected);

}

  

if(foundInList)

{

if(i < counter)

{

contact Array[i] = contact Array[counter];

}

}

UpdateTheList();

counter--;

//There's now one less name


}
private void UpdateTheList()

{

//add input to the list box


ContactList.Items.Clear();

// "ContactList"erro message


string contactname;

for(int i = 0; i < contactArray.Length; i++) //If there's only 10 names why make 20 entries? This is not so picky


{

contactname = contact Array[i].last +" "+ contactArray[i].first;

ContactList.Items.Add(contactname);

}

//"ContactList"erro message
}
private void btnExit_Click(object sender, EventArgs e)

{   
this.Close();

}

}

}
}
}