Question

In: Computer Science

Larry is a loan officer, He scanned a pile of documents from his desk for different...

Larry 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")
In C++ 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 Larry'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("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 Example:
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 atleast 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.
Note: The content of "myFile.txt" will be changed while testing your program. So make sure your program works for more documents too.
Please turn in a working .cpp file that takes input from "myFile.txt" and displays output to the console in the format mentioned above.

Solutions

Expert Solution

Code:

//Include libraries

#include<iostream>

#include<fstream>

#include <stdlib.h>

#include<string>

//Use std namespace

using namespace std;

//Define a class Report

class Report

{

     //Declare variable

     string fileName;

     //Declare variable

     string owner;

     //Declare variable

     string docType;

     //Declare variable

     int applicationId;

     //Declare variable

     int contentLength;

     //Declare variable

     int numberOfRecords;

     //Define access specifier

     public:

     //Define a method "readFile()"

     void readFile(Report []);

     //Define a method "display()"

     void display(Report []);

     //Define a method "InvalidReport()"

     void InvalidReport(Report []);

     //Define a method "SortRecordNumber()"

     void SortRecordNumber(Report rep[]);

};

//Define a method "readFile()"

void Report::readFile(Report rec[])

{

     //Define file

     ifstream readf;

     //Open file

     readf.open ("myFile.txt");

     //Declare variable

     numberOfRecords = 0;

     //Store data

     string hed;

     //Declare array

     char heading[100];

     //Read heading

     readf>>hed;

     //Loops till end

     while(!readf.eof())

     {

          //Loop until end

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

          {

              //Switch case

              switch(x)

              {

                   //Define case 0

                   case 0:

                   //Extract data

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

                   //Store data

                   rec[numberOfRecords].fileName = heading;

                   //Break

                   break;

                   //Define case 1

                   case 1:

                   //Extract data

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

                   //Store data

                   rec[numberOfRecords].owner = heading;

                   //Break

                   break;

                   //Define case 2

                   case 2:

                   //Extract data

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

                   //Store data

                   rec[numberOfRecords].docType = heading;

                   //Break

                   break;

                   //Define case 3

                   case 3:

                   //Extract data

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

                   //Converts data to integer

                   rec[numberOfRecords].applicationId = atoi(heading);

                   //Break

                   break;

                   //Define case 4

                   case 4:

                   //Extract data

                   readf>>rec[numberOfRecords].contentLength;

                   //break

                   break;

              }

          }

          //Increment count

          numberOfRecords++;

     }

     //Close file

     readf.close();

}

//Define a function "display()"

void Report::display(Report rec[])

{

     //Display message

     cout<<"\n Records in the file: ";

     //Loop until length

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

     //Display message

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

}

//Define a function "SortRecordNumber()"

void Report::SortRecordNumber(Report rec[])

{

     //Loops till end

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

     {

          //Loops till end

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

          {

              //If id is greater

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

              {

                   //Assign record

                   Report temp = rec[y];

                   //Assign next

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

                   //Swap

                   rec[y+1] = temp;

              }

          }

     }

}

//Define a method "InvalidReport()"

void Report::InvalidReport(Report rec[])

{

     //Declare variables

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

     //Declare arrays

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

     //Declare variables

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

     //Declare variable

     int c = 0;

     //Loops till end

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

     {

          //If x is 0

          if(x == 0)

          {

              //If record is bank_statement

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

              {

                   //Set id

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

              }

              //check document type

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

              {

                   //Set record number

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

              }

              //Check type

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

              {

                   //Assign id

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

              }

          }

          //Otherwise

          else

          {

              //Checks id

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

              {

                   //Checks document type

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

                   {

                        //Assign id

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

                   }

                   //Checks document type

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

                   {

                        //Assign id

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

                   }

                   //Check document type

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

                   {

                        //Assign id

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

                   }

              }

              //Otherwise

              else

              {

                   //Increment

                   c++;

                   //Checks type

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

                   {

                        //Assign id

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

                   }

                   //Check type

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

                   {

                        //Assign value

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

                   }

                   //Check type

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

                   {

                        //Assign id

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

                   }

              }

          }

     }

     //Loop until end

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

     {

          //If value is 0

          if(flag[x][0] == 0)

          //Assign value

          bank[cb++] = (x+1);

          //If value is 0

          if(flag[x][1] == 0)

          //Assign value

          medical[cm++] = (x+1);

          //If value is 0

          if(flag[x][2] == 0)

          //Assign value

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

     }

     //Display message

     cout<<"\n\n bank_statement\n";

     //Loop until length

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

     {

          //Display value

          cout<<bank[x]<<", ";

     }

     //Display message

     cout<<"\n medical_history \n";

     //Loop until count

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

     {

          //Display message

          cout<<medical[x]<<", ";

     }

     //Display message

     cout<<"\n tax_return\n";

     //Loops until count

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

     {

          //Display message

          cout<<tax[x]<<",";

     }

}

//Define main method

int main()

{

     //Create array

     Report rec[100];

     //Read file contents

     rec[0].readFile(rec);

     //Displays array

     rec[0].display(rec);

     //Sort array

     rec[0].SortRecordNumber(rec);

     //Generate document

     rec[0].InvalidReport(rec);

     //Pause console window

     system("pause");

     //Return 0

     return 0;

}


Related Solutions

Prem is a loan officer, He scanned a pile of documents from his desk for different...
Prem 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...
Larry the Loan Shark is an honorable thug. He has handshake agreements (nothing in writing) with...
Larry the Loan Shark is an honorable thug. He has handshake agreements (nothing in writing) with several clients for fixed-rate loans. His enforcers are prepared for every eventuality, except a global pandemic so he has decided to "get in on this hedging thing". How he can hedge his loan portfolio against interest rate fluctuations using both Treasury futures and SWAPS.
David Stern, Commissioner of the National Basketball Association (NBA), scanned the arena from his courtside seat...
David Stern, Commissioner of the National Basketball Association (NBA), scanned the arena from his courtside seat at the sold out Toyota Center in Houston, TX during the 2004 Western Conference Playoffs game between the Houston Rockets and the Los Angeles Lakers. The video commercials and fan-response prompts he viewed on the high-tech scoreboard reminded him of how far technology had progressed since he first took the helm of the league in 1984. The NBA’s tremendous growth that stemmed from increased...
Dr. Russell keeps a desk in the chemical storeroom where he eats his lunch. During an...
Dr. Russell keeps a desk in the chemical storeroom where he eats his lunch. During an earthquake, two chemicals spill inside a locked chemical cabinet in the storeroom. A large tub containing 17.2kg of sodium carbonate reacts with 4.00L of 12.0M hydrochloric acid when they completely mix after the spill. The cabinet is airtight and has dimensions of 1.00m tall by .500 meters wide, and .500 meters deep. The ambient temperature of the room is 23.5 C. The air pressure...
What concerns might a loan officer have when loaning funds to a sole proprietorship that he...
What concerns might a loan officer have when loaning funds to a sole proprietorship that he or she might not have when loaning funds to a corporation? Discuss. Please explain briefly. Thank you.
After reviewing the financial statements, the loan officer at the bank asked your brother whether he...
After reviewing the financial statements, the loan officer at the bank asked your brother whether he used the accrual basis of accounting for revenues and expenses. Your brother responded that he did, which is why he included an account for “Amounts Due from Customers.” The loan officer then asked whether the accounts were adjusted prior to the preparation of the statements. Your brother answered that they had not been adjusted. a. Why do you think the loan officer suspected that...
Wilson Puckett, president of Wabash Waste Management, had a stack of proposals on his desk from...
Wilson Puckett, president of Wabash Waste Management, had a stack of proposals on his desk from several truck companies. Two of the companies, Roper and Rollins, offered trucks on a lease basis, while three dealers wanted Wabash to buy their trucks. In the past Wabash always purchased their trucks. Which proposal would be best, he wondered as he picked up the proposals for the third or fourth time. Wabash Waste Management is an industrial waste recycling company. It picks up...
Ian loaned his friend $25,000 to start a new business. He considers this loan to be...
Ian loaned his friend $25,000 to start a new business. He considers this loan to be an investment, and therefore requires his friend to pay him an interest rate of 9% on the loan. He also expects his friend to pay back the loan over the next four years by making annual payments at the end of each year. Ian texted and asked that you help him calculate the annual payments that he should expect to receive so that he...
TJ is buying a truck and he will finance it with a loan from the dealer...
TJ is buying a truck and he will finance it with a loan from the dealer that requires monthly payments of $356 for the next 60 months. His loan payments are described by which one of the following terms? Group of answer choices A-Perpetuity B-Present value C-Future value D-Annuity Lump sum
Christopher took a loan of $8,300 from his parents to purchase equipment for his hair salon....
Christopher took a loan of $8,300 from his parents to purchase equipment for his hair salon. They agreed on an interest rate of 3% compounded monthly on the loan. What equal quarterly payments made at the end of each period will settle the loan for 5 years if the first payment is to be made 4 years and 1 quarter from now?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT