Question

Please don't use a void fuction and this is a c++ question. Thanks

Write a program that reads two input files whose l

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Programm #include <iostream> #include <string> #include <fstream> using namespace stai int main ) string line_1,line 2; ifstr

myfile1.close )://close file 1 myfile2.close )//close file 2 else cout << Unable to open files or files may not exist; cout

Copyable code:

#include <iostream>

#include <string>

#include <fstream>

using namespace std;

int main () {

string line_1,line_2;

ifstream myfile1("file1.txt");//load the input file 1

ifstream myfile2("file2.txt");//load the second input file

ofstream myfile3("outputfile.txt");//output file

if (myfile1.is_open()&&myfile2.is_open()) //checking for the existence of files.

{

while ( getline (myfile1,line1)&&getline(myfile2,line2)) //get the lines from each files

{

if(line1.compare(line2)<0) //comparing for alphabetical order

{

myfile3 << line1 << '\n'; //copy the files in order

myfile3 << line2 << '\n';

}

else

{

myfile3 << line2 << '\n';

myfile3 << line1 << '\n';

}

}

//checking whether the files still have extra lines or not

if(!myfile1.eof())//check upto the last line of file

{

myfile3 << line1 << '\n';

while ( getline (myfile1,line1))//loop for reading the file 1.

{

myfile3 << line1 << '\n';

}

}

if(!myfile2.eof()) //loop for reading the file 2.

{

myfile3 << line2 << '\n';

while ( getline (myfile2,line2))//get lines from both the files.

{

myfile3 << line2 << '\n';//append into the output file.

}

}

myfile1.close();//close file 1

myfile2.close();//close file 2

}

else cout << "Unable to open files or files may not exist";

cout<<"Done";

return 0;

}

//output file content will be:

Add a comment
Know the answer?
Add Answer to:
Please don't use a void fuction and this is a c++ question. Thanks Write a program...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Question Write a program that will calculate a student's year marks for all his subjects.

    Write a program that will calculate a student's year marks for all his subjects. The program must read the subject code, the assignment marks for two assignments and the percentage that each assignment contributes towards the year mark, for each subject that the student is registered for.Create an input file called assignments.dat that contains the following information for a specific student:The first field in each line represents the subject code, followed by the percentage that assignment 1 contributes towards the...

  • C Program In this assignment you'll write a program that encrypts the alphabetic letters in a...

    C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...

  • Objective: Use input/output files, strings, and command line arguments. Write a program that processes a text...

    Objective: Use input/output files, strings, and command line arguments. Write a program that processes a text file by removing all blank lines (including lines that only contain white spaces), all spaces/tabs before the beginning of the line, and all spaces/tabs at the end of the line. The file must be saved under a different name with all the lines numbered and a single blank line added at the end of the file. For example, if the input file is given...

  • Write a c++ program in that file to perform a “Search and Replace All” operation. This...

    Write a c++ program in that file to perform a “Search and Replace All” operation. This operation consists of performing a case-sensitive search for all occurrences of an arbitrary sequence of characters within a file and substituting another arbitrary sequence in place of them. Please note: One of the biggest problems some students have with this exercise occurs simply because they don’t read the command line information in the course document titled “Using the Compiler’s IDE”. Your program: 1. must...

  • //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which...

    //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...

  • in Java and also follow rubric please 4. Write a complete program to do the following:...

    in Java and also follow rubric please 4. Write a complete program to do the following: Using an input and output files, write a program that will read 20 numbers from an input file called InFile. Sum all even numbers and multiply all odd numbers. Print the numbers read from the input file to an output file called OutFile. Also print the sum of the even numbers and the product of the odd numbers to the output file. Rubric: •...

  • c++ question, i put the txt attachment picture for this question... please include comments on calculations...

    c++ question, i put the txt attachment picture for this question... please include comments on calculations and varibles Description In this program, you will write a program to emulate a vending machine (somewhat). In this version of the program, you will use a struct type defined below struct snackType string name; string code; double price; int remaining; Where name contains the snack's name, code contains the 2 digit code for the item, price holds the item's price, and remaining holds...

  • Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The progra...

    Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...

  • C++ ONLY The question is - The US Census Bureau gathers population information and aggregates it...

    C++ ONLY The question is - The US Census Bureau gathers population information and aggregates it at the city, county and state level. A research project on population distribution in the Southeast US has acquired a data file from the Census Bureau that contains the populations of each county in Mississippi (MS) and Florida (FL). For this research project write a program that calculates the average county population for these two states. Each line in the Census Bureau data file...

  • Write a C program to compute average grades for a course. The course records are in...

    Write a C program to compute average grades for a course. The course records are in a single file and are organized according to the following format: Each line contains a student’s first name, then one space, then the student’s last name, then one space, then some number of quiz scores that, if they exist, are separated by one space. Each student will have zero to ten scores, and each score is an integer not greater than 100. Your program...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT