国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C++ > 正文

C語言使用順序表實現電話本功能

2020-05-23 13:32:39
字體:
來源:轉載
供稿:網友

 簡介:

用順序表實現電話本的功能(C語言)

電話本具有如下4個功能:

1.創建一個電話本,電話本里面包含名字和電話號碼
2.在指定位置插入一個名字和電話號碼
3.在指定位置刪除一個名字和電話號碼
4.打印電話本

代碼:

//其中那個color函數是我為了美觀加上去的,如果感覺不需要的話可以將代碼中所有有關color的都刪掉即可#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <windows.h>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:"<<endl;  for(int i=1;i<=n;i++)  {     printf("    input the %d person name:",i);     scanf(" %s",s1.mylist[i-1].name);     printf("    input the %d person phonenumber:",i);     scanf(" %s",s1.mylist[i-1].number);     s1.len++;  }  color(9);  cout<<"   well done,the phonetxt has been created!!!"<<endl;  color(14);  return;}void Delet(sqlist &s1){  cout<<"   please enter the number you want to delet:";  heredelet:  int x;  scanf("%d",&x);  if( x<1 || x>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!!!"<<endl;  color(14);  return;}void Add(sqlist &s1){  cout<<"   please enter the number you want to add:";  hereadd:  int x;  scanf("%d",&x);  if( x<1 || x>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!!!"<<endl;  color(14);  return;}void Print(sqlist &s1){  color(8);  printf("    Name------phonenumber/n");  struct Node *q = s1.mylist;  for(q;q<s1.mylist+s1.len;q++)  {    printf("      %s    %s/n",q->name,q->number);  }  color(14);  color(9);  cout<<"   well done,the phonetxt is above!!!"<<endl;  color(14);  return;}void color(const unsigned short color1){      if(color1>=0&&color1<=15)  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color1);  else  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);  return;}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 黎川县| 庆安县| 江陵县| 四子王旗| 宜城市| 太和县| 桐柏县| 烟台市| 枣强县| 将乐县| 乐至县| 肇州县| 浦东新区| 安化县| 宁津县| 枣庄市| 临颍县| 栾川县| 龙泉市| 襄垣县| 巩留县| 罗定市| 绥滨县| 筠连县| 台州市| 特克斯县| 龙游县| 清流县| 肥东县| 商河县| 息烽县| 五华县| 梁平县| 克什克腾旗| 衡阳市| 灵川县| 平山县| 蓬莱市| 桐柏县| 神农架林区| 乌拉特后旗|