?? item.h
字號(hào):
#include <stdio.h>
#include <memory.h>
#define MAX_MONEY 100000000// 存入的最大金額
#define LENGTH 41 //一個(gè)記錄長(zhǎng)
class Item{
public:
int account;//帳號(hào),9位
int password;//密碼,6位
double deposit;//剩余金額,17位
char type;//存款類型,u代表活期,f代表定期
int month;//月份,3位
//成員函數(shù)
Item(){ memset(this,0,sizeof(this));};//構(gòu)造函數(shù)
void Fin(int, FILE*);//輸入是position和輸入文件名 從文件讀入相應(yīng)記錄
void Fout(int, FILE*);//輸入是postion和輸出文件名 寫入文件的相應(yīng)記錄
bool AddMoney(double, double);//輸入是金額和利率 存錢,如果儲(chǔ)蓄金額超過MAX_MONEY,返回false
bool DrawMoney(double, double);//輸入的是取款金額和利率, 取錢,如果不夠則不取,返回false
bool ChangePass(int);//輸入的是密碼, 如果改變不成功則返回false,此函數(shù)中不包括密碼驗(yàn)證
void Display();//輸出帳號(hào),剩余金額,存款類型
bool CheckPass(int);//輸入是帳號(hào)名 用來驗(yàn)證身份
//內(nèi)部用來計(jì)算利息的
void CountInterest(double);//輸入是利率
//高級(jí)管理者的成員函數(shù)
void MonthPlus();//經(jīng)過一個(gè)月
void DisplayPass();//可以看到用戶的密碼
bool operator < (Item &);
bool operator > (Item &);
Item & operator = (Item &);
bool operator == (Item &);
};
void Item::Fin(int pos, FILE* In)
{
fseek(In,pos*LENGTH,0);//LENGTH為一個(gè)記錄長(zhǎng)
fscanf(In,"%d %d %lf %c %d\n", &account, &password, &deposit, &type, &month);
return;
}
void Item::Fout(int pos, FILE* Out)
{
int whole=(int)deposit;
if(whole>deposit)
whole-=1;
int frac=(deposit-whole)*10000000;
if(frac&10 >=5){//處理double型不精確導(dǎo)致的錯(cuò)誤,四舍五入
frac/=10;
frac++;
}
else
frac/=10;
fseek(Out, pos*LENGTH,0);
fprintf(Out, "%09d %06d %09d.%06d %c %03d\n" ,account ,password ,whole ,frac ,type ,month);
return;
}
bool Item::AddMoney(double plus, double rate)
{
CountInterest(rate);
if(deposit+plus>MAX_MONEY)
return false;
else{
deposit+=plus;
return true;
}
}
bool Item::DrawMoney(double minus, double rate)//輸入的是取款金額, 取錢,如果不夠則不取,返回false
{
CountInterest(rate);
if(deposit-minus<0)
return false;
else{
deposit-=minus;
return true;
}
}
bool Item::ChangePass(int newpass)
{
password=newpass;
return true;
}
void Item::Display()
{
printf("account=%d deposit=%.2lf type=%c month=%d\n",account, deposit, type, month);
return;
}
bool Item::CheckPass(int pass)//輸入是帳號(hào)名 用來驗(yàn)證身份
{
if(pass==password)
return true;
else
return false;
}
//內(nèi)部用來計(jì)算利息的
void Item::CountInterest(double rate)
{
double plus=deposit*month*rate;
if(deposit+plus>MAX_MONEY)
deposit=MAX_MONEY;
else
deposit+=plus;
month=0;
return;
}
//高級(jí)管理者的成員函數(shù)
void Item::MonthPlus()//經(jīng)過一個(gè)月
{
month++;
return;
}
void Item::DisplayPass()//可以看到用戶的密碼
{
printf("account=%d password=%d",account, password);
return;
}
//重載運(yùn)算符
bool Item::operator < (Item & a)
{
if(account < a.account)
return true;
else
return false;
}
bool Item::operator > (Item & a)
{
if(account > a.account)
return true;
else
return false;
}
Item & Item::operator = (Item & a)
{
account=a.account;
password=a.password;
deposit=a.deposit;
type=a.type;
month=a.month;
return *this;
}
bool Item::operator == (Item & a)
{
if(account==a.account)
return true;
else
return false;
}
/*void main()
{
FILE* a=fopen("database.txt","r+");//注意一定是r+
FILE* b=fopen("d.txt","w+");
Item x[100];
for(int i=0;i<100;i++){
x[i].Fin(i,a);
}
for(i=0;i<100;i++)
x[i].Display();
for(i=0;i<100;i++)
x[i].Fout(i,b);
}*/
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -