subject
Computers and Technology, 29.07.2020 01:01 indya2

For this assignment, you will create 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." You can pick the joke and the punchline, but please make sure the joke is not inappropriate or offensive in nature. 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. You must create all files for this program. Be sure to include comments throughout your code where appropriate. Make sure that your comments thoroughly explain the stream input/output and what is happening in your program. 1 //Charles Blackwell CIS 221 M4
2 #include
3 #include
4 #include
5
6 using namespace std;
7
8 void printfirstfile(ifstream &);
9void printsecondfile(ifstream &);
10
11 int main() {
12 ifstream joke;
13 ifstream punchline;
14
15// print the joke
16 joke. open("joke. txt", ios::in);
17 if (!joke) {
18 cout << "Error opening the joke. " << endl;
19 return 0;
20 }
21 cout << " Charles Joke " << endl;
22 cout << "" << endl;
23 printfirstfile(joke);
24
25 punchline. open("punchline. txt", ios::in);
26 if (!punchline) {
27 cout << "Error opening the punchline. " << endl;
28 return 0;
29 }
30 cout << " Charles punchline " << endl;
31 cout << "" << endl;
32 printsecondfile(punchline);
33 return 0;
34
35 }
36 void printfirstfile(ifstream& file) {
37
38
39 char ch;
40 file. get(ch);
41
42 while (file) {
cout << ch;
file. get(ch);
}
}
void printsecondfile(ifstream& file) {
char ch;
file. seekg(-1L, ios::end);
file. get(ch);
while (ch != '\n') {
file. seekg(-2L, ios::cur);
file. get(ch);
}
file. get(ch);
while (!file. eof()) {
cout << ch;
file. get(ch);
}
}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 23:30
Define a function printfeetinchshort, with int parameters numfeet and numinches, that prints using ' and " shorthand. ex: printfeetinchshort(5, 8) prints: 5' 8"
Answers: 1
question
Computers and Technology, 23.06.2019 06:40
What are the three uses of a screw?
Answers: 2
question
Computers and Technology, 23.06.2019 18:40
Johnson enterprises uses a computer to handle its sales invoices. lately, business has been so good that it takes an extra 3 hours per night, plus every third saturday, to keep up with the volume of sales invoices. management is considering updating its computer with a faster model that would eliminate all of the overtime processing.
Answers: 2
question
Computers and Technology, 23.06.2019 20:30
What are some settings you can control when formatting columns?
Answers: 1
You know the right answer?
For this assignment, you will create a program that reads and prints a joke and its punch line from...
Questions
question
Mathematics, 16.03.2020 20:23
question
History, 16.03.2020 20:23
Questions on the website: 13722363