Fandom

Scratchpad

PLE:Unidad6Ejercicio10

216,184pages on
this wiki
Add New Page
Discuss this page0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

/*
Programa:         Ficheros10.cpp
Descripción:      Fusiona dos archivos ordenados.
*/
#include <iostream>
#include <fstream>
using namespace std;

int main() 
{
	ifstream f1, f2;
	ofstream fs;
	int n1, n2;
	
	f1.open("numero1.txt");
	f2.open("numero2.txt");
	fs.open("numeros.txt");
	
	if(f1.is_open() && f2.is_open() && fs.is_open())
	{
        f1 >> n1;
        f2 >> n2;
        while(!f1.eof() || !f2.eof())
        {
            if(f1.eof()) {
                cout << "n1 = EOF" << "\tn2 = " << n2 << endl;
                cout << "fs <- " << n2 << endl;
                fs << n2 << '\t';
                f2 >> n2;
            } else if(f2.eof()) {
                cout << "n1 = " << n1 << "\tn2 = EOF" << endl;
                cout << "fs <- " << n1 << endl;                
                fs << n1 << '\t';
                f1 >> n1;
            } else {
                if(n1 < n2) {
                    cout << "n1 = " << n1 << "\tn2 = " << n2 << endl;
                    cout << "fs <- " << n1 << endl;
                    fs << n1 << '\t';
                    f1 >> n1;
                } else {
                    cout << "n1 = " << n1 << "\tn2 = " << n2 << endl;
                    cout << "fs <- " << n2 << endl;                    
                    fs << n2 << '\t';
                    f2 >> n2;
                }
            }
        }        
        f1.close();
        f2.close();
        fs.close();                
    } else
        cout << "ERROR de apertura en ficheros " << endl;

    system("PAUSE");
    return EXIT_SUCCESS;    
}

Also on Fandom

Random wikia