Hi there I am trying to a create an Address Book program using an 2d array (only).
The address book must store the Names address, postcodes in a 2d array.

The Naming format must be : Surname , Firstname (e.g. Family name, Given name).
The Address format must be : 7, pembroke, newcity (e.g. Number, Road Name, Town Name)
The menu system must offer the following choices

1 Add Entry
2 Delete Entry
3 Print Book to Screen
4 Edit a Record
5 Search for a record using either Surname, Firstname or Road Name

And the Use of Methods would also help.

the array must start with with strings “XXXXXX” and when a record is deleted replace its value with “XXXXXX”. Any cell containing “XXXXXX” is now available for use.

Sorting of entries alphabetically in the array would be very helpful for the user to read.


Here is my code so far:

using

System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Assignment_2011{}

   class Program
    {
        
    
       

    static void Main()
    {
        ArrayList address = new ArrayList { };
        Boolean menu = true;
        
        
    
      string s2, s3, s4, s5, s6, s7, s8, s9, s10, s11;
     
       
       // Creates a 2d array and loads it
        string[,] a = new string[11,2]; 
              
     public static int Choice;
    // Declaring the strings in the array all as X
     string s1 = 1.XXXXXX; 
     string s2 = 2.XXXXXX;
     string s3 = 3.XXXXXX;
     string s4 = 4.XXXXXX;
     string s5 = 5.XXXXXX;
     string s6 = 6.XXXXXX;
     string s7 = 7.XXXXXX;
     string s8 = 8.XXXXXX;
     string s9 = 9.XXXXXX;
     string s10 = 10.XXXXXX;
     string s11 = 11.XXXXXX;
   
         
         
        // Main Menu for my console program
            do
   {

        Console.WriteLine("**********************************");
        Console.WriteLine("Press 1 to Add a new record");
        Console.WriteLine("Press 2 to Remove a record");
        Console.WriteLine("Press 3 to Print book to screen");
        Console.WriteLine("Press 4 to Quit the program");
        Console.WriteLine("Press 5 to Search for a record");
        Console.WriteLine("Press 6 to Edit a record");
        Console.WriteLine("Press 7 to Save entries to txt file");
        Console.WriteLine("Press 8 to Print the txt file");

       Converttoin32.Choice = (Console.ReadLine());
    
        if (Choice == 1)
    {
            Console.WriteLine("Please Enter your Lastname");
            string s1 = Console.ReadLine();
            
            Console.WriteLine("Please Enter your Firstname");
            string s1 = Console.ReadLine();
            
            Console.WriteLine("Please Enter your Address");
            s1 = Console.ReadLine();
            
            Console.WriteLine("Please Enter your Town");
            string s1 = Console.ReadLine();

            Console.WriteLine("Please Enter your Postcode");
            string s1 = Console.ReadLine();
        }

        if (Choice == 2)
        {
            Console.WriteLine("Please enter the record you want to remove");
            Console.ReadLine();
            for int (a.RemoveAt ( myArrayList.IndexOf (  Console.ReadLine(); ) );
            a.Sort();
            a.Remove("4");

        }



        if (Choice == 3)
        {
              
        for (int i = Choice; i < a.Length / 5; i++)  
 
            s1 = a[i,0];
            s2 = a[i,1];
            s3 = a[i,2];
            s4 = a[i,3];
            s5 = a[i,4];
            s6 = a[i,5];
            s7 = a[i,6];
            s8 = a[i,7];
            s9 = a[i,8];
            s10 = a[i,9];
            s11 = a[i,11];

            Console.WriteLine(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11);
            Console.ReadLine();
        }
        Console.WriteLine();

       

            if (Choice == 5)
            {
            Console.WriteLine("Please enter the record you like to locate:");
            Console.ReadLine();
            for (int i = 1; i <= a.Length; i++){if (a[i] ==  Console.ReadLine())
            {Console.WriteLine("Hello there this matches your search");}}
           
            }
            

        if (Choice == 6)
        {
            
            


        }

    
        if (Choice == 7)
        {
            
            


        }



        if (Choice == 8)
        {
  }
       
           
        
        } while(menu == true);

            

      
CODE]

Yeah sorry I have to use a 2D array only.

OK, well without using the List<string> in the other example, can you model your program after it so it will (at least) compile? After that, we can put some content in it.

Hello there here is my program again now using strings just need the menus to appear at the correct times e.g. after the contiues and the search record is not quite working here is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{

    namespace Address_Program
    {
        public class AddressBookProgram
        {
            public static string str1;
            public static string str2;
            public static string str3;
            public static string str4;
            public static string str5;
            public static string str6;
            public static string str7;
            public static string str8;
            public static string str9;
            public static string str10;
            public static string str11;
            public static string str12;
            public static string str13;




            public static string[,] Address = new string[12, 5];
            public static string s1 = Address[1,0] = string.Format("1.XXXXXX");
            public static string s2 = Address[2,0] = string.Format("2.XXXXXX");
            public static string s3 = Address[2,0] = string.Format("3.XXXXXX");
            public static string s4 = Address[3,0] = string.Format("4.XXXXXX");
            public static string s5 = Address[4,0] = string.Format("5.XXXXXX");
            public static string s6 = Address[5,0] = string.Format("6.XXXXXX");
            public static string s7 = Address[6,0] = string.Format("7.XXXXXX");
            public static string s8 = Address[7,0] = string.Format("8.XXXXXX");
            public static string s9 = Address[8,0] = string.Format("9.XXXXXX");
            public static string s10 = Address[9,0] = string.Format("10.XXXXXX");
            public static string s11 = Address[10,0] = string.Format("11.XXXXXX");
           

            public static void ShowMenu()
            
            
            {
                Console.ReadLine();
                Console.WriteLine(
                    "1 Add Records\n" +
                    "2 Remove Record\n" +
                    "3 Print Book to Screen\n" +
                    "4 Edit a Record\n" +
                    "5 Search for a record\n" +
                    "6 Quit the program/n" +
                    "7 Save records to txt file/n" +
                    "8 Print the txt file");



            }       



            public static void Display()
            {
                Console.WriteLine();
                Console.WriteLine();
            }

            private static void Main(string[] args)
            {
                Console.WriteLine("Welcome to the Address Book Program");

                char chrChoice = ' ';

                while (!chrChoice.Equals('6'))
                {
                    ShowMenu();
                    chrChoice = Console.ReadLine().Trim()[0];

                    switch (chrChoice)
                    {
                        case '1':

                            ShowMenu();
                           Console.WriteLine("Please Enter your Lastname");
                           str1 = Console.ReadLine();
                            
                           Console.WriteLine("Please Enter your Name");
                           str2 = Console.ReadLine();

                           Console.WriteLine("Please Enter your Address");
                           str3 = Console.ReadLine();

                           Console.WriteLine("Please Enter your Town");
                           str4 = Console.ReadLine();

                           Console.WriteLine("Please Enter your Postcode");
                           str5 = Console.ReadLine();

                           s1 = ("1." + str1 + Environment.NewLine + str2 + Environment.NewLine + str3 + Environment.NewLine + str4 + Environment.NewLine + str5 + Environment.NewLine);
                            
                            

                          Console.WriteLine("Please Enter your Lastname");
                          str6 = Console.ReadLine();
                           
                          Console.WriteLine("Please Enter your Name");
                          str7 = Console.ReadLine();

                          Console.WriteLine("Please Enter your Address");
                          str8 = Console.ReadLine();

                          Console.WriteLine("Please Enter your Town");
                          str9 = Console.ReadLine();

                          Console.WriteLine("Please Enter your Postcode");
                          str10 = Console.ReadLine();


                          s2 = ("2." + str6 + Environment.NewLine + str7 + Environment.NewLine + str8 + Environment.NewLine + str9 + Environment.NewLine + str11 + Environment.NewLine);


                                
                                break;

                        

                        case '2':
                          Console.WriteLine("Please Enter the record you want to remove");
                     

                            break;

                        case '3':

                           Console.WriteLine(s1 + Environment.NewLine + s2 + Environment.NewLine);
                            Console.ReadLine();
                            break;

                        case '4':
                            //Edit
                            break;

                        case '5':
                         
                         Console.WriteLine("Please enter the word for searching");
                         
                         
                         if (s1 == Console.ReadLine()){Console.WriteLine("Hey there this matches your search :)");}
                                      
                         break;

                        case '6':
                            //Quit
                            break;
                    }
                }
            }
        }
    }
}

Need help using examples for the program using the code above, To the instructions from the first post.

Thanks.

What goes in the left side of the 2d array and what goes in the right side?

Left side = Columns
Right side = Rows

All these are for the records.

Right now I am stuck on editing and removing records as string.

Please help.

Columns of what?

You will have greater success sticking with one design.
If you try to work on two things, neither will work well.

The container you put your records in is critical to the design.

Think about an actual Address book. The data is grouped into "records" where each record has a name, address, phone number, city, state and zip.
Nothing about that says 2D array to me.

I guess you could force it to have the id on one side and ALL of the data on the right (layed out as 1 string). ...but that doesn't make sense either because the ID can simply be the unique position of a single-dimension array or even a list of strings.

Thanks for the advice you are right I just need the code to remove and edit string/records based on the users input selection e.g. Console.ReadLine();

How would I do this??

Thanks.

Are they contained in the array or a list?

They just inside strings at the moment for the firstname etc
Here is my code so far for the address book program:

using System;
using System.IO;

namespace ConsoleApplication2
{

    namespace Address_Program
    {
        public abstract class AddressBookProgram
        {
            public class Contact
{
    public string FirstName { get; set;}
    public string LastName  { get; set;}
}
            public static string str1;
            public static string str2;
            public static string str3;
            public static string str4;
            public static string str5;
            public static string str6;
            public static string str7;
            public static string str8;
            public static string str9;
            public static string str10;
            public static string str11;
            public static string str12;
            public static string str13;
            public static string newstring = s1;
            public static string searchFor;
            public static string replaceWith;

            


        








            public static string[,] Address = new string[12, 5];
            public static string s1 = Address[1,0] = string.Format("1.XXXXXX");
            public static string s2 = Address[2,0] = string.Format("2.XXXXXX");
            public static string s3 = Address[2,0] = string.Format("3.XXXXXX");
            public static string s4 = Address[3,0] = string.Format("4.XXXXXX");
            public static string s5 = Address[4,0] = string.Format("5.XXXXXX");
            public static string s6 = Address[5,0] = string.Format("6.XXXXXX");
            public static string s7 = Address[6,0] = string.Format("7.XXXXXX");
            public static string s8 = Address[7,0] = string.Format("8.XXXXXX");
            public static string s9 = Address[8,0] = string.Format("9.XXXXXX");
            public static string s10 = Address[9,0] = string.Format("10.XXXXXX");
            public static string s11 = Address[10,0] = string.Format("11.XXXXXX");
          
         

            public static void ShowMenu()
            
            
            {
                Console.ReadLine();
                Console.WriteLine(
                    "1 Add Records\n" +
                    "2 Remove Record\n" +
                    "3 Print Book to Screen\n" +
                    "4 Edit a Record\n" +
                    "5 Search for a record\n" +
                    "6 Quit the program\n" +
                    "7 Save records to txt file\n" +
                    "8 Print the txt file \n" +
                    "9 Search for records in a txt file");


            }       



            public static void Display()
            {
                Console.WriteLine();
                Console.WriteLine();
            }

            private static void Main(string[] args)
            {
                Console.WriteLine("Welcome my Address Book Program");

                char chrChoice = ' ';

                while (!chrChoice.Equals('6'))
                {
                    ShowMenu();
                    chrChoice = Console.ReadLine().Trim()[0];

                    switch (chrChoice)
                    {
                        case '1':

                            ShowMenu();
                           Console.Clear();
                           Console.WriteLine("Please Enter your Lastname");
                           str1 = Console.ReadLine();
                            
                           Console.WriteLine("Please Enter your Firstname");
                           str2 = Console.ReadLine();

                           Console.WriteLine("Please Enter your Address");
                           str3 = Console.ReadLine();

                           Console.WriteLine("Please Enter your Town");
                           str4 = Console.ReadLine();

                           Console.WriteLine("Please Enter your Postcode");
                           str5 = Console.ReadLine();

                           s1 = ("1." + str1 + Environment.NewLine + str2 + Environment.NewLine + str3 + Environment.NewLine + str4 + Environment.NewLine + str5 + Environment.NewLine);
                            
                            
                          Console.Clear();
                          Console.WriteLine("Please Enter your Lastname");
                          str6 = Console.ReadLine();

                          Console.WriteLine("Please Enter your Firstname");
                          str7 = Console.ReadLine();

                          Console.WriteLine("Please Enter your Address");
                          str8 = Console.ReadLine();

                          Console.WriteLine("Please Enter your Town");
                          str9 = Console.ReadLine();

                          Console.WriteLine("Please Enter your Postcode");
                          str10 = Console.ReadLine();


                          s2 = ("2." + str6 + Environment.NewLine + str7 + Environment.NewLine + str8 + Environment.NewLine + str9 + Environment.NewLine + str11 + Environment.NewLine);


                                
                                break;

                  

                         case '2':
                          Console.WriteLine("Please enter the string you would like to remove");
                       

                            break;

                         case '3':
                          Console.Clear();
                          Console.WriteLine(s1 + Environment.NewLine + s2 + Environment.NewLine);
                          Console.ReadLine();
                            break;

                        case '4':

                      
                           
                            
   
                            


                            {
                          }


                            Console.WriteLine(s1);
                            break;
                        case '5':



                        Console.WriteLine("Please Enter a Word for Searching the records");
                        ArrayList.Contains(Console.ReadLine());
                        {Console.WriteLine("Hello there this matches your search"); }
      





         

                            break;

                       case '6':
                            //Quit
                            break;
                    
                      case '7':
                      StreamWriter sw = new StreamWriter("Records.txt");
                      sw.Write(s1 + s2);
                      sw.Close();

                            break;
                    
                    

                       case '8':
                           
                            break;

                       case '9':

                            break;



                    }



                }
            }

            protected static string ArrayList = (s1 + s2);
            {
                get { throw new NotImplementedException(); }
                set { throw new NotImplementedException(); }
            }

            protected static object app
            {
                get { throw new NotImplementedException(); }
                set { throw new NotImplementedException(); }
            }

            private static void Remove(string p)
            {
                throw new NotImplementedException();
            }

            protected static string Regex
            {
                get { throw new NotImplementedException(); }
                set { throw new NotImplementedException(); }
            }

            protected static string Convert
            {
                get {
                    return s1;
                }
                set {
                    s1 = value;
                }
            }
        }
    }

I understand! We need to start with the essentials and other things will become extremely clear afterward.

Once you get the "ADD" process down, it should be clear how to delete (or mark as deleted):

using System;
using System.IO;

namespace Address_Program
{
   public class AddressBookProgram
   {
      private static string[] arr_strFields =
         { "Last Name", "First Name", "Address", "Town", "Post Code" };

      private static string[,] Address = new string[12, 5]
      {  //LastName | FirstName | Address | Town | PostCode
         {"XXXXXX", "", "", "", ""},
         {"XXXXXX", "", "", "", ""},
         {"XXXXXX", "", "", "", ""},
         {"XXXXXX", "", "", "", ""},
         {"XXXXXX", "", "", "", ""},
         {"XXXXXX", "", "", "", ""},
         {"XXXXXX", "", "", "", ""},
         {"XXXXXX", "", "", "", ""},
         {"XXXXXX", "", "", "", ""},
         {"XXXXXX", "", "", "", ""},
         {"XXXXXX", "", "", "", ""},
         {"XXXXXX", "", "", "", ""}
      };

      public static void ShowMenu()
      {
         Console.WriteLine(
            "1 Add Records\n" +
            "2 Remove Record\n" +
            "3 Print Book to Screen\n" +
            "4 Edit a Record\n" +
            "5 Search for a record\n" +
            "6 Quit the program\n" +
            "7 Save records to txt file\n" +
            "8 Print the txt file \n" +
            "9 Search for records in a txt file");
      }

      private static int FindFirstAvailable()
      {
         int i = 0;
         int iMax = Address.GetLength(0) - 1;
         
         for (i = 0; i < Address.GetLength(0); i++)
         {
            if (Address[i,0].Equals("XXXXXX"))
            {
               break;
            }
         }

         if (i >= iMax)
         {
            i = -1;
         }

         return i;
      }

      private static void Add(int intRecNum)
      {
         Console.WriteLine("[Add record {0}:]\n", intRecNum);
         for (int i = 0; i < arr_strFields.Length; i++)
         {
            Console.Write("Please enter your {0}: ", arr_strFields[i]);
            Address[intRecNum, i] = Console.ReadLine();
         }
      }

      private static int Remove()
      {  // User will issue a 1-based record
         int intRecNum = -1;

         Console.Write("Enter the record number to remove: ");
         int.TryParse(Console.ReadLine(), out intRecNum);

         intRecNum -= 1;

         if ((intRecNum < 0) || intRecNum > (Address.GetLength(0) - 1))
         {
            return intRecNum;
         }

         Address[intRecNum, 0] = "XXXXXX";

         return intRecNum;
      }

      private static void Main(string[] args)
      {
         Console.WriteLine("Welcome my Address Book Program");
         
         int intFirstAvailable = 0;

         char chrChoice = ' ';
         while (!chrChoice.Equals('6'))
         {
            intFirstAvailable = FindFirstAvailable();

            ShowMenu();
            chrChoice = Console.ReadLine().Trim()[0];
            Console.Clear();

            switch (chrChoice)
            {
               case '1': // Add
                  if (-1 == intFirstAvailable) // is Full
                  {
                     Console.WriteLine("Address Book is full.  Please delete some records.");
                     break;
                  }

                  Add(intFirstAvailable);

                  break;

               case '2':  // Remove
                  int iRem = Remove();
                  Console.WriteLine("Record {0} Removed", (-1 == iRem) ? "not" : (1+iRem).ToString());
                  break;

               case '3':  // Print
                  break;

               case '4':  // Edit
                  break;

               case '5':  // Search
                  break;

               case '6':  // Quit
                  break;

               case '7':  // Save To File
                  break;

               case '8':  // Display File to Console
                  break;

               case '9':  // Search the file
                  break;
               default:
                  break;
            }
         }
      }
   }
}

Looks like someone has been getting some extra help with their assignment. Did't I say we had technology of tracking plagerism.

We will talk about this next semester.
Rgds Martin

Was it copied intact?

:(

:S

Ive seen this a few places on this site and around the web.
It seems to be very popular.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.