• AI创作!更智能、更完整、更原创
  • 这是一个超强AI智能对话机器人,它会写文章、做设计、绘图、敲代码,有问必答,回答你的所有问题。
🔥点击使用-AI高级问答 怎么样用AI-学教程

用C++编写一个通讯录的代码

时间2023-07-28 23:45:35 提问来自 北京市北京市 的网友 分类AI创作 浏览9638 热度0
#include <stdio.h> #include <string.h> #define MAX_CONTACTS 100 struct Contact { char name[30]; char phoneNumber[15]; }; void addContact(struct Contact contacts[], int *numContacts); void displayContacts(struct Contact contacts[], int numContacts); int main() { struct Contact contacts[MAX_CONTACTS]; int numContacts = 0; char choice; do { printf("Menu: "); printf("1. Add Contact "); printf("2. Display Contacts "); printf("3. Exit "); printf("Enter your choice: "); scanf(" %c", &choice); switch (choice) { case '1': addContact(contacts, &numContacts); break; case '2': displayContacts(contacts, numContacts); break; case '3': printf("Exiting... "); break; default: printf("Invalid choice. Please try again. "); } } while (choice != '3'); return 0; } void addContact(struct Contact contacts[], int *numContacts) { if (*numContacts == MAX_CONTACTS) { printf("Unable to add contact. Contact list is full. "); return; } struct Contact newContact; printf("Enter name: "); scanf("%s", newContact.name); printf("Enter phone number: "); scanf("%s", newContact.phoneNumber); contacts[*numContacts] = newContact; (*numContacts)++; printf("Contact added successfully. "); } void displayContacts(struct Contact contacts[], int numContacts) { if (numContacts == 0) { printf("No contacts found. "); return; } printf("Contact List: "); for (int i = 0; i < numContacts; i++) { printf("Name: %s ", contacts[i].name); printf("Phone number: %s ", contacts[i].phoneNumber); printf("---------------------- "); } }

AI创作问答(普通版)

AI创作问答(升级版)

智能问答AI写作网 免责声明:
本内容由智能问答AI写作网生成,请根据需求酌情使用,点击这里>>使用AI创作问答升级版,更聪明、更完整、更原创!
以上内容除特别注明外均来源于网友提问,智能问答AI写作网回答,权益归原著者所有;

上一篇 编写一个通讯录的代码 下一篇 怎么提高身体免疫力