1、C实习程序#include #include #include #include #define CLEAR system(cls)#define CONTINUE Continue()#define DATAFILE e:lib.txttypedef int Status;typedef struct Date int m_iYear; int m_iMonth; int m_iDay; Date;typedef struct TrafficPulishReceipt char m_sCarid7; char m_sDriname10; char m_sTPName10; char m_sR
2、ecnum11; 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 S
3、tatisticsTPR( 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 InitTPRS
4、ystem( 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 = CreatT
5、PR( 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; de
6、fault: 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_iMont
7、h, CDate-m_iDay );Status ComDate( Date* d1, Date* d2 ) if( d1-m_iYear m_iYear ) return -1; else if( d1-m_iYear d2-m_iYear ) return 1; else if( d1-m_iMonth m_iMonth ) return -1; else if( d1-m_iMonth d2-m_iMonth ) return 1; else if( d1-m_iDay m_iDay ) return -1; else if( d1-m_iDay d2-m_iDay ) return 1
8、; 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 ) m_pNext; if( p1 = pHead ) pTemp-m_pNext =
9、 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
10、_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_pN
11、ext; 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; retu
12、rn pHead;void ShowNode( PTPR pTemp ) if( pTemp ) printf( Punishment odd numbers: %sn, pTemp-m_sRecnum ); printf( Vehicle trademark: %sn, pTemp-m_sCarid ); printf( Driver name: %sn, pTemp-m_sDriname ); printf( Traffic police name: %sn, pTemp-m_sTPName ); printf( Punishment date: ); ShowDate( &pTemp-m
13、_CDate ); printf( n ); void Menu() printf( Transportation punishment list management systemn ); printf( -n ); printf( 1. Founds the new punishment listn ); printf( 2. Inquires the punishment list according to the drivern ); printf( 3. Inquires the punishment list according to the traffic policen );
14、printf( 4. Inquires the punishment list according to Punishment odd numbersn ); printf( 5. Deletion punishment listn ); printf( 6. Statisticsn ); printf( 0. exitn ); printf( -n );void Continue() printf( Press any key to continue.n ); flushall(); getch();int CharToNum( char* num ) int i, index = 0; f
15、or( i = strlen( num ); i 0; i- ) index += numi - 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( SearchNod
16、e_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
17、: ); 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 name10; int i = 1, check = 0; if( pHead ) printf( P
18、lease input treats inquires traffic polices 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(
19、 Current has not punished the list! ); void SearchByDriName( PTPR pHead ) char name10; int i = 1, check = 0; if( pHead ) printf( Please input treats inquires drivers name: ); flushall(); scanf( %s, name ); while( pHead ) pHead = SearchNode_2( pHead, name ); if( pHead ) check+; ShowNode( pHead ); pri
20、ntf(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 name10; int i = 1, check = 0; if( pHead ) printf( Please input treats the inquiry vehicle trademark:
21、); 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( no information!n ); else printf( Current has not punished the list! ); PTPR Delete
22、TPR( PTPR pHead ) char num11; PTPR pTemp, pT; if( pHead ) printf( Please input punishes the odd numbers: ); flushall(); scanf( %s, num ); pTemp = SearchNode_1( pHead, num ); if( pTemp ) if( pTemp = pHead ) pHead = pHead-m_pNext; else if( !pTemp-m_pNext ) pT = SearchNode_1_rf( pHead, num ); pT-m_pNex
23、t = NULL; else pT = SearchNode_1_rf( pHead, num ); pT-m_pNext = pTemp-m_pNext; free( pTemp ); printf( Deletes successfully!n ); else printf( The input number does not exist!n ); else printf( Current has not punished the list! ); return pHead;void StatisticsTPR( PTPR pHead ) Date d1, d2; char name10;
24、 int index = 0, i = 0; if( pHead ) printf( Please input the outset time: ); flushall(); scanf( %d %d %d, &d1.m_iYear, &d1.m_iMonth, &d1.m_iDay ); printf( Please input the closure time: ); flushall(); scanf( %d %d %d, &d2.m_iYear, &d2.m_iMonth, &d2.m_iDay ); if( ComDate( &d1, &d2 ) 0 ) printf( wrong
25、input!n ); else printf( Inputs the driver name: ); 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 ) m_sRecnum ); pHead = pHead-m_pNext; if( !( index % 30 ) ) index = 0; CONTINUE; printf( Altogether %d recordn, i ); else printf( Current has not punished the list! ); void DestoryTPR( PTPR pHead ) PTPR pTemp; while( pHead ) pTemp = pHead;
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1