📄 fig14_08.paul
字号:
// fig14_8.cpp
// Credit inquiry program
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <stdlib.h>
void outputLine( int, char*, double );
main()
{
ifstream inClientFile( "clients.dat", ios::in );
if ( !inClientFile ) {
cerr << "File could not be opened" << endl;
exit( 1 );
}
cout << "Enter request\n"
<< " 1 - List accounts with zero balances\n"
<< " 2 - List accounts with credit balances\n"
<< " 3 - List accounts with debit balances\n"
<< " 4 - End of run\n? ";
int request;
cin >> request;
while ( request != 4 ) {
int account;
char name[ 10 ];
double balance;
inClientFile >> account >> name >> balance;
switch (request) {
case 1:
cout << endl << "Accounts with zero balances:" << endl;
while (!inClientFile.eof()) {
if (balance == 0)
outputLine(account, name, balance);
inClientFile >> account >> name >> balance;
}
break;
case 2:
cout << endl << "Accounts with credit balances:"
<< endl;
while (!inClientFile.eof()) {
if (balance < 0)
outputLine(account, name, balance);
inClientFile >> account >> name >> balance;
}
break;
case 3:
cout << endl << "Accounts with debit balances:"
<< endl;
while (!inClientFile.eof()) {
if (balance > 0)
outputLine(account, name, balance);
inClientFile >> account >> name >> balance;
}
break;
}
inClientFile.clear(); // reset eof for next input
inClientFile.seekg(0); // position to beginning of file
cout << endl << "? ";
cin >> request;
}
cout << "End of run." << endl;
return 0;
}
void outputLine(int acct, char *name, double bal)
{
cout << setiosflags(ios::left) << setw(10) << acct
<< setw(13) << name << setw(7) << setprecision(2)
<< setiosflags(ios::showpoint | ios::right)
<< bal << endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -