欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C語言使用順序表實現(xiàn)電話本功能

 更新時間:2018年02月15日 10:08:50   作者:WANSNIM  
這篇文章主要為大家詳細介紹了C語言使用順序表實現(xiàn)電話本功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下

 簡介:

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

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

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

代碼:

//其中那個color函數(shù)是我為了美觀加上去的,如果感覺不需要的話可以將代碼中所有有關(guān)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;
}

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 深入理解C++中std::chrono庫的使用

    深入理解C++中std::chrono庫的使用

    在程序設(shè)計中,時間管理是一個核心概念,它不僅關(guān)系到程序的效率和性能,而且直接影響用戶體驗,C++作為一門高效的編程語言,提供了std::chrono庫,用于精確地處理和計算時間,下面就跟隨小編一起學習一下std::chrono庫的使用吧
    2023-12-12
  • 淺談時間戳與日期時間互轉(zhuǎn)C語言

    淺談時間戳與日期時間互轉(zhuǎn)C語言

    下面小編就為大家?guī)硪黄獪\談時間戳與日期時間互轉(zhuǎn)C語言。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-06-06
  • C++超詳細分析紅黑樹

    C++超詳細分析紅黑樹

    這一篇我要跟大家介紹二叉搜索樹中的另一顆樹——紅黑樹,它主要是通過控制顏色來控制自身的平衡,但它的平衡沒有AVL樹的平衡那么嚴格
    2022-03-03
  • 基于C語言實現(xiàn)的迷宮游戲代碼

    基于C語言實現(xiàn)的迷宮游戲代碼

    這篇文章主要介紹了基于C語言實現(xiàn)的迷宮游戲代碼,對于學習游戲開發(fā)的朋友相信有一定的借鑒價值,需要的朋友可以參考下
    2014-08-08
  • 一問了解C++ 的移動語義

    一問了解C++ 的移動語義

    本文主要介紹C++ 的移動語義,移動語義并不是一個容易理解的概念,很多程序員可能對其存在一定的疑惑,今天我們就來探討一下 C++ 中的移動語義
    2023-04-04
  • 讓應用程序只運行一個實例的實現(xiàn)方法

    讓應用程序只運行一個實例的實現(xiàn)方法

    我們在使用《360軟件管家》時發(fā)現(xiàn),在《360軟件管家》已經(jīng)運行了的情況下,再次點擊《360軟件管家》的圖標,那么它不會再運行另外一個《360軟件管家》,而是將已有的《360軟件管家》給激活,始終只能運行一個《360軟件管家》的實例
    2013-05-05
  • C語言數(shù)據(jù)結(jié)構(gòu)之線性表的鏈式存儲結(jié)構(gòu)

    C語言數(shù)據(jù)結(jié)構(gòu)之線性表的鏈式存儲結(jié)構(gòu)

    線性表是最基本、最簡單、也是最常用的一種數(shù)據(jù)結(jié)構(gòu)。線性表(linear list)是數(shù)據(jù)結(jié)構(gòu)的一種,一個線性表是n個具有相同特性的數(shù)據(jù)元素的有限序列,這篇文章帶你學習下線性表的鏈式存儲結(jié)構(gòu)
    2021-11-11
  • 一文詳解C++中隱含的this指針

    一文詳解C++中隱含的this指針

    這篇文章主要帶大家詳細了解一下C++中隱含的this指針,文中通過代碼示例和圖文介紹的非常詳細,對大家的學習或工作有一定的幫助,需要的朋友可以參考下
    2024-01-01
  • C/C++實現(xiàn)日期計算器的示例代碼

    C/C++實現(xiàn)日期計算器的示例代碼

    本篇文章主要介紹了C/C++實現(xiàn)日期計算器的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-09-09
  • C語言入門篇--初識結(jié)構(gòu)體

    C語言入門篇--初識結(jié)構(gòu)體

    本篇文章是基礎(chǔ)篇,適合c語言剛?cè)腴T的朋友,本文對c語言的結(jié)構(gòu)體做了簡單的分析,幫助大家快速入門c語言的世界,更好的理解c語言
    2021-08-08

最新評論