اذهب إلى المحتوى
  • 0

Data Structure And Algorithms

اسما محمد

السؤال

Develop A Contact Book Application

Write a C++ program to simulate a contact book that should hold the
following details 1) the first name, 2) the last name, and 3) contact numbers
(each contact can maximally have 3 numbers). Where contacts must be
stored in order according to the first name from A to Z. The user of the
system must have the ability to :
1. Add new contact
2. Edit an available contact (first name, last name, or a contact number)
3. Search a contact (even by contact name or number)
4. Delete a contact
5. Display contacts. This action must present only one contact and the user
can go forward or backward to see other persons. (display starts from A
and ends at Z)
6. Display the total number of contacts
7. Clear the book

حدن بقدر يحل هيدا السوال

رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 1

التمرين طويل لكن سأحاول الإجابة عن الأسئلة الأساسية التي يتم عليها بناء والإجابة عن باقي الأسئلة التي يتضمنها التمرين

أولاً سأطرح كود إضافة مستخدم جديد :

// الكود التالي موجود داخل الأداء الرئيسي
cout << Add New Contact\t\t\t\tpress $ to cancel << endl;
printline(‘-‘, 20);
counter = 0;

              //Loop till correct name and mobile variety area unit entered
            do
            {
                flag = 0;
                if(counter)
                    cout << "Try again\t\t\t\tpress $ to cancel" 
                    << endl;

                //counts how many times the do-while loop executes
                counter++; 

                cout << "Name: "; cin >> temp_name;

                //Cancel operation
                if(temp_name=="$")
                {
                    cancel_flag = 1;
                    break;
                }
                cout << "Mobile No.: "; cin >> temp_mob;

                //Cancel operation
                if(temp_mob=="$")
                {
                    cancel_flag = 1;
                    break;
                }

               //Check whether or not name exists
                for(i=0; i<100; i++)
                    if(person[i].name_exists(temp_name))
                    {
                        cout << "The name you entered is already there" 
                        " in the telephone directory, enter a distinct name." 
                        << endl;
                        flag = 1;
                        break;
                    }

            }while(!name_valid(temp_name) || 
                            flag ||
                    !mob_valid(temp_mob));

            if(cancel_flag)
            {
                system("cls");
                break;
            }


            //This code adds the contact to phonebook    
            for(i=0; i<100; i++)
                if(person[i].add(temp_name, temp_mob))
                {
                    cout << "Contact added successfully!" << endl;
                    flag = 1;
                    break;
                }

            if(!flag)
                cout << "Memory full! Delete some contacts first." 
                << endl;
// الكود التالي موجود في الكلاس
bool add(string new_name, string new_mob)
{
if(name==””)
{
name = new_name;
mob = new_mob;
return 1; // نجاح
}
else
return 0; // فشل العملية

    }

لتعديل بيانات المستخدم نعتمد :

cout << Enter a contact name to edit:” \t\t\t\tpress $ to cancel\n”; cin >> temp_name;

            //Cancel Operation
            if(temp_name=="$")
            {
                system("cls");
                break;
            }

            for(i=0; i<100; i++)
                if(person[i].edit(temp_name))
                {
                    cout << "Edited Successfully!" << endl;
                    flag = 1;
                    break;
                }

            if(!flag)
                cout << "Contact name not found!" << endl;
// the subsequent code resides within the category
bool contact :: edit(string new_name)
{
string new_mob;
if(new_name==name)
{
cout << Enter new name: “; cin >> new_name;
cout << Enter new mobile no: “; cin >> new_mob;

    name = new_name;
    mob = new_mob;
    return 1;
}
else
    return 0;
}

وبالنسة لطريقة حذف مستخدم نعتمد الكود التالي :

do
{
if(counter)
cout << Try again << endl; counter++; cout << Enter a contact name to delete:” \t\t\tpress $ to cancel\n”; cin >> temp_name;

                //Cancel Operation
                if(temp_name=="$")
                {
                    system("cls");
                    break;
                }


                //Final Confirmation
                for(i=0; i<100; i++)
                if(person[i].name_exists(temp_name))
                {
                    flag = 1;
                    cout << "Are you sure you want to delete? (1/0)" 
                    << endl;
                    int yes;
                    cin >> yes;
                    if(!yes)
                    {
                        system("cls");
                        cancel_flag = 1;
                    }
                    break;
                }

                if(!flag)
                    cout << "Contact name not found!" << endl;

                if(cancel_flag)
                    break;

                // This code deletes the contact
                if(flag)
                {
                    for(i=0; i<100; i++)
                        if(person[i].erase(temp_name))
                        {
                            cout << "Deleted successfully!" << endl;
                            break;
                        }
                }

            }while(!flag);
// the subsequent code resides within the category
bool erase(string new_name)
{
if(new_name==name)
{
name = “”;
mob = “”;
return 1;
}
else
return 0;
}

الكود التالي هو لعرض بيانات المستخدم :

cout << Showing Contacts << endl;
printline(‘-‘, 20);

            for(i=0; i<100; i++)
                if(person[i].show())
                    flag = 1;

            if(!flag)
                cout << "No contacts found!" << endl;
//This block of code resides within the category
bool show()
{
if(name != “”)
{
cout << name << \t << mob << endl;
return 1; //Indicates success
}
else
return 0; //Indicates failure
}

للبحث نستخدم الكود التالي :

do
{
if(counter)
cout << Try again << endl; counter++; cout << Search a name: \t\t\t\tpress $ to cancel\n”; cin >> temp_name;

                //Cancel Operation
                if(temp_name=="$")
                {
                    system("cls");
                    break;
                }

                for(i=0; i<100; i++)
                    if(person[i].show(temp_name))
                    {
                        flag = 1;
                        break;
                    }

                if(!flag)
                    cout << "Contact name not found" << endl;
            }while(!flag);
// the subsequent code resides within the category
bool show(string search_term)
{
if(search_term == name)
{
cout << name << \t << mob << endl;
return 1;
}
else
return 0;
}

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...