我是靠谱客的博主 年轻大门,最近开发中收集的这篇文章主要介绍简单的停车场程序,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


struct member 
{
char name[20];
char sex;
char qq[11];
char telphone[12];
char bir_year[5];
char bir_month[3];
char bir_day[3];
};
typedef struct member Member;
struct node
{
Member person;
struct node * next;
};
typedef struct node Node;


void Create_List(Node ** head);
void Add_Node(Node * head);
void Show_List(Node * head);
void Find_Node(Node * head);
void Delete_Node(Node * head);
void Modify_Node(Node * head);
void Show_Menu();


int main ()
{
Node * head = NULL;
Create_List(&head);
for(;;)
{
system("clear");
Show_Menu();
char ch;
printf("请输入数字 :n");
ch = getchar();
getchar();
switch(ch)
{
case '1' :printf("请输入个人信息:n");Add_Node(head);
do
{
printf("请按回车键返回菜单");
}while(getchar() != 'n');
break;
break;
case '2' :printf("联系人nn");Show_List(head);
do
{
printf("请按回车键返回菜单");
}while(getchar() != 'n');
break;
case '3' :Find_Node(head);
do
{
printf("请按回车键返回菜单");
}while(getchar() != 'n');
break;
case '4' :Show_List(head);
Delete_Node(head);
Show_List(head);
do
{
printf("请按回车键返回菜单");
}while(getchar() != 'n');
break;
case '5' :Show_List(head);
Modify_Node(head);
Show_List(head);
do
{
printf("请按回车键返回菜单");
}while(getchar() != 'n');
break;
case '6' :printf("ENDn"); break;
}
if(ch == '6')
{
break;
}
}

return 0;
}
void Create_List(Node ** head)
{
if((*head = (Node *)malloc(sizeof(Node))) == NULL)
{
printf("Malloc Error!n");
exit(EXIT_FAILURE);
}
(*head)->next = NULL;
}
void Add_Node(Node * head)
 {
  Node * q = head;
  Node * p ;
 
  if((p = (Node *)malloc(sizeof(Node))) == NULL)
  {
  printf("Malloc Error");
  exit(EXIT_FAILURE);
  }
 
  while(q->next != NULL)
{
q = q->next;
}

printf("n请输入姓名 : ");
do
{
scanf("%s",p->person.name);
}while(getchar() != 'n');

printf("n请输入性别(M or F) : ");
do
{
scanf("%c",&p->person.sex);
}while(getchar() != 'n');

printf("n请输入出生日期 : ");
do
{
scanf("%s %s %s",p->person.bir_year,p->person.bir_month,p->person.bir_day);
}while(getchar() != 'n');

printf("n请输入 QQ号码 : ");
do
{
scanf("%s",p->person.qq);
}while(getchar() != 'n');
printf("n请输入电话号码 : ");
do
{
scanf("%s",p->person.telphone);
}while(getchar() != 'n');

q->next = p ;
  p->next = NULL;
 }
void Show_List(Node * head)
{
Node * p = head->next;
if(p == NULL)
{
printf("请先添加联系人!n");
return;
}
int i = 0;
for (i = 0; i < 60; i += 1)
{
printf("_");
if(i==25)
{
printf("  通讯录   ");
}
}
printf("n");
printf("%-16s %-8s %-18s %-14s %-11s","姓名","性别","生日","QQ号码","手机号码");
printf("n");
printf("n");
while( p != NULL)
{
printf("%-15s %-5c %s.%s.%-8s %-12s %-11sn",p->person.name,p->person.sex,
p->person.bir_year,p->person.bir_month,p->person.bir_day,p->person.qq,p->person.telphone);
p = p->next;
}
}


void  Delete_Node(Node * head)
{
  Node * p1 = head;
Node * p2 = p1;
if(p1->next == NULL)
{
printf("请先添加联系人!n");
return;
}
char name[20],ch;
printf("请输入待删除联系人  :  ");
// do
// {
scanf("%s",name);
// }while(getchar() != 'n');
printf("确认删除此联系人?(y/n)n");
while(getchar()!='n');
if((ch = getchar()) == 'y')
{
while(getchar()!='n');
do
{
p2 = p1;
p1 = p1->next;
if(strcmp(p1->person.name,name) == 0)
{
p2->next = p1->next;
return;
}
else
{
printf("没有该联系人!n");
return;
}
}while(p1 != NULL);

}
}


void Find_Node(Node * head)
 {
  Node * p = head;
  char name[20];
  printf("请输入要查找的联系人 : ");
  do
{
scanf("%s",name);
}while(getchar() != 'n');

while(p->next != NULL)
{
p = p->next;
if(strcmp(p->person.name,name) == 0)
{
int i = 0;
for (i = 0; i < 60; i += 1)
{
printf("_");
if(i==25)
{
printf("  通讯录   ");
}
}
printf("n");
printf("%-16s %-8s %-18s %-14s %-11s","姓名","性别","生日","QQ号码","手机号码");
printf("n");
printf("n");
printf("%-15s %-5c %s.%s.%-8s %-12s %-11sn",p->person.name,p->person.sex,
p->person.bir_year,p->person.bir_month,p->person.bir_day,p->person.qq,p->person.telphone);
return;
}
else
{
printf("没有该联系人!n");
return;
}
}

 }
void Modify_Node(Node * head)
 {
  Node * p = head;
  char name[20];
  char c;
  char str[20];
 
  if(p->next == NULL)
{
printf("请先添加联系人!n");
return;
}
  memset(str,0,sizeof(str));
  memset(str,0,sizeof(name));
 
  printf("请输入需要修改的联系人 : ");
  do
{
scanf("%s",name);
}while(getchar() != 'n');
while(p->next != NULL)
{
p = p->next;
if(strcmp(p->person.name,name) == 0)
{
printf("请重新输入该联系人的信息");
printf("n请重新输入姓名(Enter键跳过) : ");
if((c = getchar()) != 'n')
{
str[0] = c;
do
{
scanf("%s",p->person.name);
strcat(str,p->person.name);
strcpy(p->person.name,str);
}while(getchar() != 'n');
}

printf("n请重新输入性别(Enter键跳过) : ");
if((c = getchar()) != 'n')
{
do
{
p->person.sex = c;
}while(getchar() != 'n');
}
memset(str,0,sizeof(str));
printf("n请重新输入出生日期(Enter键跳过) : ");
if((c = getchar()) != 'n')
{
str[0] = c;
do
{
scanf("%s %s %s",p->person.bir_year,p->person.bir_month,p->person.bir_day);
strcat(str,p->person.bir_year);
strcpy(p->person.bir_year,str);
}while(getchar() != 'n');
}
memset(str,0,sizeof(str));
printf("n请重新输入QQ号码(Enter键跳过) : ");
if((c = getchar()) != 'n')
{
str[0] = c;
do
{
scanf("%s",p->person.qq);
strcat(str,p->person.qq);
strcpy(p->person.qq,str);
}while(getchar() != 'n');
}
memset(str,0,sizeof(str));
printf("n请重新输入电话号码(Enter键跳过) : ");
if((c = getchar()) != 'n')
{
str[0] = c;
do
{
scanf("%s",p->person.telphone);
strcat(str,p->person.telphone);
strcpy(p->person.telphone,str);
}while(getchar() != 'n');
return;
}
else
{
printf("没有该联系人!n");
return;
}
}

}
 }


 
void Show_Menu()
{
int i = 0;
for (i = 0; i < 18; i += 1)
{
printf("_");
if( i == 8)
{
printf("菜单");
}
}
printf("n");
printf("    1.添加联系人n");
printf("    2.显示联系人n");
printf("    3.查找联系人n");
printf("    4.删除联系人n");
printf("    5.修改联系人n");
printf("    6.退出n");

}

最后

以上就是年轻大门为你收集整理的简单的停车场程序的全部内容,希望文章能够帮你解决简单的停车场程序所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(54)

评论列表共有 0 条评论

立即
投稿
返回
顶部