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

  Developing the sequential circuit

Develop a sequential circuit which can detect two or more consecutive 1's in a stream of the input bits. Specifically, if last two bits in sequence were 1, the circuit must output 1. Otherwise, it must output 0.

  How could companies offering "free" products

The seminar uses Linux as an example of a company that understands competitive positioning. How can companies offering "free" products (e.g., Linux, Netscape) make money from these products? How can other companies compete with these fast-rising s..

  Create a program for playing tic tac toe

A draw (no winner) occurs when all the cells on the grid have been filled with tokens and neither player has achieved a win.

  Find and prove by induction a formula for s-1

What is the inductive hypothesis? What is the inductive step? Find and prove by induction a formula for S-1

  Write code to demonstrate your function on various inputs

A function (addBinary binaryList) that takes a list of binary numbers and returns their decimal sum. (addBinary '(1101 111 10 101)) returns 27.

  Developing a pseudocode and the flowchart

Develop a flowchart and write down the psuedocode for the following: A program which prints every number from 1 through 10. A program which prints every number from 1 through 10 along with its square and cube.

  Develop the natural shape functions for a linear element

Using the natural coordinate system shown in the accompanying figure. Develop the natural shape functions for a linear element.

  Which employees does paula roberts supervise

Write an SQL Statement to add a new teller to Headquarters and an IT Manager to headquarters. MAke up the information for the other columns.

  Explain how enumeration can be considered first contact

Describe scanning and enumeration. Discuss the pros and cons of 2 scanning and enumeration tools. Explain how enumeration can be considered first contact.

  What is the average mips rate of the program

If the clock period is 0.2 its, calculate the average CPI for the program. What is the average MIPS rate of the program?

  Define word protocol and explain how it is used in computing

Define the word protocol and explain how it is used in computing. Distinguish between machine language and assembly language.

  Write a function in matlab that takes as input the number n

Write a function in Matlab that takes as input the number n, a sparse matrix given as r, c, v, m, an n-component column vector b, and a tolerance tol.

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