Dear,
/**
*This program takes two files jokes.txt and punch.txt and uses two funtions
*and read the jokes.txt and prints and read punch.txt to end of the file
*and trace back and display only the last line
*/
//Header files
#include<iostream>
#include<fstream>
using namespace std;
//funtion Protypes
void jokeFile(fstream &);
void punchFile(fstream &);
//Main funtion starts
int main()
{
//create a two file streams
fstream fin1,fin2;
//open jokes.txt in read mode
fin1.open("jokes.txt",ios::in);
if(!fin1)
{
cout<<"File not found "<
system("pause");
exit(1);
}
while(!fin1.eof())
{
//Passing the file stream to funtion
jokeFile(fin1);
}
//close the file
fin1.close();
fin2.open("punch.txt",ios::in);
while(!fin2.eof())
{
//Passing the file stream to funtion
punchFile(fin2);
}
//close the file
fin2.close();
//To pause the output
system("pause");
return 0;
}
//End of main
//jokeFile futnion definition with file stream address
void jokeFile(fstream &file)
{
cout<<"Joke File Data"<
cout<<"-------------------------------------------------"<<
while(!file.eof())
{
char line[20];
file.getline(line,21,'n');
cout<<
}
}
//punchFile futnion definition with file stream address
void punchFile(fstream &file)
{
//Variable declaration
int i=3;
char ch;
char line[30];
//Move to end
file.seekg(0L,ios::end);
//back 3 positions left
file.seekg(-3L,ios::end);
//Get character
ch=file.get();
cout<<"Punch File Data"<
cout<<"---------Last Line of Punch File ----------"<<
//Until until new line arrived
while(ch!='n')
{
file.seekg(-i,ios::end);
ch=file.get();
i++;
}
file.getline(line,i);
cout<<<
}
punch.txt file
output
Note:I have taken my own joke file and punch files.
Hope this would helpful to you..
I need to write a C++ program using DEV C++ that reads and prints a joke and its punch line from...
nothing happens when I replace the skeleton code. the program runs but it does not give me the desired results. All the question marks must be removed and filled in with the appropriate code.// Function prototypesvoid displayAllLines(ifstream &infile);void displayLastLine(ifstream &infile);int main(){// Arrays for file nameschar fileName1[SIZE];char fileName2[SIZE];// File stream objectsifstream jokeFile;ifstream punchlineFile;// Explain the program to the user.cout << "This program will print a joke "<< "and its punch line.\n\n";// Get the joke file name.cout << "Enter the name of...
1. Please provide code based on Chapter 12 only from the text. Also include output to console picture after the program is compiled. 2. Text is Tony Gaddis 9th edition C++. Chapter 12, page 714, Problem 5 'Line Numbers' 3. Please use 'forChapt12.txt' file for the problem. The text is pasted below after description of the problem. 5. LINE NUMBERS (page 714) Write a program that asks the user for the name of the file. The program should display the...
Write a C++ program that reads text from a file and encrypts the file by adding 6 to the ASCII value of each character. See section 5.11 in Starting out with C++ for information on reading and writing to text files. Your program should: 1. Read the provided plain.txt file one line at a time. Because this file has spaces, use getline (see section 3.8). 2. Change each character of the string by adding 6 to it. 3. Write the...
C++ please Write a program that reads the following sentences from a file: I am Sam Sam I am That Sam I am That Sam I am I do not like that Sam I am Do you like green eggs and ham I do not like them But I do like spam! You will first have to create the text file containing the input, separate from your program. Your program should produce two output files: (i) (ii) one with the...
Lab #10 C++ Write a C++ program that reads text from a file and encrypts the file by adding an encryption factor (EF) to the ASCII value of each character. The encryption factor is 1 for the first line and increases by 1 for each line up to 4 and then starts over at 1. So, for the 4 th line the EF is 4, for the 5th line it is 1, for the 10th line it is 2. In...
I/O program for C Write a program in direct1.c which reads from standard input a line and then outputs that line immediately to standard output. it should read the first line only ! Then, write another program called direct2.c which reads from standard input every line until end of input and outputs them to standard output. Everything that goes in should come out exactly as it was. Compile both programs and run them on the input files given below The...
In c programming, I need to write a program that reverses each of the lines in a file. The program accepts two command line arguments: The first one is the name of the input file The second is the name of the output file If the user didn't give two filenames, display an error message and exit. The program reads in each line of the input file and writes each line in reverse to the output file. Note, the lines...
I need to write a C++ program that reads two integers from a data filed called "integers.dat" The first integer should be low and the other one high. The program should loop through all integers between the low and high values and include the low and high integers and then display Display the integers in the file Displays the number of integers divisible by 5 OR 6, but not both. Displays the sum of the integers from condition 2 as...
Q4) Write a C program named "hw3q4.c” that takes three string inputs from the command line arguments that represent file names. The first and second files contain four sorted integer numbers that represent set elements. The main process creates a child process that shares the three files. The child process determines the intersection set of two sets and saves the line: "Child process PID: xxxx Intersection of (x, x, x, x) and (y, y, y, y) (z, z, z, z)"...
//I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which manipulates text from an input file using the string library. Your program will accept command line arguments for the input and output file names as well as a list of blacklisted words. There are two major features in this programming: 1. Given an input file with text and a list of words, find and replace every use of these blacklisted words with the string...