Question

In: Computer Science

Need this in C++ // Start // Declarations // InputFile masterFile; // InputFile transactionFile; // OutputFile...

Need this in C++

// Start

// Declarations

// InputFile masterFile;

// InputFile transactionFile;

// OutputFile newMasterFile;

// num mClientNumber, mtotalClientCost, tClientNumber, titemClientCost

// string mClientfName, mClientlName// output "Master File Updating Starting"

// open masterFile "Master.rtf"

// open transactionFile "Transaction.rtf"

// open newMasterFile "newMaster.rtf"

// read mClientNumber, mClientfName, mClientlName, mtotalClientCost from masterFile

// read tClientNumber, titemClientCost from transactionFile

// while ( transactionFile not EOF )

// while (( masterFile not EOF) and (mClientNumber < tClientNumber))

// output mClientNumber, mClientfName, mClientlName, mtotalClientCost to newMasterFile

// read mClientNumber, mClientfName, mClientlName, mtotalClientCost from masterFile

// endwhile

// if (masterFile is EOF)

// output "Error Client ID: ", tClientNumber, " not in Master File."

// else if (mClientNumber == tClientNumber) then

// mtotalClientCost = mtotalClientCost + titemClientCost

// output mClientNumber, mClientfName, mClientlName, mtotalClientCost to newMasterFile

// read mClientNumber, mClientfName, mClientlName, mtotalClientCost from masterFile

// else if (mClientNumber > tClientNumber) then

// output "Error Client ID: ", tClientNumber, " not in Master File."

// endif

// read tClientNumber, titemClientCost from transactionFile

// endwhile

// while (masterFile not EOF)

// output mClientNumber, mClientfName, mClientlName, mtotalClientCost to newMasterFile

// read mClientNumber, mClientfName, mClientlName, mtotalClientCost from masterFile

// endwhile

// output "Master File Updating Complete"

// close masterFile

// close transactionFile

// close newMasterFile

// Stop

Solutions

Expert Solution

#include <iostream>
#include <fstream>

using namespace std;

int main() {
  
  ifstream masterFile;
  ifstream transactionFile;

  ofstream newMasterFile;

  double mClientNumber, mtotalClientCost, tClientNumber, titemClientCost;
  string mClientfName, mClientlName;

  cout << "Master File Updating\n";

  masterFile.open("MasterFile.rtf");
  transactionFile.open("Transaction.rtf");
  newMasterFile.open("newMaster.rtf");

  masterFile >> mClientNumber >> mClientfName >> mClientlName >> mtotalClientCost;

  transactionFile >> tClientNumber >> titemClientCost;

  // read tClientNumber, titemClientCost from transactionFile

  while( !transactionFile.eof() ) {
    while( !masterFile.eof() and ( mClientNumber < tClientNumber ) ) {

      newMasterFile << mClientNumber << " " << mClientfName << " " << mClientlName << " " << mtotalClientCost << endl;

      masterFile >> mClientNumber >> mClientfName >> mClientlName >> mtotalClientCost;

    }

    if( masterFile.eof() ) {
      cout << "Error Client ID: " << tClientNumber << " not in Master File.\n";
    }

    else if (mClientNumber == tClientNumber) {
      mtotalClientCost = mtotalClientCost + titemClientCost;

      newMasterFile << mClientNumber << " " << mClientfName << " " << mClientlName << " " << mtotalClientCost << endl;

      masterFile >> mClientNumber >> mClientfName >> mClientlName >> mtotalClientCost;
    } 
    
    else if ( mClientNumber > tClientNumber ) {

      cout << "Error Client ID: " << tClientNumber << " not in Master File.\n";

    }

    transactionFile >> tClientNumber >> titemClientCost;
  }

  while( !masterFile.eof() ) {
    newMasterFile << mClientNumber << " " << mClientfName << " " << mClientlName << " " << mtotalClientCost << endl;

    masterFile >> mClientNumber >> mClientfName >> mClientlName >> mtotalClientCost;
  }

  cout << "Master File Updating Complete\n";

  masterFile.close();
  transactionFile.close();
  newMasterFile.close();
}

You have not provided any Input Samples In Your Question. Anyway I Have Tested With The Following Inputs.

MasterFile.rtf

Transaction.rtf

This Was The Output File,

newMaster.rtf

NB: As you can see, the record for id 200 was omitted as per your pseudocode. we are only adding entries from the TransactionList. People In MasterFile but not in Transaction File Are Not Included In The newMaster.rtf

This Was The Console Output Which Showed Error For Ids not in the Master File :


Related Solutions

need this in C++ Start Declarations number currentTuition number futureTuition number interestRate number numYears number year...
need this in C++ Start Declarations number currentTuition number futureTuition number interestRate number numYears number year output "Please enter current tuition: " input currentTuition output "Please enter interest rate (e.g. 9.0 for 9 percent): " input interestRate output "Please number of years for tuition: " input numYears output “Tuition at year 1 is “, currentTuition futureTuition = currentTuition for year = 2 to numYears futureTuition = futureTuition * (1 + interestRate/100) output “Tuition at year “, year ,”is “, futureTuition...
Every insurance contract has a set of declarations. The declarations of a typical insurance policy include...
Every insurance contract has a set of declarations. The declarations of a typical insurance policy include all of the following information EXCEPT A. exclusions B. name of the insured C.name of the insurer D. effective date
C (1) Create three files to submit: ItemToPurchase.h - Struct definition and related function declarations ItemToPurchase.c...
C (1) Create three files to submit: ItemToPurchase.h - Struct definition and related function declarations ItemToPurchase.c - Related function definitions main.c - main() function Build the ItemToPurchase struct with the following specifications: Data members (3 pts) char itemName [ ] int itemPrice int itemQuantity Related functions MakeItemBlank() (2 pts) Has a pointer to an ItemToPurchase parameter. Sets item's name = "none", item's price = 0, item's quantity = 0 PrintItemCost() Has an ItemToPurchase parameter. Ex. of PrintItemCost() output: Bottled Water...
Compare between document type declarations and document instance.
Compare between document type declarations and document instance.
Given two integers, start and end, where end is greater than start, write a recursive C++...
Given two integers, start and end, where end is greater than start, write a recursive C++ function that returns the sum of the integers from start through end, inclusive.Example: If start is 5 and end is 10 then the function will return: 45 which is sum of 5, 6, 7, 8, 9, and 10. int sum (int start, int end){
4. For each of the following haskell type declarations, declare an object of the type this....
4. For each of the following haskell type declarations, declare an object of the type this. a. type this = ([Bool], Float) b. type this = (Float, Integer) -> ([Float], Integer) c. data that = new Char | old Integer type this = [(Float, that)] d. type this = (a, b) -> (a, a)
what are the most important things that i need to know in order to start a...
what are the most important things that i need to know in order to start a private equity in the future? what is the best way to start?
Investors in start-ups need to know what is going on in the companies they invest in....
Investors in start-ups need to know what is going on in the companies they invest in. Explain why key metrics are needed for effective and efficient monitoring by investors. Next, for a specific business model of your choice (e.g. brick-and-mortar retail store) outline the type of information an entrepreneur should provide to the investor.
At which point in the history of mankind did societies start to experience the need to...
At which point in the history of mankind did societies start to experience the need to develop property rights? Stone Age Agricultural Age Industrial Age Information Age The exact time point cannot be easily established by historians.
Assignment (C language, not C ++) Start a new project to store grade information for 5...
Assignment (C language, not C ++) Start a new project to store grade information for 5 students using structures. Declare a structure called student_t that contains : First name Last name Student ID Number Percentage grade Letter grade Create the following functions: getStudentInfo(void)- Declares a single student object - Uses printf()/scanf() to get keyboard input for Name, SID, and Percentage (not Letter). - Returns a single student structure calcStudentGrade(student_t *st_ptr)- Takes the pointer to a student (to avoid making a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT