Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ PROGRAM (PLEASE AS SIMPLE AS POSSIBLE) write a void function that will merge

ID: 3559470 • Letter: C

Question

C++ PROGRAM (PLEASE AS SIMPLE AS POSSIBLE)

write a void function that will merge the contents of two text files containing chemical elements sorted by atomic number and will produce a sorted file by atomic number and produces a sorted file of elements. The funcion's parameters are references to the two input streams and the ouput stream. Each text file line contain for example: 11 Sodium Na 22.99 20 Calcium Ca 40.08 The function can assume that one file does not have two copies of the same element and that the binary output files should have this same property. When one of the input files is exhausted, do not forget to copy the remaining elements of the other input file to the result file. Please comment for each line to be able to understand.

Explanation / Answer

Structure typedef struct{ int atomic_number; char name[MAX]; char symbol[MAX]; double weight; }chemical_t; void merge(FILE *element_1, FILE *element_2, FILE *element){ chemical_t chemical; chemical_t chemical_1; chemical_t chemical_2; element = fopen("text_b.dat", "wb"); element_1 = fopen("text1.txt", "rb"); fscanf(element_1,"%d%s%s%lf",&chemical_1.atomic_nu mber, chemical_1.name, chemical_1.symbol, &chemical_1.weight); while(!feof(element_1)){ fwrite(&chemical, sizeof(chemical_t), 1, element); fscanf(element_1,"%d%s%s%lf",&chemical_1.atomic_nu mber, chemical_1.name, chemical_1.symbol, &chemical_1.weight); } fclose(element_1); element_2 = fopen("text2.txt", "rb"); fscanf(element_2,"%d%s%s%lf",&chemical_2.atomic_nu mber, chemical_2.name, chemical_2.symbol, &chemical_2.weight); while(!feof(element_2)){ fwrite(&chemical, sizeof(chemical_t), 1, element); fscanf(element_2,"%d%s%s%lf",&chemical_2.atomic_nu mber, chemical_2.name, chemical_2.symbol, &chemical_2.weight); fclose(element_2); fclose(element); }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote