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

/* could you please run/edit my program to match the desired output, thanks in a

ID: 3768814 • Letter: #

Question

/*

could you please run/edit my program to match the desired output, thanks in advance

________________c++ program desired output_____________

Please Enter your account number ( 1 to 100, 0 to end input )?

1

please Enter your last name

smith

please Enter your first name

john

please Enter your balance

100

Please Enter your account number ( 1 to 100, 0 to end input )?

2

please Enter your last name

johnson

please Enter your first name

jack

please Enter your balance

200

Please Enter your account number ( 1 to 100, 0 to end input )?

0

Enter the account youd like to view ( 1 to 100, 0 to end input )

1

last name: smith first name: john balance 100

acct Last name First name Balance

1 smith john 100

2 johnson jack 200

*/

#include <iostream>

#include <fstream>

#include <stdlib.h>

#include <iomanip>

#include <stdio.h>

using namespace std;

struct clientData

{

int acctNum;

char lastName[ 15 ];

char firstName[ 10 ];

double balance;

};

int main()

{

//creates a file

ofstream outCredit("credit.txt",ios::out);

struct clientData blankClient = { 0, "", "", 0.0 };

if (!outCredit)

{

printf( "File could not be opened. " );

}

else

{

for ( int i = 1; i <= 100; i++ )

{

outCredit.write(reinterpret_cast<const char*>(&blankClient), sizeof(clientData));

}

}

//writes data into the file

clientData client;

ofstream outCredit1("credit.txt",ios::ate);

cout<<"Please Enter your account number ( 1 to 100, 0 to end input )? "<<endl ;

cin>>client.acctNum;

while ( client.acctNum != 0 )

{

cout<< "please Enter your last name" <<endl;

cin>>client.lastName;

cout<< "please Enter your first name " <<endl;

cin>>client.firstName;

cout<< "please Enter your balance " <<endl;

cin>>client.balance;

outCredit1.seekp((client.acctNum-1)*sizeof(clientData));

outCredit.write(reinterpret_cast<char*>(&client),sizeof(clientData));

cout<<"please Enter your account number ( 1 to 100, 0 to end input )? "<<endl ;

cin>>client.acctNum;

}

//reads data from the file requested by user

ifstream inCredit("credit.txt",ios::in);

cout<<"Enter the account youd like to view ( 1 to 100, 0 to end input ) "<<endl ;

cin>>client.acctNum;

inCredit.seekg((client.acctNum-1)*sizeof(clientData));

inCredit.read(reinterpret_cast<char*>(&client),sizeof(clientData));

cout<<"last name: "<<client.lastName<<" "<<"first name: "<<client.firstName<<" "<<" balance: "<<client.balance<<endl;

//prints out all records that do not have account Number=0

cout<< "Acct Last Name First Name Balance"<<endl;

while ( inCredit&& !inCredit.eof() )

{

inCredit.read(reinterpret_cast<char*>(&client),sizeof(clientData));

if (client.acctNum != 0)

cout << client.acctNum<<" " << client.lastName;

cout<< " " << client.firstName << " " << client.balance << endl;;

}

system("pause");

return 0;

}

Explanation / Answer

Here is the code for you. If you have any further queries, just get back to me....

#include <iostream>
using namespace std;
int main()
{
int count = 0;
int accountNumber[20], accNo;
string lastName[20];
string firstName[20];
int balance[20];
accountNumber[0] = 1;
while(accountNumber[count] > 0 && accountNumber[count] < 101)
{
cout<<"Please Enter your account number ( 1 to 100, 0 to end input )?"<<endl;
cin>>accountNumber[count];
if(accountNumber[count] <= 0 || accountNumber[count] > 100)
break;
cout<<"please Enter your last name"<<endl;
cin>>lastName[count];
cout<<"please Enter your first name"<<endl;
cin>>firstName[count];
cout<<"please Enter your balance"<<endl;
cin>>balance[count];
count++;
accountNumber[count] = 1;
}
accNo = 1;
while(accNo >0 && accNo < 101)
{
cout<<"Enter the account youd like to view ( 1 to 100, 0 to end input )";
cin>>accNo;
if(accNo <= 0 || accNo > 100)
break;
for(int j = 0; j < count; j++)
if(accountNumber[j] == accNo)
cout<<"last name: "<<lastName[j]<<" first name: "<<firstName[j]<<" balance "<<balance[j]<<endl;
}
}