Question

In: Computer Science

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 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("myFile.txt" download it from iLearn). 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 Image

//Sample Input file

//Sample Output

//Code to copy

//working.cpp

#include "stdafx.h"
#include<iostream>

#include<fstream>

#include <stdlib.h>

#include<string>

/*Use std namespace */

using namespace std;

/*Declare a class Report */

class Report

{

   /*Declare variable fileName type of string */

   string fileName;

   /*Declare variable owner type of string */

   string owner;

   /*Declare variable docType type of string */

   string docType;

   /*Declare variable applicationId type of integer */

   int applicationId;

   /*Declare variable contentLength type of integer */

   int contentLength;

   /*Declare variable numberOfRecords type of integer */

   int numberOfRecords;


public:

   /*Declare readFile method */

   void readFile(Report[]);

   /*Declare display method*/

   void display(Report[]);

   /*Declare display InvalidReport*/

   void InvalidReport(Report[]);

   /*Declare display SortRecordNumber*/

   void SortRecordNumber(Report rep[]);

};

/*Implementation of the readFile method*/

void Report::readFile(Report rec[])

{

   /*Declare ifstream type variable*/

   ifstream readf;

   /*Open file from its Location */

   readf.open("D:/myFile.txt");

   /*Declare variable */

   numberOfRecords = 0;

   /*Store data as type of string */

   string hed;

   /*Declare array type of char */

   char heading[100];

   /*Read heading from text file */

   readf >> hed;

   /*Iterate the Loop up to end */

   while (!readf.eof())

   {


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

       {

           /*Switch case */

           switch (x)

           {


           case 0:

               /*Extract data from file */

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

               /*Store data into records */

               rec[numberOfRecords].fileName = heading;
               break;

           case 1:

               /*Extract data from file */

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

               /*Store data into records */

               rec[numberOfRecords].owner = heading;

               //Break

               break;


           case 2:

               /*Extract data from file */

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

               /*Store data into records */

               rec[numberOfRecords].docType = heading;

               break;

              

           case 3:

               /*Extract data from file */

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

               /*Converts data to integer */

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


               break;


           case 4:

               /*Extract data from file */

               readf >> rec[numberOfRecords].contentLength;

               break;

           }

       }

       //Increment the counts as numberof Records

       numberOfRecords++;

   }

   /*file close*/

   readf.close();

}

/*Implementation a function "display()" */

void Report::display(Report rec[])

{


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

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

       //Display statement

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

}

/*Implementation a function "SortRecordNumber()" */

void Report::SortRecordNumber(Report rec[])

{

   //Loops till end

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

       {

           //If id is greater then
           if (rec[y].applicationId > rec[y + 1].applicationId)

           {

               /* Assign record to temp */

               Report temp = rec[y];

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

               rec[y + 1] = temp;

           }

       }

   }

}

/*Implementation a function "InvalidReport()" */

void Report::InvalidReport(Report rec[])

{

   /*Declare variables as type of array */

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

   /* Declare arrays as integer type */

   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++)

   {

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

//Define main method

int main()

{

   //Create array of type Report

   Report rec[100];

   //Read the file contents

   rec[0].readFile(rec);

   /*Displays array of records*/

   rec[0].display(rec);

   /* Sort array process */

   rec[0].SortRecordNumber(rec);

   /*Generate document as report format */

   rec[0].InvalidReport(rec);

   system("pause");

   //Return 0

   return 0;
}


Related Solutions

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...
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?
Vincent took a loan of $8,200 from his parents to purchase equipment for his hair salon....
Vincent took a loan of $8,200 from his parents to purchase equipment for his hair salon. If they agreed on an interest rate of 6% compounded quarterly on the loan, what monthly payments will settle the loan in 5 years if he made his first payment 3 years and 6 months from now? a)$194.16 b)$255.21 c)$158.42 d)$208.23
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT