C实习程序.docx
《C实习程序.docx》由会员分享,可在线阅读,更多相关《C实习程序.docx(22页珍藏版)》请在冰豆网上搜索。
![C实习程序.docx](https://file1.bdocx.com/fileroot1/2023-1/31/679001cc-e325-4d22-a731-b9c6c963a1dd/679001cc-e325-4d22-a731-b9c6c963a1dd1.gif)
C实习程序
#include
#include
#include
#include
#defineCLEARsystem("cls")
#defineCONTINUEContinue()
#defineDATAFILEe:
\\lib.txt
typedefintStatus;
typedefstructDate
{
intm_iYear;
intm_iMonth;
intm_iDay;
}Date;
typedefstructTrafficPulishReceipt
{
charm_sCarid[7];
charm_sDriname[10];
charm_sTPName[10];
charm_sRecnum[11];
Datem_CDate;
structTrafficPulishReceipt*m_pNext;
}*PTPR,TPR;
voidInitDate(Date*,int,int,int);
voidShowDate(Date*);
StatusComDate(Date*,Date*);
PTPRCreatTPR(PTPR);
voidSearchByPocName(PTPR);
voidSearchByDriName(PTPR);
voidSearchByCarId(PTPR);
PTPRDeleteTPR(PTPR);
voidStatisticsTPR(PTPR);
voidDestoryTPR(PTPR);
PTPRInitNode(void);
PTPRInsertNode(PTPR,PTPR);
PTPRSearchNode_1(PTPR,char*);
PTPRSearchNode_1_rf(PTPR,char*);
PTPRSearchNode_2(PTPR,char*);
PTPRSearchNode_3(PTPR,char*);
PTPRSearchNode_4(PTPR,char*);
voidShowNode(PTPR);
PTPRInitTPRSystem(void);
voidExitTPRSystem(PTPR);
voidMenu(void);
voidContinue(void);
intCharToNum(char*);
intmain()
{
PTPRpHead=NULL;
charc='';
pHead=InitTPRSystem();
while(c!
='0')
{
CLEAR;
Menu();
printf("Pleaseinputtheoption:
");
flushall();
scanf("%c",&c);
switch(c)
{
case'1':
pHead=CreatTPR(pHead);
CONTINUE;
break;
case'2':
SearchByDriName(pHead);
CONTINUE;
break;
case'3':
SearchByPocName(pHead);
CONTINUE;
break;
case'4':
SearchByCarId(pHead);
CONTINUE;
break;
case'5':
pHead=DeleteTPR(pHead);
CONTINUE;
break;
case'6':
StatisticsTPR(pHead);
CONTINUE;
break;
case'0':
break;
default:
printf("wronginputoption!
\n");
CONTINUE;
break;
}
}
ExitTPRSystem(pHead);
return0;
}
voidInitDate(Date*CDate,intiYear,intiMon,intiDay)
{
CDate->m_iYear=iYear;
CDate->m_iMonth=iMon;
CDate->m_iDay=iDay;
}
voidShowDate(Date*CDate)
{
printf("%dyear%dmonth%dday",CDate->m_iYear,CDate->m_iMonth,CDate->m_iDay);
}
StatusComDate(Date*d1,Date*d2)
{
if(d1->m_iYearm_iYear)
{
return-1;
}
elseif(d1->m_iYear>d2->m_iYear)
{
return1;
}
elseif(d1->m_iMonthm_iMonth)
{
return-1;
}
elseif(d1->m_iMonth>d2->m_iMonth)
{
return1;
}
elseif(d1->m_iDaym_iDay)
{
return-1;
}
elseif(d1->m_iDay>d2->m_iDay)
{
return1;
}
else
{
return0;
}
}
PTPRInitNode()
{
PTPRpTemp=(PTPR)malloc(sizeof(TPR));
pTemp->m_pNext=NULL;
returnpTemp;
}
PTPRInsertNode(PTPRpHead,PTPRpTemp)
{
PTPRp1=pHead;
PTPRp2;
if(pHead)
{
while(p1)
{
p2=p1;
if(strcmp(pTemp->m_sRecnum,p1->m_sRecnum)<0)
{
break;
}
p1=p1->m_pNext;
}
if(p1==pHead)
{
pTemp->m_pNext=pHead;
pHead=pTemp;
}
elseif(!
p1)
{
p2->m_pNext=pTemp;
}
else
{
p2->m_pNext=pTemp;
pTemp->m_pNext=p1;
}
}
else
{
pHead=pTemp;
}
returnpHead;
}
PTPRSearchNode_1(PTPRpHead,char*sRecnum)
{
while(pHead)
{
if(!
strcmp(pHead->m_sRecnum,sRecnum))
{
break;
}
pHead=pHead->m_pNext;
}
returnpHead;
}
PTPRSearchNode_1_rf(PTPRpHead,char*sRecnum)
{
PTPRpTemp=pHead;
while(pHead)
{
pTemp=pHead;
if(!
strcmp(pHead->m_sRecnum,sRecnum))
{
break;
}
pHead=pHead->m_pNext;
}
returnpTemp;
}
PTPRSearchNode_2(PTPRpHead,char*sDriname)
{
while(pHead)
{
if(!
strcmp(pHead->m_sDriname,sDriname))
{
break;
}
pHead=pHead->m_pNext;
}
returnpHead;
}
PTPRSearchNode_3(PTPRpHead,char*sTPName)
{
while(pHead)
{
if(!
strcmp(pHead->m_sTPName,sTPName))
{
break;
}
pHead=pHead->m_pNext;
}
returnpHead;
}
PTPRSearchNode_4(PTPRpHead,char*sCarid)
{
while(pHead)
{
if(!
strcmp(pHead->m_sCarid,sCarid))
{
break;
}
pHead=pHead->m_pNext;
}
returnpHead;
}
voidShowNode(PTPRpTemp)
{
if(pTemp)
{
printf("Punishmentoddnumbers:
%s\n",pTemp->m_sRecnum);
printf("Vehicletrademark:
%s\n",pTemp->m_sCarid);
printf("Drivername:
%s\n",pTemp->m_sDriname);
printf("Trafficpolicename:
%s\n",pTemp->m_sTPName);
printf("Punishmentdate:
");
ShowDate(&pTemp->m_CDate);
printf("\n");
}
}
voidMenu()
{
printf("Transportationpunishmentlistmanagementsystem\n");
printf("--------------------------------------------------------------------------------\n");
printf("1.Foundsthenewpunishmentlist\n");
printf("2.Inquiresthepunishmentlistaccordingtothedriver\n");
printf("3.Inquiresthepunishmentlistaccordingtothetrafficpolice\n");
printf("4.InquiresthepunishmentlistaccordingtoPunishmentoddnumbers\n");
printf("5.Deletionpunishmentlist\n");
printf("6.Statistics\n");
printf("0.exit\n");
printf("--------------------------------------------------------------------------------\n");
}
voidContinue()
{
printf("Pressanykeytocontinue...\n");
flushall();
getch();
}
intCharToNum(char*num)
{
inti,index=0;
for(i=strlen(num);i>0;i--)
{
index+=num[i]-'0';
index*=10;
}
returnindex/=10;
}
PTPRCreatTPR(PTPRpHead)
{
PTPRpTemp=InitNode();
intiYear,iMon,iDay;
printf("Pleaseinputtherelatedinformation:
\n");
printf("Punishmentoddnumbers:
");
flushall();
scanf("%s",pTemp->m_sRecnum);
if(SearchNode_1(pHead,pTemp->m_sRecnum))
{
printf("Thepunishmentoddnumbershavetherepetition,pleasereinput");
free(pTemp);
returnpHead;
}
printf("Vehicletrademark:
");
flushall();
scanf("%s",pTemp->m_sCarid);
printf("Drivername:
");
flushall();
scanf("%s",pTemp->m_sDriname);
printf("trafficpolicename:
");
flushall();
scanf("%s",pTemp->m_sTPName);
printf("Punishmentdate:
");
flushall();
scanf("%d%d%d",&iYear,&iMon,&iDay);
InitDate(&pTemp->m_CDate,iYear,iMon,iDay);
returnInsertNode(pHead,pTemp);
}
voidSearchByPocName(PTPRpHead)
{
charname[10];
inti=1,check=0;
if(pHead)
{
printf("Pleaseinputtreatsinquirestrafficpolice'sname:
");
flushall();
scanf("%s",name);
while(pHead)
{
pHead=SearchNode_3(pHead,name);
if(pHead)
{
check++;
ShowNode(pHead);
printf("\n");
i++;
pHead=pHead->m_pNext;
}
if(!
(i%4))
{
i=0;
CONTINUE;
}
}
if(!
check)
{
printf("noinformation!
\n");
}
}
else
{
printf("Currenthasnotpunishedthelist!
");
}
}
voidSearchByDriName(PTPRpHead)
{
charname[10];
inti=1,check=0;
if(pHead)
{
printf("Pleaseinputtreatsinquiresdriver'sname:
");
flushall();
scanf("%s",name);
while(pHead)
{
pHead=SearchNode_2(pHead,name);
if(pHead)
{
check++;
ShowNode(pHead);
printf("\n");
i++;
pHead=pHead->m_pNext;
}
if(!
(i%4))
{
i=0;
CONTINUE;
}
}
if(!
check)
{
printf("noInformation!
\n");
}
}
else
{
printf("Currenthasnotpunishedthelist!
");
}
}
voidSearchByCarId(PTPRpHead)
{
charname[10];
inti=1,check=0;
if(pHead)
{
printf("Pleaseinputtreatstheinquiryvehicletrademark:
");
flushall();
scanf("%s",name);
while(pHead)
{
pHead=SearchNode_4(pHead,name);
if(pHead)
{
check++;
ShowNode(pHead);
printf("\n");
i++;
pHead=pHead->m_pNext;
}
if(!
(i%4))
{
i=0;
CONTINUE;
}
}
if(!
check)
{
printf("noinformation!
\n");
}
}
else
{
printf("Currenthasnotpunishedthelist!
");
}
}
PTPRDeleteTPR(PTPRpHead)
{
charnum[11];
PTPRpTemp,pT;
if(pHead)
{
printf("Pleaseinputpunishestheoddnumbers:
");
flushall();
scanf("%s",num);
pTemp=SearchNode_1(pHead,num);
if(pTemp)
{
if(pTemp==pHead)
{
pHead=pHead->m_pNext;
}
elseif(!
pTemp->m_pNext)
{
pT=SearchNode_1_rf(pHead,num);
pT->m_pNext=NULL;
}
else
{
pT=SearchNode_1_rf(pHead,num);
pT->m_pNext=pTemp->m_pNext;
}
free(pTemp);
printf("Deletessuccessfully!
\n");
}
else
{
printf("Theinputnumberdoesnotexist!
\n");
}
}
else
{
printf("Currenthasnotpunishedthelist!
");
}
returnpHead;
}
voidStatisticsTPR(PTPRpHead)
{
Dated1,d2;
charname[10];
intindex=0,i=0;;
if(pHead)
{
printf("Pleaseinputtheoutsettime:
");
flushall();
scanf("%d%d%d",&d1.m_iYear,&d1.m_iMonth,&d1.m_iDay);
printf("Pleaseinputtheclosuretime:
");
flushall();
scanf("%d%d%d",&d2.m_iYear,&d2.m_iMonth,&d2.m_iDay);
if(ComDate(&d1,&d2)>0)
{
printf("wronginput!
\n");
}
else
{
printf("Inputsthedrivername:
");
flushall();
scanf("%s",name);
while(pHead)
{
pHead=SearchNode_2(pHead,name);
if(pHead)
{
if(ComDate(&pHead->m_CDate,&d1)>0&&ComDate(&pHead->m_CDate,&d2)<0)
{
i++;
index++;
printf("%s\n",pHead->m_sRecnum);
}
pHead=pHead->m_pNext;
}
if(!
(index%30))
{
index=0;
CONTINUE;
}
}
printf("Altogether%drecord\n",i);
}
}
else
{
printf("Currenthasnotpunishedthelist!
");
}
}
voidDestoryTPR(PTPRpHead)
{
PTPRpTemp;
while(pHead)
{
pTemp=pHead;