All pastes #2510 Raw Edit

Anonymous

public cpp v1 · immutable
#2510 ·published 2004-12-01 02:34 UTC
rendered paste body
// Ryan Brown// Hw 7// Client Program#include <iostream>using std::cerr;using std::endl;using std::cout;using std::cin;using std::ios;#include <iomanip>using std::setw;#include <fstream>using std::ofstream;#include <cstdlib>#include "PersonData.h"  // ClientData class definition int main() {   int idNumber;   char lastName[15];   char firstName[15];   char age [4];   int i = 0;   ofstream outNameAge( "nameage.dat", ios::binary );   // exit program if ofstream cannot open file   if ( !outNameAge ) {      cerr << "File could not be opened." << endl;      exit( 1 );   } // end if   cout << "Enter account number "        << "(1 to 100, 0 to end input)\n? ";   // require user to specify account number   PersonData client;   cin >> idNumber;   client.setidNumber( idNumber );   // user enters information, which is copied into file   while ( client.getidNumber() > 0 && client.getidNumber() <= 100 ) {      // user enters last name, first name and age      cout << "Enter lastname, firstname, age\n? ";      cin >> setw( 15 ) >> lastName;      cin >> setw( 15 ) >> firstName;      cin >> setw( 4 ) >> age;      // set record lastName, firstName and balance values      client.setLastName( lastName );      client.setFirstName( firstName );      client.setAge( age );      // seek position in file of user-specified record      outNameAge.seekp( ( client.getidNumber() - 1 ) *          sizeof( PersonData ) );      // write user-specified information in file      outNameAge.write(          reinterpret_cast< const char * >( &client ),         sizeof( PersonData ) );      // enable user to specify another id number      i++;	  cout << "Enter id number\n? ";      cin >> idNumber;      client.setidNumber( idNumber );	  	  if (i > 3) {		  break;	  }   } // end while      return 0;} // end main