#include stdio.h
在北侖等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計 網(wǎng)站設(shè)計制作按需定制開發(fā),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),全網(wǎng)整合營銷推廣,成都外貿(mào)網(wǎng)站建設(shè),北侖網(wǎng)站建設(shè)費用合理。
#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");
}
java里面本身沒有這樣的方法, 如果你想實現(xiàn), 考慮jni本地化調(diào)用其他編譯語言(如 c/c++, delphi)的dll, 這些語言可以無縫的調(diào)用系統(tǒng)sdk api,
如:ExitWindowsEx(EWX_LOGOFF or EWX_FORCE, 0);
不過Window2000,NT,XP都要先取得SE_SHUTDOWN_NAME權(quán)限
用jsp寫了一個注銷腳本logout.jsp如下:
%
session.removeValue("UserName");
session.removeValue("UserClass");
session.invalidate();
response.sendRedirect("index.jsp");
%