Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to display rest of the info from file after searching a word

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 531
    Answer it

    I've been working on a project and I'm stuck at how to display a certain info when I found the word. For example. I want to search the balance sheet data of January 2015 and it will display the rest of the info in the file when found the exact month and year. I then would update that certain info if needed. I tried to make a search function but my program crashes all the time. Is it because as the file is being read, are the data not stored into their respective variables?

      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);
        }

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: