#include <iostream>
#include <stdlib.h>
#include <fstream> // this library is used to reading a text file
#include <string.h> // this library is used to calling string functions
using namespace std;
int main () {
// declare a input file stream
ifstream inFile;
// open a file stream
inFile.open("transactions.txt"); // note the .txt file must be in the .cpp file location
// the proccess is checking the was file opened or wasn't
if (!inFile) {
cerr << "Unable to open file datafile.txt";
exit(1); // call system to stop
}
// we declare a string for placing the elements in .txt file
string summary = "";
string x;
while (inFile >> x) {
summary += x + " ";
}
// we initialize all informations to Summary string
int n = 0;
int number_of_deposits = 0;
// this is convert string to char
char cstr[summary.size() + 1];
strcpy(cstr, summary.c_str());
string account_number = "";
for (int i = 0; i < 3; i++) {
account_number += cstr[i];
}
cout << "Account number is that : " << account_number << endl;
for (int i = 0; i < summary.size() + 1; i++) {
if (cstr[i] == 'd') {
string deposit = "";
for (int j = i + 1; ; j++) {
deposit += cstr[j];
if (cstr[j] == ' ')
break;
}
n++;
cout << n << " - deposit balance is " << deposit << endl;
number_of_deposits++;
}
if (cstr[i] == 'w') {
string withdrawn_deposit = "";
for (int j = i + 1; j <= i + 5; j++) {
withdrawn_deposit += cstr[j];
}
cout << "Amount of withdrawn is " << withdrawn_deposit << endl;
}
}
cout << "The number of Deposits: " << number_of_deposits;
}


Comments
Leave a comment