Print a joke and its punch line from two different files

Assignment Help Computer Engineering
Reference no: EM132211391

Write a program that reads and prints a joke and its punch line from two different files. The first file contains a joke, but not its punch line.

The second file has the punch line as its last line, preceded by "garbage." The main function of your program should open the two files and then call two functions, passing each one the file it needs.

The first function should read and display each line in the file it is passed (the joke file).

The second function should display only the last line of the file it is passed (the punch line file). It should find this line by seeking to the end of the file and then backing up to the beginning of the last line.

Data to test your program can be found in the joke.txt and punchline.txt files.

To display the final line in a file, you need to find it by going to the end of the file and then

backing up a character at a time until it reaches the beginning of the last line. For example,

// Go to the end of the file.
infile.seekg(0, ios::end);

// Move backwards to beginning of the
// final char in the file and read it in
infile.seekg(-1, ios::cur);
ch = infile.get();

Then use while loop to back up until we find a newline. It is where the last sentence starts.

The joke.txt and punchline.txt are attached. You need to save them with the same folder as .cpp file in your project for testing your codes without specifying directory path.

To test the executable, save the exe, joke.txt and puchline.txt in a same folder. So you do not need to specify directory path for txt files.

Reference no: EM132211391

Questions Cloud

What are the reasons that sears fails their stores : What are the 5 most important reasons that Sears fails and start closing their stores. And what lessons we can learn as a business student.
Display the substrings ordered by number of characters : Write a program which reads a single word and displays all possible substrings of that word.
What were american eagle impairment : What were American Eagle's impairment and restructuring charges for the fiscal year ending February 3, 2018? Did American Eagle's gross profit margin increase.
Write a program that reads data from port b once : Write a program that reads data from port B once, extracts data from port A once, and continuously reads data from port C and outputs data from port D.
Print a joke and its punch line from two different files : Write a program that reads and prints a joke and its punch line from two different files. The first file contains a joke, but not its punch line.
Write a program that reads an integer between 0 and 1000 : Write a program that reads an integer between 0 and 1000 by selecting the integer at random; then sum the digits.
Determine impact of the compliance changes : Please walk us through the analysis and approach to determine impact of the compliance changes to USG. Ideal candidates will show work and present results.
How much could the railroad afford to spend now : Burlington Northern is considering the elimination of a railroad grade crossing by constructing a dual-track overpass. The railroad subcontracts for maintenance
Write a program that read a line of text from standard input : Write a program that reads a line of text from standard input and saves it to a text file.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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