0
Reply

Allow user to edit or delete input list.

Ask a question
Kwan Rock

Kwan Rock

9y
417
1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Friend[] friend = new Friend[8];
            Friend tempFriend = new Friend();
            string[] firstName = new string[8];

            for (int a = 0; a < 8; a++)
            {
                friend[a] = new Friend();
            }

            for (int a = 0; a < 8; a++)
            {
                Console.Write("Input friend #{0}'s firstname: ", (a + 1));
                friend[a].FName = Console.ReadLine();
                Console.Write("Input friend #{0}'s lastname: ", (a + 1));
                friend[a].LName = Console.ReadLine();
                Console.Write("Input friend #{0}'s phone no.: ", (a + 1));
                friend[a].Phone = Console.ReadLine();
                Console.Write("Input friend #{0}'s birthmonth: ", (a + 1));
                friend[a].M = Convert.ToInt32(Console.ReadLine());
                Console.Write("Input friend #{0}'s birthday: ", (a + 1));
                friend[a].D = Convert.ToInt32(Console.ReadLine());
                Console.Write("Input friend #{0}'s birthyear: ", (a + 1));
                friend[a].Y = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine();
            }
            for (int a = 0; a < 8; a++)
            {
                for (int b = 0; b < 7; b++)
                {
                    if (string.Compare(friend[b].FName, friend[b + 1].FName) == 1)
                    {
                        tempFriend = friend[b + 1];
                        friend[b + 1] = friend[b];
                        friend[b] = tempFriend;
                    }
                }
            }



            for (int a = 0; a < 8; a++)
            {
                Console.WriteLine("Name#{0}: {1}, Phone No.: {2}, Birthday: {3}/{4}/{5}", (a + 1),
                 (friend[a].FName + " " + friend[a].LName), (friend[a].Phone), friend[a].M, friend[a].D, friend[a].Y);
            }

            string nameQuery;
            bool isFound = false;
            int indexFound = 0;
            Console.Write("\nInput your friend's first name: ");
            nameQuery = Console.ReadLine();

            for (int a = 0; a < 8; a++)
            {
                if (nameQuery.Equals(friend[a].FName))
                {
                    isFound = true;
                    indexFound = a;
                    break;
                }
            }

            if (isFound)
                Console.WriteLine("{0}'s birthday is {1}/{2}/{3}.",
                 nameQuery, friend[indexFound].M, friend[indexFound].D, friend[indexFound].Y);
            else
                Console.WriteLine("{0} is not on the friends list.", nameQuery);

            Console.WriteLine("FRIENDS WITH SAME BIRTHMONTH AS {0}:\n", nameQuery);
            for (int a = 0; a < 8; a++)
            {
                if (friend[indexFound].M == friend[a].M)
                {
                    Console.WriteLine("{0}'s birtday is {1}/{2}/{3}.",
                    (friend[a].FName + " " + friend[a].LName), friend[a].M, friend[a].D, friend[a].Y);
                }
            }

            Console.ReadLine();
        }
    }

    class Friend
    {
        string fName;

        public string FName
        {
            get { return fName; }
            set { fName = value; }
        }

        string lName;

        public string LName
        {
            get { return lName; }
            set { lName = value; }
        }


        string phone;

        public string Phone
        {
            get { return phone; }
            set { phone = value; }
        }
        int m, d, y;

        public int Y
        {
            get { return y; }
            set { y = value; }
        }

        public int D
        {
            get { return d; }
            set { d = value; }
        }

        public int M
        {
            get { return m; }
            set { m = value; }
        }

        private void AddItemToListView()
        {

            ListViewItem item = listView1.Items.Add(String.Empty);
            item.BeginEdit();
        }
    }
}