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, 23.06.2019 14:30
Open this link after reading about ana's situation. complete each sentence using the drop-downs. ana would need a minimum of ato work as a translator. according to job outlook information, the number of jobs for translators willin the future.
Answers: 3
question
Computers and Technology, 23.06.2019 16:00
Does read theory have answers keys ?
Answers: 1
question
Computers and Technology, 23.06.2019 17:00
Companies that implement and apply an information system effectively can create
Answers: 1
question
Computers and Technology, 24.06.2019 01:00
What shows the web address of the page that is currently displayed in the workspace? status window toolbar location bar internet box
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, 06.05.2021 07:50
Questions on the website: 13722361