Write the data to the pipe as a c-string

Assignment Help C/C++ Programming
Reference no: EM131458263

ASSIGNMENT

Write a Linux program in C++ to do the following:

Set up pipe:

1) Call fork() to create a parent/child setup.

2) Set up a pipe between parent and child so that the parent is the producer and the child is the consumer.

3) The interlacing of messages printed by different processes will depend on the timing of your program and does not have to match the sample output. However, individual messages should not be broken up. Prevent this using the same method as in HW2:

a) Issue the cout << unitbuf command at the beginning of your program.
b) Use only use one extraction operator ("<<") to print each message, using stringstream to build the message before printing and using \n instead of endl to avoid using a second extraction operator.

Parent processing:

1) Read input file from the file specified a the command line parameter. If no parameter is given, use as a default ~t90rkf1/d480/dhw4/resv.txt.

2) For each record do the following:

a) Write the length of the entry to the pipe as a three-digit alpha field (i.e., no terminator).
b) Write the data to the pipe as a C-string (i.e., with a terminator).
c) Print the data and its length (not including the terminator).

3) At the end of the file, print a count of the number of input records read.

You will find it helpful to log your I/O on standard output, e.g.:

Parent: Reading: 09JUN2014/WN123/MDW/BWI/etc.

Writing: __ bytes: 09JUN2014 etc.

(blank line)

Reading: (etc.)

Child processing:

1) Read each entry as follows:

a) Read the length from the pipe and convert it to a number.
b) Read the specified number of bytes. Add 1 to include the terminator.
c) Break the entry into fixed-length fields and save the fields in a vector of pointers to objects, just as in HW1.

2) Use C++ string functions (not C string functions or subscript use) or regular expressions to break the input record into individual entries. Build keys with fixed-length fields.

3) Use a sort function to sort the entries by date, flight number, city pair, last name and first name. A city pair consists of an origin and destination city. Date, flight number and city pair determine a flight leg. For debugging purposes, it is always a good idea to use a sequence-preserving sort so that the same input will always produce the same output. For a vector, that is the stable_sort function. The record locator (=airline lingo for reservation ID) is printed but is not a sort key, since it doesn't matter to anyone but the passenger.

4) Print the entries with subtotals by flight leg, flight number, date, year/month, and grand total. For example:

2014 September 26 WN 123 MDW-BWI ABC478 Kelly, Gary
WN 123 MDW-BWI ABC456 Kelly, Mary
2014 September 26 WN 123 MDW-BWI 2 * Passengers this leg

2014 September 26 WN 123 BWI-FLL ABC499 Mouse, Mickey
2014 September 26 WN 123 BWI-FLL 1 * Passengers this leg

2014 September 26 WN 123 3 ** Passengers all legs

2014 September 26 3 *** Date total

2014 September 27 WN 123 FLL-MSY ABC499 Mouse, Mickey 2014 September 27 WN 123 FLL-MSY 1 * Passengers this leg

2014 September 27 WN 123 1 ** Passengers all legs

2014 September 27 1 *** Date total

2014 September 4 **** Month total

2014 October 1 WN 123 FLL-MSY ABC487 Mouse, Mickey 2014 October 1 WN 123 FLL-MSY 1 * Passengers this leg

2014 October 1 WN 123 1 ** Passengers all legs

2014 October 1 1 *** Date total

2014 October 1 **** Month total

5 ***** Grand total

Leave a space before each total line except the flight leg total.

Make sure that all of your columns line up and that you print suitable information on each total line.

Your TA may use a different file to test your program.

Hints:

Use the man command to learn the usage of the following system calls and user functions.

pipe( ) read( ) write( ) atoi( )

The following files were used in class to demonstrate binary I/O.

~t90rkf1/d480/dio/dbinary/*.cpp

Note that each of these just reads or writes a single line. For this program, you will need to write a loop that reads multiple records from a binary file. The man page for read explains how to tell when end of file has been reached for a binary file.

The following files will be used in class to illustrate subtotal processing:

~t90rkf1/d480/sub3.cpp single-level subtotal processing
~t90rkf1/d480/msub1.cpp multi-level subtotal processing
~t90rkf1/d480/sub-pseudo.cpp pseudocode explanation of subtotal processing

Some examples of building a comparison function for a sort can be found here::

~t90rkf1/d480/dsort/*.cpp

Further detail about regular expression processing in C++ can be found in this example:

~t90rkf1/d480/regex1d.cpp

Testing suggestions:

Write your program in the following order. Make sure each part works correctly before you go on to the next. Your TA has been instructed not to discuss later sections with you until you have completed the earlier sections correctly.

1. First, make sure that you can read the input correctly and write it to a physical binary file.
2. Second, make sure that you can read your physical binary file correctly and print the detail lines.
3. Then combine your two pieces of code, replacing the physical file with a pipe.
4. Finally, add the total processing.

Style requirements:

Do not use printf, sprintf, character arrays or other features which belong to C style rather than C++. You can use a character array where required as the input to a system call.

Submission instructions:

Same rules as in previous assignments, including the following:

Whenever you issue a system call such, make sure to check for error and terminate, e.g., exit(-1), if the system call fails.

Submit a zip file containing hw4.cpp, the source file for your object (and any other source files you create) and a makefile.

Business case:

The purpose of the detail lines and the "passengers this leg" total is to allow the gate agents to track passenger loading and the passenger load.

The purpose of the "passengers all legs" field is to see how many people would be inconvenienced if the complete flight was cancelled.

The purpose of the date, month and grand totals are to track business, which is seasonal. Most airlines permit reservations 364 days in advance.

There is no need for a terminator on the length field since it is a fixed-length field. Technically, there is no need for a terminator on the data field either but it greatly simplifies debugging. You could save a couple of bytes by eliminating the terminator on the data field and using unsigned binary instead of characters for the length, but it makes the intermediate file a lot harder to visualize.

Reference no: EM131458263

Questions Cloud

How the life cycle competition matrix : After reviewing chapter 15, discuss how the life cycle competition matrix applies to a healthcare organization.
Consumers and consumers incomes : Often times, variations in a company's sales are related to a difference in product prices as well as in consumers and consumers' incomes, tastes.
What can be done to improve working relationships : Different cultures and personalities, and how it can impact the workplace.What are some cultural reasons why workplace bullying is tolerated.
Describ two different ways-synthetically constructing swap : Describe the two different ways of synthetically constructing a swap. Which method is likely to be the easier to implement?
Write the data to the pipe as a c-string : Write the data to the pipe as a C-string. Write the length of the entry to the pipe as a three-digit alpha field (i.e., no terminator).
Define the problem or barrier you are addressing : Define the problem or barrier you are addressing.Explain why your approach is an effective solution to the problem or barrier.
Explain the answer of the given statement : In the Bankers Trust versus Procter & Gamble situation, P&G argued that it did not fully understand the complex interest rate swap it had entered.
Explain the phases of a project life cycle : Explain the phases of a project's life cycle and provide one similarity and one difference between a project and product life cycle.
Does this leader uphold ethical principles : Does this leader uphold ethical principles? Explain. What have you learned from observing this person?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  The private members of yclass are public members of xclass

Suppose that a class employeeType is derived from the class personType. Give examples of data and function members that can be added to the class employeeType.

  What is the output of this c code

What is the output of this C code?

  Test all the memeber function and overloaded operators

Write a program to test all the memeber function and overloaded operators in your class definition.

  Program should read in the file and place periods

Create a C++ program that will read this file and correct errors in the English syntax of the file. The program should Read in the file and Place periods at the end of all sentences throughout this file

  Write a function that compares two stacks for equality

Write a function that compares two stacks for equality. The function takes two stacks as parameters and returns true if they are identical.  The stacks should remain unchanged after the function returns to the calling program.

  What is special about the point where cp is a maximum

what position along the chord does the minimum pressure occur - what is special about the point where Cp is a maximum?

  Write a program in c of fibonacci series

Write a program in c of fibonaci series with and without using fibo func, both

  Calculate the area of the circle

Write an application that prompts the user for the radius of a circle and uses a method called circleArea to calculate the area of the circle.

  Create a void function that takes as parameters

Create a void function that takes as parameters two integers, adds them, and prints them out to the command line.

  Using the labor market, production function

Using the labor market, production function. and AS/AD graphs of the classical model, show the effects of an increase in the marginal product of labor. What are the effects on real wages, the quantity of labor, real GDP, and prices? Explain and show ..

  Write a function to calculate tax

write a function to calculate tax, the sample output is : Filing Status (1) Single (2) Married (3) Head of Household (0)

  A c++ program using the concept of function overloading

write a c++ program using the concept of function overloading for the following options : select the options from [1-3], 1- Area of rectangle 2- Area of square 3- Exit ,

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd