online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
// Leer un archivo de acceso aleatorio de forma secuencial. #include <iostream> #include <iomanip> #include <fstream> #include <cstdlib> #include "ClientData.h" // definicion de la clase ClientData using namespace std; void outputLine(ostream &, const ClientData &); // prototipo int main(){ ifstream inCredit("credit.dat", ios::in | ios::binary); // Salir del programa si ifstream no puede abrir el archivo if (!inCredit){ cerr << "No se pudo abrir el archivo." << endl; exit(1); } // end if cout << left << setw(10) << "Cuenta" << setw(16) << "Apellido" << setw(11) << "Nombre" << left << setw(10) << right << "Saldo" << endl; ClientData client; // Crear el registro // Leer el primer registro desde el archivo inCredit.read(reinterpret_cast<char *>(&client), sizeof(ClientData)); // Leer todos los registros del archivo while( inCredit && !inCredit.eof() ){ // mostrar el registro if(client.getAccountNumber() != 0) outputLine(cout, client); // leer el siguiente registro del archivo inCredit.read(reinterpret_cast<char *>(&client), sizeof(ClientData)); } // end while } // end main // mostrar un solo registro void outputLine( ostream &output, const ClientData &record ){ output << left << setw( 10 ) << record.getAccountNumber() << setw( 16 ) << record.getLastName() << setw( 11 ) << record.getFirstName() << setw( 10 ) << setprecision( 2 ) << right << fixed << showpoint << record.getBalance() << endl; } // fin de la funcion outputLine
#ifndef CLIENTDATA_H #define CLIENTDATA_H #include <string> using namespace std; class ClientData{ public: // constructor predeterminado de ClientData ClientData( int accountNumberValue =0, string lastNameValue="", string firstNameValue="", double balanceValue =0.0){ setAccountNumber( accountNumberValue ); setLastName( lastNameValue ); setFirstName( firstNameValue ); setBalance( balanceValue ); } // fin del constructor ClientData // Obtener el valor del numero de cuenta int getAccountNumber() const{ return accountNumber; } // fin de la funcion getAccountNumber // Establecer el valor de account-number void setAccountNumber( int accountNumberValue ){ accountNumber = accountNumberValue; } // fin de la funcion setAccountNumber // Obtener el valor de last-name string getLastName() const{ return lastName; } // fin de la funcion getLastName // Establecer el valor de last-name void setLastName( string lastNameString ){ // copiar como máximo 15 caracteres de la cadena a lastName int length = lastNameString.size(); length = ( length < 15 ? length : 14 ); lastNameString.copy( lastName, length ); lastName[ length ] = '\0'; // añadir carácter nulo a lastName } // fin de la funcion setLastName // Obtener el valor de first-name string getFirstName() const{ return firstName; } // fin de la funcion getFirstName // Establecer el valor de first-name void setFirstName( string firstNameString ){ // copiar como máximo 10 caracteres de la cadena a firstName int length = firstNameString.size(); length = ( length < 10 ? length : 9 ); firstNameString.copy( firstName, length ); firstName[ length ] = '\0'; // añadir carácter nulo a firstName } // fin de la funcion setFirstName // Obtener el valor de balance double getBalance() const{ return balance; } // fin de la funcion getBalance // Establecer el valor de balance void setBalance( double balanceValue ){ balance = balanceValue; } //fin de la funcion setBalance private: int accountNumber; char lastName[ 15 ]; char firstName[ 10 ]; double balance; }; // fin de la clase ClientData #endif
GonzalesJose�@ PerezesJuan33333G�@ SanchezPedro33333K�@ZMartinezCarlos�b@_LopezzMaria�g@

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue