Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Simple C++ Coding. Please make sure it compiles :) records.txt John Harris 10011

ID: 3581908 • Letter: S

Question

Simple C++ Coding. Please make sure it compiles :)

records.txt

John Harris 100110030
Lisa Smith 100250122
Adam Johnson 100055967
Sheila Smith 100925710
Tristen Major 101236012
Yannic Lennart 101501457
Lorena Emil 101836902
Tereza Santeri 102025010

(5 points) Extra Credit A banking software needs to read the database of the customers available in a text file. Define a structure with three member variables for first name, last name and bank account number. Use suitable data type. Your program needs to read the text file one record at a time and then display the records on the screen using the member v ariables record a time. Use the text file records-txt for this problem.

Explanation / Answer

// C++ code
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <string> // std::string, std::to_string
#include <math.h>
#include <fstream>

using namespace std;


struct Customer
{
string firstName;
string lastName;
int accountNumber;
};


int main()
{
Customer s[20];
int size = 0;

ifstream inFile ("records.txt");
if (inFile.is_open())
{
while(true)
{
if(inFile.eof())
break;

inFile >> s[size].firstName >> s[size].lastName >> s[size].accountNumber;
size++;
}
inFile.close();
}
else cout << "Unable to open file";


cout << "Customer details ";
for (int i = 0; i < size; ++i)
{
cout << s[i].firstName << " " << s[i].lastName << " " << s[i].accountNumber << endl;
}

return 0;
}

/*
records.txt
John Harris 100110030
Lisa Smith 100250122
Adam Johnson 100055967
Sheila Smith 100925710
Tristen Major 101236012
Yannic Lennart 101501457
Lorena Emil 101836902
Tereza Santeri 102025010


output:
Customer details
John Harris   100110030
Lisa Smith   100250122
Adam Johnson   100055967
Sheila Smith   100925710
Tristen Major   101236012
Yannic Lennart   101501457
Lorena Emil   101836902
Tereza Santeri   102025010

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote