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

  Discuss the impact the internet

How do you think the future changes of the Internet will impact the professional development of IT professionals?

  Use the penn treebank tags to tag each word given below

Many years later, as he faced the firing squad, Colonel Aureliano Buendía was to remember that distant afternoon when his father took him to discover ice.

  Why has functional programming never become dominant

Imperative programming was the dominant paradigm from the dawn of computing until about 1990. Why has functional or logic programming never become dominant?

  The employee and the weekly pay amount

make a non-GUI based Java application that calculates weekly pay for an employee. The application should display text that requests the user input the name of the employee, the hourly rate, and the number of hours worked for that week.

  What is the probability that someone who tests positive

There is an excellent test for the disease; 99% of people with the disease test positive and only 0.01% who do not have the disease test positive.

  Make sure that the procedure can return the result

Write a PL/SQL procedure that will compute XY+1. Make sure that the procedure can return the result of the computation .

  Pros and cons of chen and crow''s feet notations

What are the pros and cons of Chen and Crow's feet notations.

  Why do not the administrators just use random numbers

Why don't the administrators just use random numbers? Would these be the same for a proxy firewall? How would a NAC work with a firewall?

  Identify the computer operating systems

Identify the computer operating systems and networking systems used in the company. Explain the pros and cons of IPv6 over the use of IPv4.

  How you would find the area of atriangle defined

Write C++ code or a mathematical derivation that shows how you would find the area of atriangle defined by the vertices a, b, and c.

  What is a data bus

Give short answers to the following: (a.g] Why is an address decoder used in I/O interfaces?

  How many comparisons will insertion sort perform

How many comparisons will insertion sort perform when it is executing the pass that moves the element at index n-1 into position?

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