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

Create C++ code for the following: John is a loan officer, He scanned a pile of

ID: 3836650 • Letter: C

Question

Create C++ code for the following: John is a loan officer, He scanned a pile of documents from his desk for different mortgage applications. Some of the loan applications are missing required documents. Write a program to help him organize the documents, and determine which ones are missing.

Every document contains metadata, including:

- document name("fileName"),

- document owner("owner"),

- document type ("docType"),

- loan application ID ("applicationId"), and

- content length ("contentLength")

your task is to find all the document types that are missing for each loan application. Every loan application must include every document type. Since you are new to Prem's work, you don't know how many document types there are in total. You should figure that from the pile yourself.

INPUT (stdin):

Take input from a file called "myFile.txt" . A sample file input is given below as an example.

A comma delimited file with the first line as field names.

Input Sample File:

fileName,owner,docType,applicationId,contentLength

bank_statement_1,Sunny,bank_statement,1,1000

tax_document_1,Sunny,tax_return,1,16001

tax_document_2,Jay,tax_return,2,2000

document_123,Ram,tax_return,3,1500

medical_report,Ram,medical_history,3,15000

prescription,Jason,medical_history,4,200

property_assets,Jason,bank_statement,4,4000

OUTPUT (stdout):

- Print out two lines for each document type. The first line is document type. The second line are the application IDs that are missing for this type of document.

- Delimit the application IDs by one space

- Sort document types in alphabetical order. Sort application IDs in numerical order.

- Print only document types when they are missing for at least one loan application.

SAMPLE OUTPUT:

bank_statement

2 3

medical_history

1 2

tax_return

4

EXPLANATION:

After scanning the given file we come to know that each application should contain bank_statement, medical_history and tax_return.

Jay and Ram are missing bank_statement in their application

Sunny and Jay are missing medical_history in their application

Jason is missing tax_return in his application

since Id of sunny is 1, Jay is 2, Ram is 3 and Jason is 4.

if we write all documents in alphabetical order and people who are missing them. Then the output would look like the sample output above.

Explanation / Answer

#include<iostream>

#include<fstream>

#include<stdlib.h>

using namespace std;

// class docs definatio

class Docs

{

//data member

string fileName;

string owner;

string docType;

int appId;

int contentLength;

int numOfRecords;

public:

//member functions

//to read file

void readFile (Docs []);

//to display file contents

void display(Docs [])

{

// swapping process

if(rec[y].appId>rec[y+1].appId)

{

Docs temp=rec[y];

rec[y]=rec[y+1];

rec[y+1]=temp;

}

}

}

}

}

//function to find out the records missing documents

void Docs::InvalidDocs(Docs rec[])

{

//creates 3 flag point for each record

// zero column position for bank statement missing

// 1 column position for medical statement missing

// 2 column position for tax statement missing

int flag[100][3]={0,0,0,0};

//to store record number missing documents

int bak[100], medical[100], tax[100];

//counter cb for bank, cm for medical, ct for tax

int cb=0, cm=0, ct=0;

//counter for each record

it c=o;

for(int x=0; x<numOfRecords; x++)

{

//checks for the 1st record

if(x==0)

{

//checks if the record number document type is bank account

if(rec[x].docType=="Bank_Statement")

{

// flag record number(row) position & document type[column] position is set to record number

flag[c][0]=rec[x].appId;

}

//checks if the record number document type is medical history

if(rec[x].docType=="Medical_History")

{

// flag record number(row) position & document type[column] position is set to record number

flag[c][1]=rec[x].appId;

}

//checks if the record number document type is the tax return

if(rec[x].docType=="Tax_Return")

{

// flag record number(row) position & document type[column] position is set to record number

flag[c][2]=rec[x].appId;

}

}

//if not first record

else

{

//checks current application id = previous app id then don't change the record num for flag

if(rec[x].appId==rec[x-1].appId)

{

//

//checks if the record number document type is bank account

if(rec[x].docType=="Bank_Statement")

{

// flag record number(row) position & document type[column] position is set to record number

flag[c][0]=rec[x].appId;

}

//checks if the record number document type is medical history

if(rec[x].docType=="Medical_History")

{

// flag record number(row) position & document type[column] position is set to record number

flag[c][1]=rec[x].appId;

}

//checks if the record number document type is the tax return

if(rec[x].docType=="Tax_Return")

{

// flag record number(row) position & document type[column] position is set to record number

flag[c][2]=rec[x].appId;

}

}

//checks current app id is not equal to previous app id then increase flag record number by 1

else

{

//increase the flag record num by 1

c++;

//

//checks if the record number document type is bank account

if(rec[x].docType=="Bank_Statement")

{

//store invalid records

void InvalidReport(Docs[]);

//display file contents

void Docs::display(Docs rec[])

{

cout<<" records in the file";

for(int x=0; x<numOfRecords;x++)

{

cout<<rec[x].fileName<<" "<<rec[x].owner<<" "<<rec[x].docType<<" "<<rec[x].appId<<" "<<rec[x].contentLength;

}

//sort record num

void SortRecordNum(Docs rec[])

{

//for(int x=0; x<numOfRecords; x++)

{

//loops till number of records-x-1 times

//on each iteration 1 record is sorted so number of records=x

for(int y=0; y<numOfrecords-x-1; y++)

{

tax[ct++]=(x+1);

}

};

int main()

{

Docs rec[100];

rec[0].readFile(rec);

rec[0].display(rec);

rec[0].SortRecNum(rec);

rec[0].InvalidReport(rec);

return 0;

}

//read the data from file & return no.of records

void Docs::readFile(Docs rec[])

{

//creates an object if ifstream

ifstream readf;

//opens the file myFile.txt for reading

readf,open("myFile.txt");

//intializes no.of records to zero

numOfRecords=0;

//to store idividual data

string hed;

char heading[100];

//read heading

readf>>hed;

//loops till end of file

while(readf.eof())

{

//loops 5 times for each heading

for(int x=0; x<5; x++)

{

//checks the heading num

switch(x)

{

case 0:

//extracts data till comma

readf.getline(heading, 256, ',');

//stores the data in fileName

rec[numOfRecords].fileName=heading;

break;

case 1:

readf.getline(heading, 256, ',');

rec[numOfRecords].owner=heading;

break;

case 2:

readf.getline(heading, 256, ',');

rec[numOfRecords].docType=heading;

break;

case 3:

readf.getline(heading, 256, ',');

//conerts the data to int

rec[numOfRecords].appId=atoi(heading);

break;

case 4:

readf>>rec[numOfRecords].contentLength;

break;

}

}

//increase the record counter

numOfRecords++;

}

readf.close();

}