#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#define CLEAR system("cls")
#define CONTINUE Continue()
#define DATAFILE e:\\lib.txt
typedef int Status;
typedef struct Date
{
int m_iYear;
int m_iMonth;
int m_iDay;
} Date;
typedef struct TrafficPulishReceipt
{
char m_sCarid[7];
char m_sDriname[10];
char m_sTPName[10];
char m_sRecnum[11];
Date m_CDate;
struct TrafficPulishReceipt* m_pNext;
} *PTPR, TPR;
void InitDate( Date*, int, int, int );
void ShowDate( Date* );
Status ComDate( Date*, Date* );
PTPR CreatTPR( PTPR );
void SearchByPocName( PTPR );
void SearchByDriName( PTPR );
void SearchByCarId( PTPR );
PTPR DeleteTPR( PTPR );
void StatisticsTPR( PTPR );
void DestoryTPR( PTPR );
PTPR InitNode( void );
PTPR InsertNode( PTPR, PTPR );
PTPR SearchNode_1( PTPR, char* );
PTPR SearchNode_1_rf( PTPR, char* );
PTPR SearchNode_2( PTPR, char* );
PTPR SearchNode_3( PTPR, char* );
PTPR SearchNode_4( PTPR, char* );
void ShowNode( PTPR );
PTPR InitTPRSystem( void );
void ExitTPRSystem( PTPR );
void Menu( void );
void Continue( void );
int CharToNum( char* );
int main()
{
PTPR pHead = NULL;
char c = ' ';
pHead = InitTPRSystem();
while( c != '0' )
{
CLEAR;
Menu();
printf( "Please input the option: " );
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( "wrong input option!\n" );
CONTINUE;
break;
}
}
ExitTPRSystem( pHead );
return 0;
}
void InitDate( Date* CDate, int iYear, int iMon, int iDay )
{
CDate->m_iYear = iYear;
CDate->m_iMonth = iMon;
CDate->m_iDay = iDay;
}
void ShowDate( Date* CDate )
{
printf( "%dyear%dmonth%dday", CDate->m_iYear, CDate->m_iMonth, CDate->m_iDay );
}
Status ComDate( Date* d1, Date* d2 )
{
if( d1->m_iYear < d2->m_iYear )
{
return -1;
}
else if( d1->m_iYear > d2->m_iYear )
{
return 1;
}
else if( d1->m_iMonth < d2->m_iMonth )
{
return -1;
}
else if( d1->m_iMonth > d2->m_iMonth )
{
return 1;
}
else if( d1->m_iDay < d2->m_iDay )
{
return -1;
}
else if( d1->m_iDay > d2->m_iDay )
{
return 1;
}
else
{
return 0;
}
}
PTPR InitNode()
{
PTPR pTemp = ( PTPR )malloc( sizeof( TPR ) );
pTemp->m_pNext = NULL;
return pTemp;
}
PTPR InsertNode( PTPR pHead, PTPR pTemp )
{
PTPR p1 = pHead;
PTPR p2;
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;
}
else if( !p1 )
{
p2->m_pNext = pTemp;
}
else
{
p2->m_pNext = pTemp;
pTemp->m_pNext = p1;
}
}
else
{
pHead = pTemp;
}
return pHead;
}
PTPR SearchNode_1( PTPR pHead, char* sRecnum )
{
while( pHead )
{
if( !strcmp( pHead->m_sRecnum, sRecnum ) )
{
break;
}
pHead = pHead->m_pNext;
}
return pHead;
}
PTPR SearchNode_1_rf( PTPR pHead, char* sRecnum )
{
PTPR pTemp = pHead;
while( pHead )
{
pTemp = pHead;
if( !strcmp( pHead->m_sRecnum, sRecnum ) )
{
break;
}
pHead = pHead->m_pNext;
}
return pTemp;
}
PTPR SearchNode_2( PTPR pHead, char* sDriname )
{
while( pHead )
{
if( !strcmp( pHead->m_sDriname, sDriname ) )
{
break;
}
pHead = pHead->m_pNext;
}
return pHead;
}
PTPR SearchNode_3( PTPR pHead, char* sTPName )
{
while( pHead )
{
if( !strcmp( pHead->m_sTPName, sTPName ) )
{
break;
}
pHead = pHead->m_pNext;
}
return pHead;
}
PTPR SearchNode_4( PTPR pHead, char* sCarid )
{
while( pHead )
{
if( !strcmp( pHead->m_sCarid, sCarid ) )
{
break;
}
pHead = pHead->m_pNext;
}
return pHead;
}
void ShowNode( PTPR pTemp )
{
if( pTemp )
{
printf( "Punishment odd numbers: %s\n", pTemp->m_sRecnum );
printf( "Vehicle trademark: %s\n", pTemp->m_sCarid );
printf( "Driver name: %s\n", pTemp->m_sDriname );
printf( "Traffic police name: %s\n", pTemp->m_sTPName );
printf( "Punishment date: " );
ShowDate( &pTemp->m_CDate );
printf( "\n" );
}
}
void Menu()
{
printf( " Transportation punishment list management system\n" );
printf( "--------------------------------------------------------------------------------\n" );
printf( " 1. Founds the new punishment list\n" );
printf( " 2. Inquires the punishment list according to the driver\n" );
printf( " 3. Inquires the punishment list according to the traffic police\n" );
printf( " 4. Inquires the punishment list according to Punishment odd numbers\n" );
printf( " 5. Deletion punishment list\n" );
printf( " 6. Statistics\n" );
printf( " 0. exit\n" );
printf( "--------------------------------------------------------------------------------\n" );
}
void Continue()
{
printf( "Press any key to continue...\n" );
flushall();
getch();
}
int CharToNum( char* num )
{
int i, index = 0;
for( i = strlen( num ); i > 0; i-- )
{
index += num[i] - '0';
index *= 10;
}
return index /= 10;
}
PTPR CreatTPR( PTPR pHead )
{
PTPR pTemp = InitNode();
int iYear, iMon, iDay;
printf( "Please input the related information:\n" );
printf( "Punishment odd numbers: " );
flushall();
scanf( "%s", pTemp->m_sRecnum );
if( SearchNode_1( pHead, pTemp->m_sRecnum ) )
{
printf( "The punishment odd numbers have the repetition, please reinput" );
free( pTemp );
return pHead;
}
printf( "Vehicle trademark: " );
flushall();
scanf( "%s", pTemp->m_sCarid );
printf( "Driver name: " );
flushall();
scanf( "%s", pTemp->m_sDriname );
printf( "traffic police name: " );
flushall();
scanf( "%s", pTemp->m_sTPName );
printf( "Punishment date: " );
flushall();
scanf( "%d %d %d", &iYear, &iMon, &iDay );
InitDate( &pTemp->m_CDate, iYear, iMon, iDay );
return InsertNode( pHead, pTemp );
}
void SearchByPocName( PTPR pHead )
{
char name[10];
int i = 1, check = 0;
if( pHead )
{
printf( "Please input treats inquires traffic police's name: " );
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( "no information!\n" );
}
}
else
{
printf( "Current has not punished the list!" );
}
}
void SearchByDriName( PTPR pHead )
{
char name[10];
int i = 1, check = 0;
if( pHead )
{
printf( "Please input treats inquires driver's name: " );
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( "no Information!\n" );
}
}
else
{
printf( "Current has not punished the list!" );
}
}
void SearchByCarId( PTPR pHead )
{
char name[10];
int i = 1, check = 0;
if( pHead )
{
printf( "Please input treats the inquiry vehicle trademark: " );
flushall();
scanf( "%s", name );
while( pHead )
{
pHead = SearchNode_4( pHead, name );
if( pHead )
{
check++;
ShowNode(