Reading information from a .dat file and storing in an array.

hello all,

I am working on a project to essentially take information from a .dat file, and the program should read in the information from this data file and then provide on-line instructions for a user’s transactions including withdraw, deposit, and check balance. Then goes on to talk about adding accounts, and saving as an updated file but right now I'm having trouble taking the information from the dat file and using it.

birthday, name, balance saving, balance checking for 2 clients (info inside .dat)

The .dat file:

1 8 1943
Margaret Dana Mitchell
1000.00
5000.00
1 12 1955
Mario C. Puzo
9930.00
0.00

This is what I have so far, the output gives the .dat file but not sure where to go from here, not looking for free code just some examples I can use or at least some hints. Yes this is for a project for school but I am stuck and not sure where to go!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;

struct Date 
{
	int day, month, year;
};
struct Name
{
	string First_name, Middle_name, Last_name;
};

class Customer 
{
private:
	Date birth_date;
	Name name;
	float Balance_saving;
	float Balance_checking;
public: 
	void withdraw( float amount, int  account_type);
    void deposit (float amount, int  account_type);
    void check_balance( );  // print out the balance on screen

	Customer();  
	Customer(Date birth_date,  Name  name, float initial_saving, float initial_checking);
};



int main ()

{
	string input;

	fstream dataFile("account.dat", ios::in);

	if (dataFile)
		{
			getline(dataFile, input, '$');

	while (dataFile)
			{
			cout << input << endl;

				getline(dataFile, input, '$');
			}

	dataFile.close();
		}
	else
		{
			cout << "ERROR: Cannot open file.\n";
		}
	system("Pause");
	return 0;
} 
Last edited on
Topic archived. No new replies allowed.