新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
简介:
网站建设哪家好,找创新互联建站!专注于网页设计、网站建设、微信开发、微信平台小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了宜兴免费建站欢迎大家使用!用顺序表实现电话本的功能(C语言)
电话本具有如下4个功能:
1.创建一个电话本,电话本里面包含名字和电话号码
2.在指定位置插入一个名字和电话号码
3.在指定位置删除一个名字和电话号码
4.打印电话本
代码:
//其中那个color函数是我为了美观加上去的,如果感觉不需要的话可以将代码中所有有关color的都删掉即可 #include#include #include #include #include using namespace std; const int N = 1000+10; int n; struct Node { char name[100]; char number[20]; }; typedef struct { struct Node* mylist; int len; int listsize; }sqlist; void Init(sqlist &s1); void Creat(sqlist &s1); void Delet(sqlist &s1); void Add(sqlist &s1); void Print(sqlist &s1); void color(const unsigned short color1); int main() { sqlist s1; Init(s1); color(10); printf("\n\n\n\n --------------- WSM's phonetxt-------------------\n\n"); printf(" |You could chose these ops: |\n"); printf(" | 1.Creat the phonetxt |\n"); printf(" | 2.Delet the member in the phonetxt |\n"); printf(" | 3.Add the member in the phonetxt |\n"); printf(" | 4.Print the phonetxt |\n"); color(14); printf("\n\n\n\n Now,you can enter an optiton:"); int op; while(scanf("%d",&op)!=EOF) { if(op==1) Creat(s1); else if(op==2) Delet(s1); else if(op==3) Add(s1); else if(op==4) Print(s1); else { color(4); printf(" You input is invalid,reinput please:)\n"); color(14); } printf("\n Now,you can enter an optiton:"); } return 0; } void Init(sqlist &s1) { s1.mylist = (Node *)malloc(100*sizeof(Node)); s1.len = 0; s1.listsize = 100; return; } void Creat(sqlist &s1) { s1.len = 0; cout<<" how many numbers do you want to built:"; scanf("%d",&n); cout<<" please input their informations:"< s1.len) { color(4); cout<<" sorry,your input is invalid,please input again:"; color(14); goto heredelet; } struct Node *p,*q; p = &(s1.mylist[x-1]); q = s1.mylist + s1.len -1; for(++p;p<=q;++p) *(p-1) = *p; --s1.len; color(9); cout<<" well done,the member has been deleted!!!"< s1.len+1) { color(4); cout<<" sorry,your input is invalid,please input again:"; color(14); goto hereadd; } struct Node cur; printf(" input the person name:"); scanf(" %s",cur.name); printf(" input the person phonenumber:"); scanf(" %s",cur.number); struct Node *p,*q; q = &(s1.mylist[x-1]); for(p=&(s1.mylist[s1.len-1]);p>=q;--p) *(p+1) = *p; *q = cur; ++s1.len; color(9); cout<<" well done,the member has been added!!!"< name,q->number); } color(14); color(9); cout<<" well done,the phonetxt is above!!!"< =0&&color1<=15) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color1); else SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7); return; }
另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。