Programalama > C++


Ort. 0
Puan ver:
#include<iostream>
#include<string>
#include<fstream>
#include<iomanip>

using namespace std;





class ClientData {

 public:

 
 ClientData( int n= 0, string f= "", string l= "", double b= 0.0 )
 {
	 setFirstName(f);
	 setLastName(l);
	 setAccountNumber(n);
	 setBalance(b);
 }

 
 void setAccountNumber( int a )
 {
	 accountNumber=a;
 }
 int getAccountNumber() const
 {
	 return accountNumber;
 }

 
 void setLastName( string a )
 {
	 const char *temp=a.data();
	 int length=strlen(temp);
	 strncpy(lastName, temp ,length);

	 lastName[length]='\0';

 }
 string getLastName() const
 {
	 return lastName;
 }
 
 void setFirstName( string firstNameString)
 {
	
 
	 const char *firstNameValue = firstNameString.data();
 
	 int length = strlen( firstNameValue );
 
	 length = ( length < 10 ? length : 9 );
 
	 strncpy( firstName, firstNameValue, length );

 
 
	 firstName[ length ] = '\0';
 }
 string getFirstName() const
 {
	 return firstName;
 }

 
 void setBalance( double a )
 {

	 balance=a;
 }
 double getBalance() const
 {
	 return balance;
 }

 private:
 int accountNumber;
 char lastName[ 15 ];
 char firstName[ 10 ];
 double balance;

 };


int main()
 {
 
	int accountNumber;
 
	char lastName[ 15 ];
 
	char firstName[ 10 ];
 
	double balance;

	 ofstream outCredit( "credit.dat", ios::binary );

 
 
 
 if ( !outCredit )
 {
 
	 cerr << "File could not be opened." << endl;
 
	 exit( 1 );

 } 

 
 cout << "Enter account number " << "(1 to 100, 0 to end input)\n? ";


 
 ClientData client;
 
 cin >> accountNumber;
 client.setAccountNumber( accountNumber );

 while ( client.getAccountNumber() > 0 && client.getAccountNumber() <= 100 ) 
 {


 
	cout << "Enter lastname, firstname, balance\n? ";
 
	cin >> lastName;
 
	cin >> firstName;
 
	cin >> balance;


 
	client.setLastName( lastName );
 
	client.setFirstName( firstName );
 
	client.setBalance( balance );

 
 
	outCredit.seekp( ( client.getAccountNumber() - 1 ) *sizeof( ClientData ) );


 
	outCredit.write(reinterpret_cast< const char * >( &client ),sizeof( ClientData ) );
 
 
	cout << "Enter account number\n? ";
 
	cin >> accountNumber;
 
	client.setAccountNumber( accountNumber );

	ifstream ferid("credit.dat",ios::in);

	ferid.seekg(0,ios::beg);

	ferid.read(reinterpret_cast< char *>(&client),sizeof(ClientData));

	cout<<client.getFirstName()<<endl;

} 

 return 0;

 }

ferid mövsümov
faridmovsumov@gmail.com


Yorumlar                 Yorum Yaz
Bu hazır kod'a ilk yorumu siz yapın!
KATEGORİLER
ASP - 240
ASP.NET - 24
C# - 75
C++ - 174
CGI - 8
DELPHI - 247
FLASH - 49
HTML - 536
PASCAL - 246
PERL - 11
PHP - 160
WML - 9
XML - 2
Copyright © 2002 - 2024 Hazır Kod - Tüm Hakları Saklıdır.
Siteden yararlanırken gizlilik ilkelerini okumanızı tavsiye ederiz.
hazirkod.com bir İSOBİL projesidir.