1.開戶2.銷戶3.存錢4.取錢5.查詢技術(shù)點(diǎn):TcpServer服務(wù)端TcpSocket客戶端多線程并發(fā)訪問數(shù)據(jù)庫存儲數(shù)據(jù)XML組織傳輸?shù)臄?shù)據(jù)
創(chuàng)新互聯(lián)建站是一家集網(wǎng)站建設(shè),南宮企業(yè)網(wǎng)站建設(shè),南宮品牌網(wǎng)站建設(shè),網(wǎng)站定制,南宮網(wǎng)站建設(shè)報價,網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,南宮網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競爭力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
#include stdio.h
#include string.h
#include stdlib.h
#define LEN sizeof(struct Account)
#define RECORDCOUNT 5
#define MESSAGELENGTH 100
#define NAMELENGTH 100
#define VIEWCOUNT 5
#define DEFAULTBALANCE 0.00
#define SAVE 1
struct Account *head,*tail,*p; /*賬戶頭部和尾部指針*/
struct Account
{
char name[NAMELENGTH]; /* 賬戶名稱 */
float balance; /* 賬戶余額*/
char message[RECORDCOUNT][MESSAGELENGTH]; /* 交易記錄 */
int maxMessageIndex;
struct Account *next; /* 指向下一賬戶 */
};
void freeMemory(); /*釋放內(nèi)存*/
void removeFirst(struct Account * account); /*移除第一個元素*/
void showMenu(); /*輸出選擇菜單*/
struct Account * findAccountByName(char name[]); /*通過賬戶名稱找到對應(yīng)的賬戶 */
void writeMessage(struct Account * account,char message[]); /* 寫入交易記錄 */
void init(); /* 創(chuàng)建鏈表,并返回表頭指針 */
void openAccount(); /* 開戶 */
void closeAccount(); /* 銷戶 */
void deposit(); /* 存款*/
void withdraw(); /* 取款 */
void transfer(); /* 轉(zhuǎn)賬 */
void print(); /*輸出賬戶列表*/
void printMessage(); /*輸出賬戶交易記錄*/
int main()
{
init();
printf("歡迎使用ATM管理系統(tǒng)\n");
showMenu();
char choice;
fflush(stdin);
choice = getchar();
while(choice != '8')
{
switch(choice)
{
case '1':
openAccount();
showMenu();
fflush(stdin);
choice = getchar();
break;
case '2':
closeAccount();
showMenu();
fflush(stdin);
choice = getchar();
break;
case '3':
deposit();
showMenu();
fflush(stdin);
choice = getchar();
break;
case '4':
withdraw();
showMenu();
fflush(stdin);
choice = getchar();
break;
case '5':
transfer();
showMenu();
fflush(stdin);
choice = getchar();
break;
case '6':
print();
showMenu();
fflush(stdin);
choice = getchar();
break;
case '7':
printMessage();
showMenu();
fflush(stdin);
choice = getchar();
break;
default:
printf("無效菜單!\n");
showMenu();
fflush(stdin);
choice = getchar();
break;
}
}
freeMemory(); /*釋放內(nèi)存*/
return 0;
}
void showMenu()
{
printf("請選擇 1.開戶 2.銷戶 3.存款 4.取款 5.轉(zhuǎn)賬 6.查看所有賬戶 7. 最近五筆交易 8.退出\n");
}
//通過賬戶名稱找到對應(yīng)的賬戶
struct Account * findAccountByName(char name[])
{
if(strlen(name)0)
{
p = head;
while(p != NULL)
{
if(strcmp(p-name,name)==0)
{
return p;
}
p = p-next;
}
}
return NULL;
}
//寫入交易記錄
void writeMessage(struct Account * account,char message[])
{
if(account-maxMessageIndex = RECORDCOUNT)
{
removeFirst(account);
strcpy((account-message)[RECORDCOUNT-1],message);
account-maxMessageIndex = account-maxMessageIndex+1;
}
else
{
strcpy((account-message)[account-maxMessageIndex],message);
account-maxMessageIndex = account-maxMessageIndex+1;
}
}
void removeFirst(struct Account * account)
{
int i=0;
for(i=1; iRECORDCOUNT; i++)
strcpy((account-message)[i-1],(account-message)[i]);
}
/* 初始化三個默認(rèn)賬戶 */
void init()
{
p = (struct Account *)malloc(LEN); /* 創(chuàng)建第一個賬戶 */
p-balance=DEFAULTBALANCE;
p-next=NULL;
p-maxMessageIndex=0;
strcpy(p-name,"001");
head=p;
tail = p;
p = (struct Account *)malloc(LEN); /* 創(chuàng)建第二個賬戶 */
p-balance=DEFAULTBALANCE;
p-next=NULL;
p-maxMessageIndex=0;
strcpy(p-name,"002");
head-next = p;
tail = p;
p = (struct Account *)malloc(LEN); /* 創(chuàng)建第三個賬戶 */
p-balance=DEFAULTBALANCE;
p-next=NULL;
p-maxMessageIndex=0;
strcpy(p-name,"003");
tail-next = p;
tail = p;
}
//輸出賬戶列表信息
void print()
{
int i;
p = head;
i = 1;
while(p != NULL)
{
printf("第%d個賬戶的數(shù)據(jù) 賬戶名稱:%s 余額:%.2f\n",i++,p-name,p-balance);
p = p-next;
}
}
//釋放內(nèi)存
void freeMemory()
{
p = head;
while(p != NULL)
{
head = p;
free(head);
p = p-next;
}
}
//開戶
void openAccount()
{
char name[NAMELENGTH];
printf("請輸入新開立的賬戶名稱 : ");
fflush(stdin);
gets(name);
if(strlen(name)0)
{
p = (struct Account *)malloc(LEN); /* 創(chuàng)建一個新賬戶 */
p-balance=DEFAULTBALANCE;
p-next=NULL;
strcpy(p-name,name);
tail-next=p;
tail = p;
}
}
//銷戶
void closeAccount()
{
char name[NAMELENGTH];
printf("請輸入要銷戶的賬戶名稱 : ");
fflush(stdin);
gets(name);
if(strlen(name)0)
{
struct Account *pre;
p = head;
pre=head;
int find=0;
while(p != NULL)
{
if(strcmp(p-name,name)==0)
{
if(head == p)
head=p-next;
else if(tail==p)
{
pre-next=NULL;
tail = pre;
}
else
{
pre-next = p-next;
}
find=1;
break;
}
pre = p;
p = p-next;
}
if(find==0)
printf("沒有此賬戶,無法完成銷戶!\n");
}
}
//存款
void deposit()
{
char name[NAMELENGTH];
printf("請輸入要存款的賬戶名稱 :");
fflush(stdin);
gets(name);
p = findAccountByName(name);
if(p!=NULL)
{
float savemoney;
printf("請輸入要存款的金額 : ");
scanf("%f",savemoney);
while(savemoney=0)
{
printf("存款額不能小于等于零,請重新輸入! ");
scanf("%f",savemoney);
}
p-balance = p-balance+savemoney; /*存入賬戶金額*/
char message[MESSAGELENGTH];
sprintf(message,"賬戶%s成功存入%.2f元!\n",name,savemoney);
writeMessage(p,message); /*寫入交易記錄*/
}
else
printf("沒有此賬戶!\n");
}
//取款
void withdraw()
{
char name[NAMELENGTH];
printf("請輸入要取款的賬戶名稱 :");
fflush(stdin);
gets(name);
p = findAccountByName(name);
if(p!=NULL)
{
float savemoney;
printf("請輸入要取款的金額 : ");
fflush(stdin);
scanf("%f",savemoney);
while(savemoney=0 || savemoney p-balance)
{
printf("存款額不能小于等于零或者大于余額,請重新輸入! ");
scanf("%f",savemoney);
}
p-balance = p-balance-savemoney; /*存入賬戶金額*/
char message[MESSAGELENGTH];
sprintf(message,"賬戶%s成功取出%.2f元!\n",name,savemoney);
writeMessage(p,message); /*寫入交易記錄*/
}
else
printf("沒有此賬戶!\n");
}
//轉(zhuǎn)賬
void transfer()
{
char outname[NAMELENGTH];
char inname[NAMELENGTH];
struct Account *outAccount;
struct Account *inAccount;
printf("請輸入要轉(zhuǎn)出的賬戶名稱 :");
fflush(stdin);
gets(outname);
outAccount = findAccountByName(outname);
if(outAccount!=NULL)
{
printf("請輸入要轉(zhuǎn)入的賬戶名稱 :");
fflush(stdin);
gets(inname);
inAccount = findAccountByName(inname);
if(inAccount != NULL)
{
float money;
printf("請輸入要轉(zhuǎn)賬的金額 : ");
fflush(stdin);
scanf("%f",money);
while(money=0 || money outAccount-balance)
{
printf("轉(zhuǎn)賬金額不能小于等于零或者大于轉(zhuǎn)出賬戶余額,請重新輸入! ");
scanf("%f",money);
}
outAccount-balance = outAccount-balance-money; /*減少轉(zhuǎn)出賬戶金額*/
inAccount-balance = inAccount-balance+money; /*增加轉(zhuǎn)入賬戶金額*/
char outmessage[MESSAGELENGTH];
sprintf(outmessage,"賬戶%s成功轉(zhuǎn)出%.2f元!\n",outname,money);
writeMessage(outAccount,outmessage); /*寫入轉(zhuǎn)出交易記錄*/
char inmessage[MESSAGELENGTH];
sprintf(inmessage,"賬戶%s成功轉(zhuǎn)入%.2f元!\n",inname,money);
writeMessage(inAccount,inmessage); /*寫入轉(zhuǎn)出交易記錄*/
}
}
else
printf("沒有此轉(zhuǎn)出賬戶!\n");
}
//查看賬戶最近五筆交易歷史
void printMessage()
{
char name[NAMELENGTH];
printf("請輸入要查看最近五筆交易歷史的賬戶名稱 :");
fflush(stdin);
gets(name);
p = findAccountByName(name);
if(p!=NULL)
{
int i=0;
int end = (p-maxMessageIndex)=VIEWCOUNT?VIEWCOUNT:(p-maxMessageIndex);
for(i=0; iend; i++)
printf("%s",(p-message)[i]);
}
else
printf("沒有此賬戶!\n");
}
掛起用戶[需要root權(quán)限運(yùn)行,需要掛起的用戶名為 socol] Java代碼 # sudo skill -STOP -u socol 喚醒已掛起用戶 Java代碼 # sudo skill -CONT -u socol 殺死/注銷用戶[socol] Java代碼 # skill -KILL -u socol 殺死/注銷所有用戶 Java代碼 # skill -KILL -v /dev/pts/*