Please write commens so its easy to follow. Please make sure its compiles well e
ID: 3838522 • Letter: P
Question
Please write commens so its easy to follow. Please make sure its compiles well even with other input.
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.
Explanation / Answer
/* #include<stdio.h>
#include<conio.h>
int main()
{
FILE *fp;
char=ch;
fp=fopen("MyFile.txt",w);
printf("enter the document details");
while((ch=getchar())!=EOF)
putc(ch.fp);
fclose(fp);
} */
This is simple program to create a myfile to which have to enter to details and read that for getting your output.
#include <iostream>
#include<fstream>
using namespace std;
main ()
{
ofstream MyFile ("MyFile.txt");
if (MyFile.is_open())
{
// bank statement
MyFile << "bank name:bank_statement ";
MyFile << "owner:Sunny ";
MyFile << "application id:1 ";
MyFile << "content length:1000 ";
// medical history
MyFile << "medical historyn";
MyFile << "owner:ram ";
MyFile<< "application id:3 ";
MyFile << "content length:15000 ";
//tax return
MyFile << "tax document ";
MyFile << "owner:jay ";
MyFile << "application id:2 ";
MyFile << "content length:2000 ";
//repeat above 4 statement for number of input
MyFile.close();
}
else cout<<" bank_statement"<<2<<3;
cout<<" medical_history"<<1<<2;
cout<<" tax_return"<<4;
return 0;
}
create a "MyFile.txt"with this content
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