Question

C++ Write a program with the following elements: in main() -opens the 2 files provided for...

C++

Write a program with the following elements:

in main()

-opens the 2 files provided for input (Lab_HW9_2Merge1.txt and Lab_HW9_2Merge2.txt)

-calls a global function to determine how many lines are in each file

-creates 2 arrays of the proper size

-calls a global function to read the file and populate the array (call this function twice, once for each file/array)

-calls a global function to write out the 'merged' results of the 2 arrays

*if there are multiple entries for a person, these should be merged and should appear as a single entry in the resulting file

*resulting file should be named 'merged_output.txt'

program should check to see if a name is already present in one file or another. If the name is present in both files display the name once in the merged file and add the numbers.

Example:

1st File:

Carlos 7

Tina 3

2nd File:

Lena 2

Carlos 3

Merged File:

Carlos 10

Tina 3

Lena 2

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

#include<fstream> #include<iostream> #include<string> using namespace std; int lines (ifstream a) int c=0; while(!a.eof() c+=fa[i]=agel[i] //outfile<<agel[i]<<endl; for(i=0;i<f2;i++) infile2>>name2[i]; infile2>>age2[i]; for(int j=0; j<fl ; j++) { if(

Add a comment
Know the answer?
Add Answer to:
C++ Write a program with the following elements: in main() -opens the 2 files provided for...
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
  • write program in C language. To get more practice working with files, you will write several...

    write program in C language. To get more practice working with files, you will write several functions that involve operations on files. In particular, implement the following functions 1. Write a function that, given a file path/name as a string opens the file and returns its entire contents as a single string. Any endline characters should be preserved char *getFileContents (const char filePath); 2. Write a function that, given a file path/name as a string opens the file and returns...

  • C++: Make sure to identify codes with comments and no other programming other than C++ (please...

    C++: Make sure to identify codes with comments and no other programming other than C++ (please make it simple as possible) DON'T COPY CODES FROM OTHER ANSWERS Create a program that:           - in main                    - opens the file provided for input                    - calls a function to determine how many lines are in the file                    - creates an array of the proper size                    - calls a function to read the file and populate the array                   ...

  • Kindly solve this using C PROGRAMMING ONLY. 4. Write a program marks.c which consists of a...

    Kindly solve this using C PROGRAMMING ONLY. 4. Write a program marks.c which consists of a main function and three other functions called. readmarks , changemarks (, and writemarks() The program begins by calling the function readmarks () to read the input file marksin. txt which consists of a series of lines containing a student ID number (an integer) and a numeric mark (a float). Once the ID numbers and marks have been read into arrays (by readmarks () the...

  • JAVA Write a program that prompts the user to enter a file name, then opens the...

    JAVA Write a program that prompts the user to enter a file name, then opens the file in text mode and reads it. The input files are assumed to be in CSV format. The input files contain a list of integers on each line separated by commas. The program should read each line, sort the numbers and print the comma separated list of integers on the console. Each sorted list of integers from the same line should be printed together...

  • Write a C program as follows: Single source code file Calls a function with an arbitrary...

    Write a C program as follows: Single source code file Calls a function with an arbitrary name (i.e. you name it) that accepts two arrays of the same size The function should add each element in the arrays together and place the values in a third array Each array element, each array address, and the sum are printed to the screen in tabulated format with headersI also would like to request that LOTS of comments be included, as I need...

  • Write a complete JAVA program to do the following program. The main program calls a method...

    Write a complete JAVA program to do the following program. The main program calls a method to read in (from an input file) a set of people's three-digit ID numbers and their donations to a charity (hint: use parallel arrays)Then the main program calls a method to sort the ID numbers into numerical order, being sure to carry along the corresponding donations. The main program then calls a method to print the sorted 1ists in tabular form, giving both ID...

  • write a code on .C file Problem Write a C program to implement a banking application...

    write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...

  • please write me this program in C language Review UW files from the Internet can contain...

    please write me this program in C language Review UW files from the Internet can contain viruses. Unless you need to edit, it's safer to stay in Protected View View View - Word Terme MOHAMMED MUNTHER MOH Enable Editing Task # 3: Consider two integer arrays x and y of same size n with values: Xo, X1, X3,..., Xe1 and yo, yi, ya..... Yn-1 Write a function merge that receives array x and y and their size. It then returns...

  • c++ program8. Array/File Functions Write a function named arrayToFile. The function should accept three arguments:...

    c++ program8. Array/File Functions Write a function named arrayToFile. The function should accept three arguments: the name of a file, a pointer to an int array, and the size of the array. The function should open the specified file in binary mode, write the contents of the array to the file, and then close the file. Write another function named fileToArray. This function should accept three argu- ments: the name of a file, a pointer to an int array, and the size...

  • This assignment uses functions, files, and strings. Enough flexibility is provided for you to apply your...

    This assignment uses functions, files, and strings. Enough flexibility is provided for you to apply your knowledge of basic C++ programing to develop your solution. Develop a functional flowchart and then write a C++ program to solve the following problem. 1. Create a text file named file1.txt and write your brand of car (like Honda, Toyota, etc) in the file. You will be reading the name of the file from the keyboard as a string, using the string class. Your...

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