c語言開戶,c語言用戶註冊

本文目錄一覽:

銀行開戶 c語言 我做了個銀行開戶系統,可是不會用文件保存,就是每次執行都必須初始輸入開戶信息,

文件I/O函數。

fopen打開本地文件

fseek定位到文件某個位置(可用來修改已經存在的用戶信息等)

fwrite寫入

fclose關閉

帶f的IO函數是標準IO,下面資料是linux特有的。用法差不多。

網上有很多例子,可以參考資料,希望對你有幫助

用C語言編一個程序,建立一個簡單的銀行帳戶管理系統

#include stdio.h #include string.h struct information { char account[20]; char IDcardNum; char workUint; char homeAddress; float money; char cardNum; long int password; }; void openAccount(); { cardNum++; user[cardNum].cardNum = cardNum; printf(“請輸入您的姓名:”); gets(user[cardNum].account); printf(“請輸入您的身份證號:”); gets(user[cardNum].IDcardNum); printf(“請輸入您的工作單位:”); gets(user[cardNum].workUnit); print(“請輸入您的家庭住址:”); gets(user[cardNum].homeAddress); printf(“請輸入您的密碼:”); gets(user[cardNum].password); printf(“請輸入您要存入的金額:”); scanf(“%d”,user[cardNum].money); //寫入文件out.txt中,寫入後,游標移至下一行 read();//讀取文件 write(); //寫入文件 cardNum++; } void deposit(); { int money; printf(“請輸入您的卡號:”); scanf(“%d”,cardNum); printf(“請輸入您要存入的金額:”); scanf(“%f”,money); user[cardNum].money = user[cardNum].money + money; printf(“您現在賬戶中的餘額是¥%f”,user[cardNum].money); } void withdraw(); { int money; printf(“請輸入您的卡號:”); scanf(“%d”,cardNum); printf(“請輸入您要存入的金額:”); scanf(“%f”,money); user[cardNum].money = user[cardNum].money – money; printf(“您現在賬戶中的餘額是¥%f”,user[cardNum].money); } void changeInformation(); { printf(“請輸入您的卡號:”); scanf(“%d”,cardNum); user[cardNum].cardNum = cardNum; printf(“請輸入您的姓名:”); gets(user[cardNum].account); printf(“請輸入您的身份證號:”); gets(user[cardNum].IDcardNum); printf(“請輸入您的工作單位:”); gets(user[cardNum].workUnit); print(“請輸入您的家庭住址:”); gets(user[cardNum].homeAddress); printf(“請輸入您的密碼:”); gets(user[cardNum].password); printf(“請輸入您要存入的金額:”); scanf(“%d”,user[cardNum].money); //寫入文件out.txt中,寫入後,游標移至下一行 read();//讀取文件 write(); //寫入文件 } void reportLoss(); { } void closeAccount(); { } void read(); { } void write(); { } int main() { int i; unsigned long int cardNum = 00001; information user[cardNum]; printf(“請您選擇要進行的操作:\n”); printf(“——————————————————\n”); printf(“1、開戶/辦卡 2、存款 3、取款 4、修改信息 5、掛失 6、銷戶\n”); printf(“——————————————————\n”); scanf(“%d”,i); if(i 1 || i 6) printf(“ERROR!\n”); else { switch(i) { case 1 : openAccount(); break; case 2 : deposit(); break; case 3 : withdraw(); break; case 4 : changeInformation(); break; case 5 : reportLoss(); break; case 6 : closeAccount(); break; } } return 0; } 沒有寫完,樓主可以參考一下!

用c語言編寫ATM的程序,實現開戶、存款、取款、查詢餘額、轉賬的業務邏輯。

#include stdio.h

#include stdlib.h

#include conio.h

#include string.h

void regist();

void login();

void quite();

void inputpassword(char mima[]);

void service();

struct bank

{

char name[20];

char password[7];

int account;

double money;

}kehu;

int find;

int a[10];

struct bank one;

FILE *fp;

void main()

{

int i;

int t=1;

for(i=0;i100;i++)

{

printf(“\t\t\t\t\t\t歡迎使用青軟ATM系統\n”);

printf(“\t\t\t\t\t\t正在進入主界面,請稍等”);

int j;

for(j=1;jt;j++)

{

printf(“.”);

}

t++;

if(t==10)

{

t=1;

}

printf(“\n\t\t\t\t\t\t%d%%”,i);

system(“cls”);

}

while(1)

{

printf(“\t\t\t\t\t\t服務類型: \n”);

printf(“\t\t\t\t\t\t[a]: 用戶註冊\n”);

printf(“\t\t\t\t\t\t[b]: 用戶登錄\n”);

printf(“\t\t\t\t\t\t[c]: 退出系統\n”);

printf(“\t\t\t\t\t\t請選擇服務: “);

fflush(stdin);

char xz;

scanf(“%c”,xz);

if(xz==’a’||xz==’A’)

{

regist();

} else if (xz==’b’||xz==’B’)

{

login();

} else if(xz==’c’||xz==’C’)

{

quite();

} else

{

printf(“輸入有誤,請重新輸入”);

}

getch();

system(“cls”);

}

}

void inputpassword(char mima[])

{

int i=0;

char ch;

while(1)

{

ch=getch();

if(ch!=’\r’)

{

if(ch!=’\b’){

mima[i]=ch;

i++;

printf(“*”);

}else{

if(i0){

i–;

printf(“\b \b”);

}

}

}else{

break;

}

}

mima[i]=’\0′;

printf(“\n”);

}

void regist()

{

fp=fopen(“atm.txt”,”ab+”);

if(fp==NULL)

{

printf(“\n\t\t\t文件打開失敗!”);

return;

}

system(“cls”);

printf(“\t\t\t現在執行的是註冊函數的使用\n”);

printf(“\t\t請輸入用戶名: “);

fflush(stdin);

gets(kehu.name);

char password1[7];

while(1)

{

while(1)

{

printf(“\n\n\t\t請輸入密碼:”);

fflush(stdin);

inputpassword(kehu.password);

int n=strlen(kehu.password);

if(n==6)

{

break;

}else

{

printf(“\n\t\t密碼必須為6位!”);

}

}

printf(“\n\t\t請輸入正確密碼!: “);

fflush(stdin);

inputpassword(password1);

if(strcmp(kehu.password,password1)==0)

{

break;

}else{

printf(“\n\n\t\t兩次密碼必須相同!”);

}

}

rewind(fp);

struct bank k;

if(fread(k,sizeof(struct bank),1,fp)==1)

{

fseek(fp,-sizeof(k),2);

fread(k,sizeof(k),1,fp);

kehu.account=k.account+1;

}else{

kehu.account=20170001;

}

kehu.money=0;

fseek(fp,0,2);

fwrite(kehu,sizeof(struct bank),1,fp);

fclose(fp);

printf(“\n\n\t\t開戶成功! “);

printf(“\n\t\t您的賬號為%d!”,kehu.account);

printf(“\n\t\t現在請您重新登錄!”);

}

void searchmoney()

{

system(“cls”);

printf(“您現在使用的是查詢餘額功能: \n”);

printf(“\n\n\t\t您的餘額是%0.2lf”,one.money);

}

void savemoney()

{

system(“cls”);

double inmoney;

printf(“請您選擇您要存款的金額 \n”);

scanf(“%lf”,inmoney);

int q;

int r=1;

for(q=0;q100;q++)

{

int w;

for(w=1;wr;w++)

{

printf(“.”);

}

r++;

if(r==10)

{

r=1;

}

printf(“\n\t\t\t\t\t\t正在存款%d%%”,q);

system(“cls”);

}

one.money=one.money+inmoney;

fseek(fp,-sizeof(one),1);

fwrite(one,sizeof(one),1,fp);

printf(“\n\n\t\t\t\t\t\t您已存款成功!”);

}

void withdrawalmoney()

{

system(“cls”);

double outputsomemoney;

printf(“請您選擇您要取款的金額 \n”);

scanf(“%lf”,outputsomemoney);

if(one.moneyoutputsomemoney){

printf(“您的餘額已不足,請您注意!”);

}else {

int q;

int r=1;

for(q=0;q100;q++)

{

int w;

for(w=1;wr;w++)

{

printf(“.”);

}

r++;

if(r==10)

{

r=1;

}

printf(“\n\t\t\t\t\t\t正在取款%d%%”,q);

system(“cls”);

}

one.money=one.money-outputsomemoney;

fseek(fp,-sizeof(one),1);

fwrite(one,sizeof(one),1,fp);

printf(“\n\n\t\t\t\t\t\t您已取款成功!請點清鈔票!”);

printf(“\n\n\t\t\t\t\t\t您現在的餘額為%lf”,one.money);

}

}

void transfermoney()

{

system(“cls”);

int duifang;

int qian;

fflush(stdin);

printf(“\n\n\n\t\t您現在使用的是轉賬功能”);

printf(“\n\t\t\t請輸入您要轉賬的賬戶:”);

scanf(“%d”,duifang);

int n=ftell(fp);

rewind(fp);

int flag=0;

struct bank temp;

while(fread(temp,sizeof(temp),1,fp)==1)

{

if(temp.account==duifang)

{

flag=1;

break;

}

}

if(flag==1)

{

printf(“請輸入轉賬金額:”);

scanf(“%d”,qian);

if(one.money=qian)

{

int q;

int r=1;

for(q=0;q100;q++)

{

int w;

for(w=1;wr;w++)

{

printf(“.”);

}

r++;

if(r==10)

{

r=1;

}

printf(“\n\t\t\t\t\t\t正在轉賬,請稍後!%d%%”,q);

system(“cls”);

}

temp.money=temp.money+qian;

fseek(fp,-sizeof(temp),1);

fwrite(temp,sizeof(temp),1,fp);

one.money=one.money-qian;

fseek(fp,n-sizeof(one),0);

fwrite(one,sizeof(one),1,fp);

printf(“\n\t\t\t\t轉賬成功!”);

}else{

printf(“\n\t\t\t\t您的餘額已不足!”);

}

}

}

void xiugai(){

system(“cls”);

printf(“\n\n\t\t 現在進行的是修改密碼功能\n”);

char oldpassword[7];

char newpassword[7];

char newpassword1[7];

int i;

for(i=0;i3;i++){

printf(“\n\t\t\t 請輸入舊密碼:\n”);

inputpassword(oldpassword);

if(strcmp(oldpassword,one.password)==0){

printf(“\n\t\t\t 輸入成功!\n”);

break;

}else{

printf(“\n\t\t\t 密碼輸入有誤,請重新輸入!\n”);

}

}

if(i3){

while(1){

printf(“\n\t\t\t 請輸入您的新密碼:\n”);

inputpassword(newpassword);

printf(“\n\t\t\t 請輸入您的確認密碼:\n “);

inputpassword(newpassword1);

if(strcmp(newpassword,newpassword1)==0){

strcpy(one.password,newpassword);

fseek(fp,-sizeof(one),1);

fwrite(one,sizeof(one),1,fp);

printf(“\n\t\t\t 密碼修改成功!”);

break;

}else{

printf(“\n\t\t\t 兩次密碼輸入不一致!”);

}

}

}else{

printf(“\n\t\t\t 密碼輸入錯誤!”);

}

}

int zhuxiaozhanghao()

{

system(“cls”);

int zhuxiaoxitong;

char sf;

printf(“你要註銷的賬號是%d”,one.account);

printf(“你是否要對此賬號進行註銷?\n\n\t\t請您選擇:註銷(Y)or不註銷(N):”);

fflush(stdin);

scanf(“%c”,sf);

if(sf==’y’||sf==’Y’)

{

printf(“正在為您註銷!\n”,one.account);

zhuxiaoxitong=1;

}else{

printf(“不註銷系統!\n”,one.account);

}

return zhuxiaoxitong;

}

void service()

{

while(1){

system(“cls”);

printf(“\n\n\n\t\t\t\t\t\t現在是服務系統,本系統有以下服務”);

printf(“\n\t\t\t\t\t\t[a] 查詢餘額\n”);

printf(“\n\t\t\t\t\t\t[b] 存款服務\n”);

printf(“\n\t\t\t\t\t\t[c] 轉賬服務\n”);

printf(“\n\t\t\t\t\t\t[d] 取款服務\n”);

printf(“\n\t\t\t\t\t\t[e] 修改密碼\n”);

printf(“\n\t\t\t\t\t\t[f] 註銷 \n”);

printf(“\n\t\t\t\t\t\t[g] 退出系統\n”);

char e;

printf(“\n\t\t\t\t\t\t您要選擇的服務是:”);

fflush(stdin);

scanf(“%c”,e);

switch(e)

{ case’A’:

case’a’: searchmoney() ;break;

case’B’:

case’b’: savemoney() ;break;

case’C’:

case’c’: transfermoney() ;break;

case’D’:

case’d’: withdrawalmoney() ;break;

case’E’:

case’e’: xiugai() ;break;

case’F’:

case’f’: {int zhuxiaoxitong=zhuxiaozhanghao();{if(zhuxiaoxitong==1) return;}break;}

case’G’:

case’g’: quite();break;

}

printf(“\n\n\n\t\t\t\t按任意鍵繼續……\n”);

getch();

}

}

void login()

{

fp=fopen(“atm.txt”,”rb+”);

if(fp==NULL)

{

printf(“\n\n\n\t\t\t\t文件打開失敗!”);

return;

}

system(“cls”);

printf(“\n\t\t\t\t\t\t現在執行的是登錄函數的使用\n”);

int zhanghao;

printf(“\n\t\t\t\t\t\t請輸入賬號:”);

scanf(“%d”,zhanghao);

int flag=0;

while(fread(one,sizeof(one),1,fp)==1)

{

if(zhanghao==one.account){

flag=1;

break;

}

}

char password2[7];

if(flag==1){

int h;

for(h=0;h3;h++){

printf(“\n\t\t\t\t\t\t請輸入密碼:”);

fflush(stdin);

inputpassword(password2);

if(strcmp(password2,one.password)==0)

{

printf(“\n\t\t\t\t\t\t登陸成功!”);

service();

break;

}else{

printf(“密碼不正確!”);

}

}

if(h==3){

printf(“\n\t\t\t您的密碼三次輸入有誤,返回”);

}

}else{

printf(“無此賬號!”);

}

fclose(fp);

}

void quite()

{

system(“cls”);

printf(“\t\t\t現在執行的是退出函數的使用\n”);

exit(0);

}

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/258651.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-15 12:50
下一篇 2024-12-15 12:50

相關推薦

  • AES加密解密演算法的C語言實現

    AES(Advanced Encryption Standard)是一種對稱加密演算法,可用於對數據進行加密和解密。在本篇文章中,我們將介紹C語言中如何實現AES演算法,並對實現過程進…

    編程 2025-04-29
  • 學習Python對學習C語言有幫助嗎?

    Python和C語言是兩種非常受歡迎的編程語言,在程序開發中都扮演著非常重要的角色。那麼,學習Python對學習C語言有幫助嗎?答案是肯定的。在本文中,我們將從多個角度探討Pyth…

    編程 2025-04-29
  • Python被稱為膠水語言

    Python作為一種跨平台的解釋性高級語言,最大的特點是被稱為”膠水語言”。 一、簡單易學 Python的語法簡單易學,更加人性化,這使得它成為了初學者的入…

    編程 2025-04-29
  • OpenJudge答案1.6的C語言實現

    本文將從多個方面詳細闡述OpenJudge答案1.6在C語言中的實現方法,幫助初學者更好地學習和理解。 一、需求概述 OpenJudge答案1.6的要求是,輸入兩個整數a和b,輸出…

    編程 2025-04-29
  • Python按位運算符和C語言

    本文將從多個方面詳細闡述Python按位運算符和C語言的相關內容,並給出相應的代碼示例。 一、概述 Python是一種動態的、面向對象的編程語言,其按位運算符是用於按位操作的運算符…

    編程 2025-04-29
  • Python語言由荷蘭人為中心的全能編程開發工程師

    Python語言是一種高級語言,很多編程開發工程師都喜歡使用Python語言進行開發。Python語言的創始人是荷蘭人Guido van Rossum,他在1989年聖誕節期間開始…

    編程 2025-04-28
  • Python語言設計基礎第2版PDF

    Python語言設計基礎第2版PDF是一本介紹Python編程語言的經典教材。本篇文章將從多個方面對該教材進行詳細的闡述和介紹。 一、基礎知識 本教材中介紹了Python編程語言的…

    編程 2025-04-28
  • Python語言實現人名最多數統計

    本文將從幾個方面詳細介紹Python語言實現人名最多數統計的方法和應用。 一、Python實現人名最多數統計的基礎 1、首先,我們需要了解Python語言的一些基礎知識,如列表、字…

    編程 2025-04-28
  • Python作為中心語言,在編程中取代C語言的優勢和挑戰

    Python一直以其簡單易懂的語法和高效的編碼環境而著名。然而,它最近的發展趨勢表明Python的使用範圍已經從腳本語言擴展到了從Web應用到機器學習等廣泛的開發領域。與此同時,C…

    編程 2025-04-28
  • Python基礎語言

    Python作為一種高級編程語言擁有簡潔優雅的語法。在本文中,我們將從多個方面探究Python基礎語言的特點以及使用技巧。 一、數據類型 Python基礎數據類型包括整數、浮點數、…

    編程 2025-04-28

發表回復

登錄後才能評論