-7
#include<iostream>
#include<conio.h>
#include<stdio.h>
#include<cstring>

using namespace std;

int i, j;

struct info
{
    char name[20];
    int number;
};

void addcontact(info contactlist[]);

void editcontact(info contactlist[]);

void deletecontact(info contactlist[]);

void showallcontact(info contactlist[]);

void exit(info contactlist[]);

void menue(void);

void main()
{
    menue();
}

void menue(void)
{
    cout << "_______________________n";

    cout << "     PHONE BOOK        n";

    cout << "_______________________n";

    cout << "1-Add Contactn";

    cout << "2-Edit Contactn";

    cout << "3-Delete Contactn";

    cout << "4-Show All Contactsn";

    cout << "5-Exitn";

    int option;

    cin >> option;

    if (option == 1)
    {
        void addcontact(info contactlist[]);
    }
    else if (option == 2)
    {
        void editcontact(info contactlist[]);
    }
    else if (option == 3)
    {
        void deletecontact(info contactlist[]);
    }
    else if (option == 4)
    {
        void showallcontact(info contactlist[]);
    }
    else if (option == 5)
    {
        void exit(info contactlist[]);
    }
}



void addcontact(info contactlist[])
{
    i = 0;

    system("CLS");

    cout << "Welcome to Add contact sectionn";

    cout << "Enter namen";

    cin >> contactlist[i].name;

    cout << "Enter numbern";

    cin >> contactlist[i].number;

    cout << "Contact Addedn";

    i = i + 1;

    if (i == 19)
    {
        cout << "Contact limit reachedn";
    }

    menue();
}

void editcontact(info contactlist[])
{
    int flag = 0;
    int k;
    char name[20];

    system("CLS");

    cout << "Welcome to Edit contact sectionn";

    cout << "Enter name to editn";

    cin >> name;

    for (int k = 0; k < 20; k++)
    {
        if (strcmp(name, contactlist[k].name) == 0);
        {
            flag = 1;
            break;
        }
    }

    if (flag == 1)
    {
        cout << "Enter a new namen";

        cin >> contactlist[k].name;

        cout << "Contact Editedn";

        menue();
    }
    else if (flag != 1)
    {
        cout << "No record foundn";
    }
}

void deletecontact(info contactlist[])
{
    char name[20];

    cout << "Enter name of contact to be deleted" << endl;

    cin >> name;

    for (int i = 0; i < 20; i++)
    {
        if (strcmp(name, contactlist[i].name) == 0)
        {
            strcpy(contactlist[i].name, " ");

            cout << "contact deletedn" << endl;

            menue();
        }
    }
}

void showallcontacts(info contactlist[])
{
    int l;

    cout << "detailsn";

    for (l = 0; l < 20; l++)
    {
        cout << contactlist[l].name << endl;
        cout << contactlist[l].number << endl;

        menue();
    }
}



void exit()
{
    exit(0);
}
4

1 回答 1

3

您的代码没有任何意义。你写的有很多问题

我不会全部介绍,但最明显的是

if (option == 1) {
    void addcontact(info contactlist[]);
}

这不是调用函数的方式。相反,它应该看起来像

if (option == 1) 
{
    addcontact(x);
}

其中 X 是您尚未定义的“信息”类型的对象。

我强烈建议找一些基本的编程教程来更好地熟悉你在做什么。

于 2013-07-24T18:04:25.827 回答