資源簡介
c++課程設計的一個記賬軟件,對于一些想開始做一些稍大的c++程序的同學有很大的啟示性
代碼片段和文件信息
/*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*
*
*該軟件對大家的日常支出進行管理,具體的功能如下:
*
*1.錄入功能:對某項支出進行錄入,包括支出日期,金額,類別,備注等;
*2.統(tǒng)計功能:能對支出進行多種形式的統(tǒng)計:
* A.?時間段查詢:比如2012-1-30到2012-2-20之間的總支出;
* B.?過高支出查詢:查詢超出N元的天數(shù)和具體日期和支出金額;
* C.?按天列出該天的支出明細;
*3.修改功能:對某項支出進行修改;
*4.刪除功能:刪除該項支出
*
?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*/
#include
#include
#include
using?namespace?std;
void?check_more();//過高支出查詢
void?check_by_time_fun();//時間查詢函數(shù)
void?revise_fun();//用戶對賬單修改函數(shù)
void?detele_fun();//刪除函數(shù)
void?clear_and_detailed();//按照用戶的要求查詢某一天的詳細賬單
void?input_fun();//定義增加賬單函數(shù)
void?check(int&?yearint&?monthint&?day);//檢查函數(shù),檢查年月日的輸入是否合法
//定義公用結構體
struct?Date
{
int?year;
int?month;
int?day;
};//定義日期結構體
struct?Bill
{
Date?date;
double?amount_of_money;//定義金額
char?type;//定義類型
char?remark[200];//定義備注
};//定義賬單結構體
int?main()
{
int?ans;
char?ans2;
do{
cout?<<“*?*?*?歡迎使用萬能記賬?*?*?*?*??\n“;
cout?<<“*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?\n“;
cout?<<“*?????????????????????????????*?\n“;
cout?<<“*??1?.?增加賬單???????????????*?\n“;
cout?<<“*??2?.?按時間查詢?????????????*?\n“;
cout?<<“*??3?.?超過金額查詢???????????*?\n“;
cout?<<“*??4?.?詳單查詢???????????????*?\n“;
cout?<<“*??5?.?修改賬單???????????????*?\n“;
cout?<<“*??6?.?刪除某一天的賬單???????*?\n“;
cout?<<“*??7?.?exit???????????????????*?\n“;?
cout?<<“*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?\n“;
cout?<“請按要求輸入:\n“;
cin?>>?ans;
switch(ans)
{
case?1:
input_fun();
break;
case?2:
check_by_time_fun();
break;
case?3:
check_more();
break;
case?4:
clear_and_detailed();
break;
case?5:
revise_fun();
break;
case?6:
detele_fun();
break;
case?7:
cout?<“非常感謝您使用.\n“;
exit(0);
default:
cout?<<“you?input?error!“;
}
cout?<“?您想再次對賬單進行修改或查看嗎?如果想繼續(xù)請輸入y或者是Y:“;
cin?>>?ans2;
}while(ans2?==?‘y‘||?ans2?==?‘Y‘);
return?0;
}
?
void?input_fun()//用戶錄入函數(shù)
{
ofstream?fout;
fout.open(“bill.txt“ios::app);
if(fout.fail())
{
cout?<“fout?open?failed!\n“;
exit(1);
}
Bill?bill; //生成結構體變量bill
cout?<<“請輸入消費賬單的時間(****年**月**日)(年月日之間用空格隔開):“;
cin?>>?bill.date.year?>>bill.date.month?>>bill.date.day;
check(bill.date.yearbill.date.monthbill.date.day);
cout?<“請輸入消費金額:“;
cin?>>?bill.amount_of_money;
cout?<“請輸入消費類型(以單個英文字母表示):“;
cin?>>?bill.type;
cout?<“請輸入該次消費賬單的備注(不超過一百個字符):“;
cin.get();
int?i=-1;
do{
i++;
cin.get(bill.remark[i]);
}while(bill.remark[i]?!=?10);
//向文件輸出所增加的賬單
fout?< fout?< fout?< fout?< fout?< for(int?j=0;j {
fout?< }
fout?<
fout.close();
return;
}
//按時間查詢
void?check_by_time_fun()
{
ifstream?fin;
fin.open(“bill.txt“);
if(fin.fail())
{
cout?<“
評論
共有 條評論