I am just getting started with C++, so please explain things to me in the most basic way you can. I really don't even know where to start to be honest. Below is a problem that I would like to learn how to code. Examples are welcome. Thank you.

Suppose you want to keep your bank transactions on your computer, and you'd rather keep the information as a simple text file that you can manipulate using C++ programs, rather than being slave to Excel or Quicken. You decide to use the following format for your bank transaction file:
The first line will be the starting balance, and the last line will be -1.

All other lines will contain transactions.

There are three types of transactions: Deposits, checks and ATM withdrawals.

Deposit lines are of the form:
Year Month Day Amount

The year, month and day are all integers, and the amount is a positive double.

Check lines are of the form:
Year Month Day Amount Number

The year, month and day are all integers. The amount is a negative double and number is the check number, which is a positive integer.

ATM withdrawal lines are of the form:
Year Month Day Amount 0

The year, month and day are all integers, and the amount is a negative double.

I really don't even know where to start to be honest.

So you have a file with x lines in them, and you know that the last line will be a '-1', you could use the getline() command to get one line at a time.

For example:

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main()
{
    string line;
    ifstream infile("yourfile.txt");
    if (!infile.is_open())
    {
        cout << "failed to open!";
        return 0;
    }
    while (getline(infile,line))
    {
        cout << line;
        // do stuff with your line here
    }
    return 0;
}

Now you need to parse each line to filter out the date/data. Stringstreams might come in handy at this point.

Try experimenting a bit with this and come back if you have any questions

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.