首页 新闻 聚焦 科技 财经 创业 综合 图片 视频

IT界

旗下栏目: 行业 生态 IT界 创新

讲解CS 480留学生程序、讲解C++编程

来源:互联网 发布时间:2021-04-04
讲解CS 480留学生程序、讲解C++编程
CS 480/580-1 ASSIGNMENT #3 Spring 2021 100 points
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 ostringstream or
equivalent 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/dhw/hw3-air/resv.txt. A smaller test file named resv0.txt is available.
2) For each record do the following:
a) Print the input record.
b) Write the data to the pipe as a C-string (i.e., with a terminator).
c) Print the same 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.
 
Child processing:
1) Read each entry as follows:
a) Read the C-string.
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 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. 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:
Leave a space before each total line except the flight leg total. Note that detail lines after the first one in the same first-level group (i.e., for the same leg) have their keys suppressed. Not printing these keys makes the output easier to read.
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( )
The following files were used in class to demonstrate binary I/O.
~t90rkf1/d480/dio/dbinary/*.cpp
Remember that 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 were 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 as well as others in the same directory, especially regex2d.cpp.
~t90rkf1/d480/dregex/*.cpp
Testing suggestions:
Write your program in the Following order. Make sure each part works correctly before you go on to the next.
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 named hw3-xxxx.cpp, where xxxx is your 4letter ID, containing hw3.cpp, the source file for your class (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 track business by flight.
The purpose of the date, month and grand totals are to track business on a seasonal basis. More people travel in the summer than in the winter. In addition, the month right after summer vacation, i.e., September, has the lowest totals of all. Most airlines permit reservations 364 days in advance.
Note that none of the above allow the Copany to see how many people would be inconvenienced if the complete flight was cancelled. For that, cross-cutting totals starting with locator number are required.
 
Grading rubric:
20 points: fork and pipe handling
20 points: input processing and binary I/O
20 points: building objects and sorting
20 points: output processing: printing detail lines
20 points: output Processing: printing total lines
 
请加QQ:99515681 或邮箱:99515681@qq.com   WX:codehelp
  免责声明:珠穆朗玛网对于有关本网站的任何内容、信息或广告,不声明或保证其正确性或可靠性,用户自行承担使用网站信息发布内容的真假风险。
责任编辑:珠穆朗玛网