We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,737 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

array addressbook

I've got a university assignment and just need to know how to remove an entry from the address book and use it as a method

Here's what I have so far, everything's fine apart from the removing, please make it quite simple

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

namespace Assignment2
{
    class Program
    {
        // strings for arrays
        public static string name;
        public static string name2;
        public static string address;
        public static string address2;

        public static bool addressbookloop = false;
        public static string selectioninput;
        public static char selection;


        static void addcontact(string[,] addressbook)
        {
            Console.WriteLine();


            Console.WriteLine("You want to add a new entry");
            Console.WriteLine("Press enter to continue");
            Console.ReadLine();

            Console.WriteLine("Please type in the contacts first name");
            name = Console.ReadLine();

            Console.WriteLine("And what is the contacts last name");
            name2 = Console.ReadLine();

            Console.WriteLine("Please type in the contacts house number and street name");
            address = Console.ReadLine();

            Console.WriteLine("Please type in the contacts town / city");
            address2 = Console.ReadLine();

            Console.WriteLine("CONTACT SAVED");

            Console.WriteLine();

            // Sending to Array
            int i = 0; bool Xs = false;
            do
            {
                if (addressbook[i, 0] == "XXXXXXX")
                {
                    addressbook[i, 0] = name;
                    addressbook[i, 1] = name2;
                    addressbook[i, 2] = address;
                    addressbook[i, 3] = address2;

                    Xs = true;
                }
                else
                {
                    i++;
                }

            } while (Xs == false);

        }

        static void removecontact(string[,] addressbook)
        {
            Console.WriteLine("Which contact do you want to delete");
            
                Console.WriteLine("You wish to delete {0} {1}, {2} {3}'s address.", name, name2, address, address2);
                Console.ReadLine();
   
        }


        static void showaddresses(string[,] addressbook)
        {
            Console.WriteLine("*** Address Book ***");
            Console.WriteLine();
            for (int i = 0; i < addressbook.GetLength(0); i++)
            {
                name = addressbook[i, 0];
                name2 = addressbook[i, 1];
                address = addressbook[i, 2];
                address2 = addressbook[i, 3];
                Console.WriteLine("{0} {1}, {2}, {3}", name, name2, address, address2);
            }
            Console.WriteLine();
            Console.WriteLine("Press enter to go back to the homepage");

        }

        static void Main()
        {
            // starting array
            string[,] addressbook = new string[10, 4];

            for (int i = 0; i < addressbook.GetLength(0); i++)
            {
                for (int j = 0; j < addressbook.GetLength(1); j++)
                {
                    addressbook[i, j] = "XXXXXXX";
                }
            }

            do
            {
                Console.WriteLine("*** My Address Book ***");
                Console.WriteLine();
                Console.WriteLine("Which option would you like to choose");
                Console.WriteLine();
                Console.WriteLine("1. Add new entry");
                Console.WriteLine("2. Remove entry");
                Console.WriteLine("3. Show address book");
                Console.WriteLine();
                Console.WriteLine("Please enter your selection below");
                selectioninput = Console.ReadLine();
                selection = Convert.ToChar(selectioninput);

                switch (selection)
                {
                    case '1':
                        // Add Contact
                        addcontact(addressbook);
                        break;
                    case '2':
                        // Remove contact

                        removecontact(addressbook);
                        break;
                    case '3':
                        // Show addresses
                        showaddresses(addressbook);
                        Console.ReadLine();
                        break;
                    default:
                        Console.WriteLine("This is an invalid selection, Please Try Again");
                        Console.WriteLine();
                        break;

                }
            }
            while (addressbookloop == false);
             


        }

    }
}
4
Contributors
5
Replies
1 Day
Discussion Span
1 Year Ago
Last Updated
6
Views
tom92united
Newbie Poster
1 post since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

There are a couple of other UK students working on the same thing.
Please check this post. Maybe you can work together.

thines01
Postaholic
Team Colleague
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7

Hi,

You can try removing from array's "removeat(array index) " method to remove particular record..

thanx.

kamilacbe
Junior Poster in Training
89 posts since Jun 2010
Reputation Points: 10
Solved Threads: 11
Skill Endorsements: 0

You can try removing from array's "removeat(array index) " method to remove particular record.

From what I understand from looking at the other two sets of requirements, they are supposed to mark the records as available for overwrite by filling the first element in the array with six X "XXXXXX".

thines01
Postaholic
Team Colleague
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7

Do you HAVE to use arrays? They aren't exactly tuned performance-wise for remove operations. A linked list or binary tree would be the ideal datastructures here.

skatamatic
Posting Shark
986 posts since Nov 2007
Reputation Points: 403
Solved Threads: 132
Skill Endorsements: 1

I'm assuming this is for academic purposes only.
Ive seen this a few places on this site and around the web.

Maybe the next lesson will be "Look how much easier this is with classes and collections". :D

thines01
Postaholic
Team Colleague
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0727 seconds using 2.75MB