DS Assignment 1

Embed Size (px)

Citation preview

  • 7/29/2019 DS Assignment 1

    1/6

    CSC 1023 Data Structures Second Trimester Jan-April 2013

    Assignment 1Part 1

    Date Released10th Feb 2013

    Date of Submission: 18th Feb 2013 12:00 Midnight

    (Late Submission Policy-

    19th Feb 12:00 Midnight, your marks will be multiplied by 0.9

    20th

    Feb 12:00 Midnight, your marks will be multiplied by 0.8

    21st Feb 12:00 Midnight, your marks will be multiplied by 0.7

    22nd Feb 12:00 Midnight, your marks will be multiplied by 0.6

    23rd Feb 12:00 Midnight, your marks will be multiplied by 0.5

    24th Feb 12:00 Midnight, your marks will be multiplied by 0.4

    25th Feb 12:00 Midnight, your marks will be multiplied by 0.3

    After 25th Feb 2013, assignment will not be accepted.

    )

    You can do the assignment in groups of two students. In each file, names of both the students

    and their student ids, should be written in comments. There should be proper alignment of all

    statements in your programs. Use appropriate readable variable names and method names so

    that your program is readable. If programs of two groups are found same or

    almost similar, appropriate action will be taken against both groups.

    Please send your softcopies of your project in zipped files to [email protected]

    Description of Assignment

    In this assignment, you are required to develop a Phone Directory Application using Generic

    Array List (code was given to you in class). Using this application, you should be able to add

    new name/phone number pairs to arraylist, given the name search phone number, modify

    existing number, and delete existing name/number pair from arraylist.

    This application will use following classes:

    DirectoryEntry Class

  • 7/29/2019 DS Assignment 1

    2/6

    MyArrayList Class

    PhoneDirectory Class

    The skeleton of all these classes and required methods are given below. You need to read

    these first read and understand the given classes and complete the classes and run theapplication. Sample output of the execution of application should produce the output as in the

    attached notepad file.

    //Start of Phone Book Application

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    namespace PhoneApplication

    {

    class DirectoryEntry // Class DirectoryEntry

    {

    string name;

    string phoneNumber;

    //constructor

    public DirectoryEntry( two parameter constructor)

    { . }

    public void SetPhoneNumber (.)

    { .. }

    public string GetName ()

    { }

    public string GetPhoneNumber( )

    {.}

    public override string ToString()

    {

  • 7/29/2019 DS Assignment 1

    3/6

    string entry = "\n\nName = "+ name+" \nPhone Number = "+ phoneNumber;

    return entry; } // End of Class DirectoryEntry

    //Start of Generic Class MyArrayList

    public class MyArrayList

    {

    T[ ] data;

    public int numOfElements;

    public MyArrayList( )// Constructor without paramerts

    {. }

    public void Add(T newElement) // Method for adding a new element to MyArrayList

    {}

    private void Reallocate( )// Method for allocating space for new array

    {.}

    public T Remove(int index)//Method for removing an element from MyArrayList at

    {} //index position

    public T Get(int index) //Method for returning an element at index

    {. }

    public T Set(int index, T newValue) //Method for setting a new value at a given index

    {..} // position and returning old element

    public int Count ()//Method for returning number of elements in MyArrayList

    {}

    }//End of generic MyArrayList Class

    //Start of PhoneDirectory Class

    class PhoneDirectory

    {

    MyArrayList phoneBook;

    //Method for adding a Directory Entry to phonebook

  • 7/29/2019 DS Assignment 1

    4/6

    public void AddEntry (DirectoryEntry DE)

    {. }

    //Method for printing all entries in phoneBook

    public void PrintDirectory()

    {..}// end of printDirectory

    //Method for Displaying Menu

    public void DisplayMenu ()

    { .

    .

    switch (choice)

    {

    case 1: AddPhoneEntry(); break;

    case 2: SearchPhoneNumber(); break;

    case 3: DeletePhoneEntry(); break;

    case 4: ModifyPhoneNumber(); break;

    case 5: PrintDirectory(); break;

    case 6: ExitDirectoryApplication(); break;

    default: Console.WriteLine("Invalid Choice. Please enter correct choice");

    break;

    }

    } while ( choice != 6);

    }

    //This AddPhoneEntry method asks user to enter name and phone number and adds entry

    //to thephonebook by calling AddEntry() method, which you need to write yourself

    public void AddPhoneEntry()

    {

    string name, phoneNumber;

    Console.Write("Enter name : ");

  • 7/29/2019 DS Assignment 1

    5/6

    name = Console.ReadLine();

    Console.Write("\nEnter the Phone Number: ");

    phoneNumber = Console.ReadLine();

    AddEntry (new DirectoryEntry (name, phoneNumber));

    }

    //This method asks user to enter name and this method will search the corresponding

    //phone number. I f the name does not exist then it should display appropriate message.

    public string SearchPhoneNumber()

    { ..}

    //This method should ask the user to enter name and this method will search the

    //corresponding phone number. I f the name does not exist then it should display

    //appropriate message. Else it should remove the entry from the phonebook and display the

    message that it has been deleted.

    public void DeletePhoneEntry()

    {.}

    // This method should ask the user to enter name and it will search the name in the

    //phone book. I f the name does not exist then it should display appropriate message.//Else it should ask the user to enter new phone number and replace it in the phonebook.

    //This method should also display modified entry.

    public void ModifyPhoneNumber()

    {. }

    //This method written to exit from application

    public void ExitDirectoryApplication()

    {

    Console.WriteLine("\n\n Bye Bye");

    Console.ReadKey();

    System.Environment.Exit(0);

    }

    public static void Main()

    {

  • 7/29/2019 DS Assignment 1

    6/6

    PhoneDirectory pd = new PhoneDirectory();

    pd.phoneBook = new MyArrayList ();

    pd.DisplayMenu();

    Console.ReadKey();

    }

    }

    }//End of Application