Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++. I am trying to execute the program challenge below, but I am getting error messages. I have my text files in the same folder

C++.

I am trying to execute the program challenge below, but I am getting error messages. I have my text files in the same folder as my .cpp file, but I cannot get the program to execute.

image text in transcribed

This is what the output should look like.

image text in transcribed

Here are the contents of the .txt docs

Joke:

Two men who work together in a factory were talking. "I know how to get some time off," said one. "How are you going to do that?" asked the other. "Watch," he said, and climbed a ladder to the ceiling. The foreman asked what he was doing up there, and the man replied. "I'm a lightbulb." "I think you need some time off," the foreman said, and the first man walked out of the factory. After a moment, the second man followed him. "Where do you think you're going?" the foreman shouted.

Punchline:

asfasdfasdfasdfsdf asdfasdfsadfsadfsadf asdfsadfsdfsdf "I can't work in the dark," he said.

Here is my current code:

#include #include using namespace std;

void jokeFile(fstream&); void punchFile(fstream&);

int main()

{ fstream fin1, fin2; Open two files jokes.txtand punch.txt in read mode.If files not found it generates exception. fin1.open("jokes.txt", ios::in); fin2.open("punch.txt", ios::in); Make a call to function jokeFile repeatedly until end of file is reached. while (!fin1.eof())

{ jokeFile(fin1); }

while (!fin2.eof())

{ punchFile(fin2); }

Call to close method closes two files fin1.close(); fin2.close(); system("pause");

return 0;

}

void jokeFile(fstream& file)

{

while (!file.eof())

{ char line[20]; file.getline(line, 21, ' '); cout

}

void punchFile(fstream& file)

{

int i = 3; char ch; char line[30]; file.seekg(0L, ios::end); file.seekg(-3L, ios::end); ch = file.get(); while (ch != ' ')

{

file.seekg(-i, ios::end); ch = file.get(); i++;

}

file.getline(line, i); cout 3. Punch Line 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. CAUsers\davyn\Documents\courses_troy\_2013\C++\Homework\student_work\Debug\week4_sa. This program will print a joke and its punch line. Enter the nane of the file holding the joke (joke.txt): joke.txt Enter the nane of the file holding the punch iine (punchiine.txt): punchline.txt Two nen who work together in a factory were talking. "I know how to get some time off," said one. "How are you going to do that?" asked the other. "Watch," he said, and climbed a ladder to the ceiling. The foreman asked what he was doing up there, and the man replied. "I'm a lightbulb. "I think you need sone time off," the forenan said, and the first nan walked out of the factory. After a moment, the second man followed him. "Where do you think you're going?" the foreman shouted. "I Press any key to continue work in the dark," he said

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

3rd Edition

0071107010, 978-0071107013

More Books

Students also viewed these Databases questions