问:我一直在从事一个项目,但是当我找到一个单词时,我一直坚持如何显示某些信息。例如。我想搜索2015年1月的资产负债表数据,当找到确切的月份和年份时,它将在文件中显示其余信息。然后,如果需要,我会更新该特定信息。我试图做一个搜索功能,但是我的程序一直崩溃。是因为在读取文件时,数据没有存储在各自的变量中吗?
class BalanceSheet
{
//total
double assets;
double totalLiabilities;
double totalEquity;
double totalLiabilitiesAndEquity;
string departmentName;
int serialNo;
int serialNo_Inc;
public:
string month;
string year;
double cash;
double accountsReceivable;
double inventory;
double building;
double land;
double equipment;
double otherAssets;
//liabilities
double accountsPayable;
double loansPayable;
//equity
double equity;
double retainedEarnings;
BalanceSheet *balanceSheetNext = NULL;
BalanceSheet()
{
assets = 0;
totalEquity = 0;
totalLiabilities = 0;
totalLiabilitiesAndEquity = 0;
assets = cash + accountsReceivable + inventory + building + land + equipment + otherAssets;
accountsPayable = accountsReceivable;
loansPayable = land;
equity = cash + accountsReceivable + inventory + otherAssets;
retainedEarnings = assets - (equipment + inventory + otherAssets);
totalEquity = equity + retainedEarnings;
totalLiabilities = accountsPayable + loansPayable;
totalLiabilitiesAndEquity = totalLiabilities + totalEquity;
}
void setDataForFile(ifstream &fileBalanceSheetInput)
{
serialNo = serialNo_Inc++;
fileBalanceSheetInput >> month;
fileBalanceSheetInput >> year;
fileBalanceSheetInput >> cash;
fileBalanceSheetInput >> accountsReceivable;
fileBalanceSheetInput >> inventory;
fileBalanceSheetInput >> land;
fileBalanceSheetInput >> building;
fileBalanceSheetInput >> equipment;
fileBalanceSheetInput >> otherAssets;
}
void setDataManual()
{
cout << "Serial Number " <<endl;
serialNo = serialNo_Inc++;
cout << "Month: ";
cin >> month;
cout << endl;
cout << "Year: ";
cin >> year;
cout << endl;
cout << "Cash: ";
cin >> cash;
cout << endl;
cout << "Accounts Receivable: ";
cin >> accountsReceivable;
cout << endl;
cout << "Inventory: ";
cin >> inventory;
cout << endl;
cout << "Land: ";
cin >> land;
cout << endl;
cout << "Building: ";
cin >> building;
cout << endl;
cout << "Equipment: ";
cin >> equipment;
cout << endl;
cout << "Other Assets: ";
cin >> otherAssets;
cout << endl;
}
void updateBalanceSheet(BalanceSheet *bsUpdateNode, string = "", string year = "", double cash = 0, double accountsReceivable = 0, double inventory = 0, double building = 0, double land =0, double equipment = 0, double otherAssets = 0)
{
bsUpdateNode->cash = cash;
bsUpdateNode->accountsReceivable = accountsReceivable;
bsUpdateNode->inventory = inventory;
bsUpdateNode->building = building;
bsUpdateNode->land = land;
bsUpdateNode->equipment = equipment;
bsUpdateNode->otherAssets = otherAssets;
}
void displayRecord()
{
assets = cash + accountsReceivable + inventory + building + land+ equipment + otherAssets;
accountsPayable = accountsReceivable;
loansPayable = land;
equity = cash + accountsReceivable + inventory + otherAssets;
retainedEarnings = assets - (equipment + inventory + otherAssets);
totalEquity = equity + retainedEarnings;
totalLiabilities = accountsPayable + loansPayable;
totalLiabilitiesAndEquity = totalLiabilities + totalEquity;
cout << "Serial Number" << serialNo;
cout << "---------Election Commissions---------" << endl;
cout << month << ", " << year << "---------" << endl;
cout << endl;
cout << "-------------------" << endl;
cout << "ASSETS: " << endl;
cout << "-------------------" << endl;
cout << "Cash: " << "\t\t\t Tk." << cash << endl;
cout << "Accounts Receivable: " << "\t\t\t Tk." << accountsReceivable << endl;
cout << "Inventories: " << "\t\t\t Tk." << inventory << endl;
cout << "Land: " << "\t\t\t Tk." << land << endl;
cout << "Buildings: " << "\t\t\t Tk." << building << endl;
cout << "Equipment: " << "\t\t\t Tk." << equipment << endl;
cout << "Other assets: " << "\t\t\t Tk." << otherAssets << endl;
cout << "---Total Assets---\t\t\t Tk." << assets << endl;
cout << endl;
cout << "-------------------" << endl;
cout << "LIABILITIES: " << endl;
cout << "-------------------" << endl;
cout << endl;
cout << "Accounts Payable: " << "\t\t\t Tk." << accountsPayable << endl;
cout << "Loans Payable: " << "\t\t\t Tk." << loansPayable << endl;
cout << "---Total Liabilities---\t\t\t Tk." << totalLiabilities << endl;
cout << endl;
cout << "-------------------" << endl;
cout << "EQUITY: " << endl;
cout << "-------------------" << endl;
cout << endl;
cout << "Retained Earnings: " << "\t\t\t Tk." << retainedEarnings << endl;
cout << "Equity: " << "\t\t\t Tk." << equity << endl;
cout << "---Total Equity---\t\t\t Tk." << totalEquity << endl;
cout << endl;
cout << "---Total Equity and Liabilities---\t\t\t Tk."<< totalLiabilitiesAndEquity << endl;
}
void pushIntoDatabaseForBalanceSheet(BalanceSheet *balanceSheetNode)
{
ofstream bsFile;
bsFile.open("BalanceSheet3.txt", ofstream::out | ofstream::app );
while (balanceSheetNode)
{
balanceSheetNode->assets = balanceSheetNode->cash + balanceSheetNode->accountsReceivable + balanceSheetNode->inventory + balanceSheetNode->building + balanceSheetNode->land+ balanceSheetNode->equipment + balanceSheetNode->otherAssets;
balanceSheetNode->accountsPayable = balanceSheetNode->accountsReceivable;
balanceSheetNode->loansPayable = balanceSheetNode->land;
balanceSheetNode->equity = balanceSheetNode->cash + balanceSheetNode->accountsReceivable + balanceSheetNode->inventory + balanceSheetNode->otherAssets;
balanceSheetNode->retainedEarnings = balanceSheetNode->assets - (balanceSheetNode->equipment + balanceSheetNode->inventory + balanceSheetNode->otherAssets);
balanceSheetNode->totalEquity =balanceSheetNode->equity + balanceSheetNode->retainedEarnings;
balanceSheetNode->totalLiabilities = balanceSheetNode->accountsPayable + balanceSheetNode->loansPayable;
balanceSheetNode->totalLiabilitiesAndEquity = balanceSheetNode->totalLiabilities + balanceSheetNode->totalEquity;
bsFile << "---------Election Commissions---------" << "\n";
bsFile << balanceSheetNode->month << ", " << balanceSheetNode->year << "---------" << "\n";
bsFile << "-------------------" << endl;
bsFile << "ASSETS: "<< "\n";
bsFile << "-------------------" << endl;
bsFile << "Cash: " << "\t\t\t Tk." << balanceSheetNode->cash << "\n";
bsFile << "Accounts Receivable: " << "\t\t\t Tk." << balanceSheetNode->accountsReceivable << "\n";
bsFile << "Inventories: " << "\t\t\t Tk." << balanceSheetNode->inventory << "\n";
bsFile << "Land: " << "\t\t\t Tk." << balanceSheetNode->land << "\n";
bsFile << "Buildings: " << "\t\t\t Tk." << balanceSheetNode->building << "\n";
bsFile << "Equipment: " << "\t\t\t Tk." << balanceSheetNode->equipment << "\n";
bsFile << "Other assets: " << "\t\t\t Tk." << balanceSheetNode->otherAssets << "\n";
bsFile << "---Total Assets---\t\t\t \nTk." << balanceSheetNode->assets << "\n";
bsFile << "-------------------" << endl;
bsFile << "LIABILITIES: " << "\n";
bsFile << "-------------------" << endl;
bsFile << "Accounts Payable: " << "\t\t\t Tk." << balanceSheetNode->accountsPayable << "\n";
bsFile << "Loans Payable: " << "\t\t\t Tk." << balanceSheetNode->loansPayable << "\n";
bsFile << "---Total Liabilities---\t\t\t \nTk." << balanceSheetNode->totalLiabilities << "\n";
bsFile << "-------------------" << endl;
bsFile << "EQUITY: " << "\n";
bsFile << "-------------------" << endl;
bsFile << "Retained Earnings: " << "\t\t\t Tk." << balanceSheetNode->retainedEarnings << "\n";
bsFile << "Equity: " << "\t\t\t Tk." << balanceSheetNode->equity << "\n";
bsFile << "---Total Equity---\t\t\t Tk." << balanceSheetNode->totalEquity << "\n";
bsFile << "\n";
bsFile << "---Total Equity and Liabilities---\t\t\t \nTk." << "\n" << balanceSheetNode->totalLiabilitiesAndEquity << "\n";
balanceSheetNode = balanceSheetNode->balanceSheetNext;
bsFile << "\n";
}
bsFile.close();
}
};
BalanceSheet *balanceSheetFirstPoint = NULL;
BalanceSheet *balanceSheetTempPoint;
BalanceSheet bs;
void GetBalanceSheetMonthly(int NUMBER_INDICES)
{
for (int i = 1; i <= NUMBER_INDICES; i++)
{
balanceSheetTempPoint = new BalanceSheet;
if (!balanceSheetFirstPoint)
{
balanceSheetTempPoint->setDataManual();
balanceSheetFirstPoint = balanceSheetTempPoint;
}
else
{
balanceSheetTempPoint->setDataManual();
balanceSheetTempPoint->balanceSheetNext = balanceSheetTempPoint;
balanceSheetFirstPoint = balanceSheetTempPoint;
bs.pushIntoDatabaseForBalanceSheet(balanceSheetFirstPoint);
}
}
}
void showBalanceSheetMonthly()
{
balanceSheetTempPoint = balanceSheetFirstPoint;
while (balanceSheetTempPoint)
{
balanceSheetTempPoint->displayRecord();
balanceSheetTempPoint = balanceSheetTempPoint->balanceSheetNext;
cout << endl;
}
}
BalanceSheet searchBS(BalanceSheet *bsFirstPoint, string month, string year)
{
BalanceSheet *tempPoint;
tempPoint = bsFirstPoint;
BalanceSheet found;
while (tempPoint)
{
if (tempPoint->month == month && tempPoint->year==year)
{
found = *tempPoint;
return found;
}
tempPoint = tempPoint->balanceSheetNext;
}
}
void findNode(string month, string year)
{
searchBS(balanceSheetFirstPoint, month, year);
}
答:以上代码不能体现。