⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 accountinformation.cpp

📁 C++大学简明教程,解压就行没有密码。希望对大家有用
💻 CPP
字号:
// Exercise 15.13: AccountInformation.cpp
// This application displays bank account information.
#include <iostream> // required to perform C++ stream I/O
#include <iomanip> // required for parameterized stream manipulators

// include definition of class Client from Client.h
#include "Client.h"

using namespace std; // for accessing C++ Standard Library members

const int ARRAY_SIZE = 8; // stores size of array used for Clients

// function prototypes
void initializeAccountRecords( Client [] );
void displayInformation( int, Client [] );

int main()
{
   int response = 0; // store the user's response

   // initialize accountRecords and make it the same
   // length as the variables to be stored in it
   Client accountRecords[ ARRAY_SIZE ];

   initializeAccountRecords( accountRecords );

   // display floating-point values as currency
   cout << fixed << setprecision( 2 );

   // repeat while user does not choose to exit
   while ( response != -1 )
   {
      // prompt the user for and input an account number
      cout << "\nEnter account number (-1 to exit ): ";
      cin >> response; // get account number

      displayInformation( response, accountRecords );
   } // end while

   cout << endl; // insert newline for readability

   return 0; // indicate that program ended successfully

} // end function main

// initialize Client data
void initializeAccountRecords( Client accountRecords[] )
{
   // variables hold data to be stored in accountRecords
   string firstName[] = { "John", "Sarah", "Jack", "Adam", "Diane",
      "David", "Kristin", "Jennifer" };
   string lastName[] = { "Blue", "White", "Red", "Brown", "Yellow",
      "Black", "Green", "Orange" };
   int accountNumber[] = { 1234652, 1234666, 1234678, 1234681,
      1234690, 1234770, 1234787, 1234887 }; 
   double balance[] = { 1000.78, 2056.24, 978.65, 990.00,  432.75,
      780.78, 4590.63, 7910.11 };

   // store account information variables in accountRecords
   for ( int i = 0; i < ARRAY_SIZE; i++ )
   {
      accountRecords[ i ] = Client( firstName[ i ],
         lastName[ i ], accountNumber[ i ], balance[ i ]  );
   }

} // end function initializeAccountRecords

// display correct information
void displayInformation( int accountNumber, Client accountRecords[] )
{
   // find the account record
   for ( int i = 0; i < ARRAY_SIZE; i++ )
   {      
      // if the account number matches
      if ( accountRecords[ i ].getAccount() == accountNumber )
      {
         // display the account information
         cout << "\nFirst name: " 
            << accountRecords[ i ].getFirstName() << endl;
         cout << "Last name: " 
            << accountRecords[ i ].getLastName() << endl;
         cout << "Account balance: $"
            << accountRecords[ i ].getBalance() << endl;
      } // end if

   } // end for

} // end function displayInformation


/**************************************************************************
* (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *
* Pearson Education, Inc. All Rights Reserved.                           **
* DISCLAIMER: The authors and publisher of this book have used their     *
* best efforts in preparing the book. These efforts include the          *
* development, research, and testing of the theories and programs        *
* to determine their effectiveness. The authors and publisher make       *
* no warranty of any kind, expressed or implied, with regard to these    *
* programs or to the documentation contained in these books. The authors *
* and publisher shall not be liable in any event for incidental or       *
* consequential damages in connection with, or arising out of, the       *
* furnishing, performance, or use of these programs.                     *
**************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -