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 03:10
Write a program that begins by reading in a series of positive integers on a single line of input and then computes and prints the product of those integers. integers are accepted and multiplied until the user enters an integer less than 1. this final number is not part of the product. then, the program prints the product. if the first entered number is negative or 0, the program must print “bad input.” and terminate immediately. next, the program determines and prints the prime factorization of the product, listing the factors in increasing order. if a prime number is not a factor of the product, then it must not appear in the factorization. sample runs are given below. note that if the power of a prime is 1, then that 1 must appear in t
Answers: 3
question
Computers and Technology, 22.06.2019 10:40
Nims is applicable to all stakeholders with incident related responsibilities. true or false
Answers: 1
question
Computers and Technology, 22.06.2019 19:30
When creating a presentation in libre office impress, where does the editing of slides take place? a. the slides panel b. the center panel c. the tasks panel, under the masters pages tab d. the tasks panel, under the layouts tab
Answers: 3
question
Computers and Technology, 23.06.2019 18:00
Ramona enjoys her job because she is able to kids in an after school program. the work value ramona feels strongest about is a. leadership b. risk c. independence d. work with people select the best answer from the choices provided a b c d
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
Geography, 17.01.2020 06:31
question
Mathematics, 17.01.2020 06:31
Questions on the website: 13722361