Lecture 7 Examples


image from book

Open table as spreadsheet

Program

Demonstrates

account.cpp

Demonstration of a C++ class which illustrates a function as a member.

account2.cpp

Demonstration of a C++ class which illustrates a function as a member.

asgnconv.cpp

Shows the use of a constructor with several defaults to demonstrate a copy constructor and type conversion constructor.

bank.h

Shows the definition of the class BankAccount that is with programs which require its objects and it shows the use of static class data members.

bank1.cpp

Shows an initializing member function and a member access function.

bank2.cpp

Shows how to initialize the objects with a constructor member function using the constructor's arguments..

bank3.cpp

Shows how to initialize the objects with a constructor by default.

bank4.cpp

Shows how to initialize the objects with constructor functions which are overloaded.

bank5.cpp

Show the use of a constructor function with a default value.

bank6.cpp

Shows ho a static data member can be shared by all objects.

bank7.cpp

Shows a data member can be an array.

bank9.cpp

Shows the use of class pointers and the arrow operator.

bank10.cpp

Shows the use of class pointers and pointers as data members.

bankaccount.cpp

transactions.txt (Data for the program)

Inputs data into an array of object of the class transactions and then displays the data on the screen.

bankacnt.cpp

Shows how to initialize class objects with a constructor function with default values in the signature.

bankactv.cpp

Shows how static class members can be used to keep track of information about the objects.

bnkacnts.cpp

Shows the use of friend functions to permit functions to get access to multiple class objects.

bnkacnts2.cpp

Shows that friend functions may be declared in private access section as well as public access section.

banktotl.cpp

Shows how class objects can be used as arguments of a member function.

bankttl2.cpp

Shows how class objects can be used as arguments and output of a member function.

bnkwhedr.cpp

Shows how the class definition can be included in a header like bank.h.

callcons.cpp

Shows a constructor may be called by using the assignment operator.

circles.cpp

Shows the use of the pointer this using struct and using classes.

clock.cpp

Shows an example of a class which simulates the movement of a clock.

consdesc.cpp

Shows how constructors and destructors are called in relationship to the calling into existence of main()

const.cpp

Shows the use of constant class objects and constant member functions.

copy.cpp

Shows the use of a copy constructor.

crclclss.cpp

Shows a class circle similar to a previous structure circle

date.cpp

Contains the definitions of the methods for the class Date which is defined in the header file date.h

date.h

Contains the definition of the class Date and the definition of the methods are in the file date.cpp

dateclas.cpp

Shows class with member functions defined inside of the class and therefore should expand inline.

defltcon.cpp

Shows a constructor with several default arguments.

futrpas2.cpp

Demonstrates the keyword operator with the increment operator ++() and the decrement operator --().

haim3.cpp

Demonstrates that the size of a class does not include the size of any static attributes.

newdate.cpp

Demonstrates the keyword operator with the increment operator ++() and the decrement operator --() with the ability to assign the new values to another day in the definition of the class date. In addition it demonstrates the use of the this pointer.

invclass.cpp

Shows the concept of nested classes.

invclass2.cpp

Shows the use of external header files with class definitions

invoice.cpp

Contains the definitions of the methods for the class Invoice which is defined in the header file invoice.h

invoice.h,

Contains the definition of the class Invoice and the definition of the methods are in file invoice.cpp.

invoice2.cpp

Shows functions where class objects are arguments of a non-member function and are output of a non-member function.

invoice3.cpp

Shows functions where class objects are arguments of a non-member function and are output of a non-member function. One of the functions is passing the object by reference.

invoice4.cpp

Shows functions where arrays of class objects are passed to a non-member function.

nlinclass.cpp

Shows the use of inline functions defined outside of the class definition.

prvtfnct.cpp

Shows how member functions can be in the private access section.

theAccount.h

Contains the definition of the class Account.

theAccount_h.cpp

Contains the member functions for the class Account whose definition is contained in the header file: theAccount.h. This file should be a source file in the project.

staticAccount.cpp

Demonstrates that a static attribute may be accessed by the class but not if it is declared in the private access section.

staticAccount2.cpp

Demonstrates the access of static attributes by the class name if it is declared in the public access section.

stactfnct.cpp

Shows a static member function.

this.cpp

Shows the use of the class pointer this.

The files for the book inventory program:

Design Phase:

  • Class design: bookInventory.gif

  • Structure chart: sc_doInventory.gif

  • Pseudo code: pc_doInventory.txt

Coding Phase:

  • bookInventory.cpp

  • bookInventory.h

  • theFunctions.h

  • doInventory.cpp

Files needed for the inventory example.

image from book

 //   program_id    account2.cpp //   author      Don Voils //   date_written  08/03/2006 // //   description   Demonstration of a C++ class //             which illustrates a function as a member. #include<iostream> #include<iomanip> using namespace std; #include "theAccount.h" void main() {   cout << fixed << setprecision(2);   Account myAccount;   float theAmount;   cout << "What was the balance of the account when it started? ";   cin >> theAmount;   myAccount.settheBalance(theAmount);   cout << "What is the amount of the deposit? ";   cin >> theAmount;   myAccount.doDeposit(theAmount);   cout << "What is the amount of the withdrawal? ";   cin >> theAmount;   myAccount.doWithdrawal(theAmount);   cout << "The current balance is $" << myAccount.gettheBalance();   cout << endl << endl;   char resp;   cout << endl << endl << "Continue? ";   cin >> resp;   cout << endl << endl; } //   program_id    account.cpp //   author      Don Voils //   date_written  08/03/2006 // //   description   Demonstration of a C++ class //             which illustrates a function as a member. // // #include<iostream> #include<iomanip> using namespace std; class Account {    private:       float theBalance;    public:      void settheBalance(float);      float gettheBalance();      void doDeposit(float);      void doWithdrawal(float); }; void Account::settheBalance(float theAmount) {   theBalance = theAmount; } float Account::gettheBalance() {       return theBalance; } void Account::doDeposit(float theAmount) {   theBalance += theAmount; } void Account::doWithdrawal(float theAmount) {   theBalance -= theAmount; } void main() {   cout << fixed << setprecision(2);   Account myAccount;   float theAmount;   cout << "What was the balance of the account when it started? ";   cin >> theAmount;   myAccount.settheBalance(theAmount);   cout << "What is the amount of the deposit? ";   cin >> theAmount;   myAccount.doDeposit(theAmount);   cout << "What is the amount of the withdrawal? ";   cin >> theAmount;   myAccount.doWithdrawal(theAmount);   cout << "The current balance is $" << myAccount.gettheBalance();   cout << endl << endl;   char resp;   cout << endl << endl << "Continue? ";   cin >> resp;   cout << endl << endl; } // program_id      asgnconv.cpp // author        don voils // date written   10/8/2006 // // program description   This program shows the use of //               a constructor with several default //               to demonstrate a copy constructor //               and type conversion constructor. // #include<iostream> using namespace std; class test {    private:       int element1,          element2,          element3,          element4;    public:       test(int e1=1 , int e2=2, int e3=3, int e4=4)       {          element1=e1;          element2=e2;          element3=e3;          element4=e4;       }       test(test &a_test)       {    element1=a_test.element1;           element2=a_test.element2;           element3=a_test.element3;           element4=a_test.element4;       }       ~test(){ }       void show_object(){cout << " e1 = "<< element1                    << " e2 = "<< element2                    << " e3 = "<< element3                    << " e4 = "<< element4;} }; void main(void) {    test test0;    cout << endl << endl << "Showing Test0 ";    test0.show_object();    test test_conversion=5;    cout << endl << endl << "Showing type conversion constructor ";    test_conversion.show_object();    test test_copy=test0;    cout << endl << endl << "Showing copy constructor ";    test_copy.show_object();    cout << endl << endl; } //   program_id         bank1.cpp //   author           don voils  //   date written       9/23/2006 // //   program description This program simulates a bank //                 account using the class bank. //                 It initializes the objects with //                 an initilizing function. // #include<iostream> using namespace std; class BankAccount {      private:           float amount;      public:           void startAccount(float start_amt)           {                amount = start_amt;           }           void depositSlip(float deposit)           {                amount += deposit;           }           void withdrawalSlip(float checkAmount)           {                amount -= checkAmount;           }           float showBalance(void)           {               return amount;           } }; void main(void) {      BankAccount myAccount;      cout << "I started my account with $500.00" << endl << endl;      myAccount.startAccount(500);      cout << "I deposited $2,000.00 in my account" << endl << endl;      myAccount.depositSlip(2000.00);      cout << "I wrote checks for $700.00 against my account." << endl <<endl;      myAccount.withdrawalSlip(700.00);      cout << "My account balance is $" << myAccount.showBalance();      char resp;      cout << endl << endl << "Continue? ";      cin >> resp;      cout << endl << endl; } //   program_id    bank2.cpp //   author      don voils //   date written 9/23/2006 // //   program description   This program simulates a bank //                 account using the class bank. //                 It initializes the objects with //                 a constructor function. // #include<iostream> using namespace std; class BankAccount {  private:      float amount;  public:      BankAccount(float start_amt)      {          amount = start_amt;      }      void depositSlip(float deposit)      {           amount += deposit;      }      void withdrawalSlip(float check_amount)      {           amount -= check_amount;      }      float showBalance(void)      {         return amount;      } }; void main(void) {      cout << "I started my account with $500.00" << endl << endl;      BankAccount MyAccount(500);      cout << "I deposited $2,000.00 in my account" << endl << endl;      MyAccount.depositSlip(2000.00);      cout << "I wrote checks for $700.00 against my account." << endl <<endl;      MyAccount.withdrawalSlip(700.00);      cout << "My account balance is $"         << MyAccount.showBalance();      char resp;      cout << endl << endl << "Continue? ";      cin >> resp;      cout << endl << endl; } //   program_id    bank3.cpp //   author      don voils //   date written 9/23/2006 // //   program description   This program simulates a bank //                 account using the class bank. //                 It initializes the objects with //                 a constructor function. // #include<iostream> using namespace std; class BankAccount {  private:      float amount;  public:      BankAccount()      {          amount = 0;      }      void depositSlip(float deposit)      {           amount += deposit;      }      void withdrawalSlip(float check_amount)      {           amount -= check_amount;      }      float showBalance()      {         return amount;      } }; void main() {      cout << "I started my account at the bank" << endl << endl;      BankAccount MyAccount;      cout << "I deposited $2,000.00 in my account" << endl << endl;      MyAccount.depositSlip(2000.00);      cout << "I wrote checks for $700.00 against my account." << endl <<endl;      MyAccount.withdrawalSlip(700.00);      cout << "My account balance is $" << MyAccount.showBalance();      char resp;      cout << endl << endl << "Conitnue? ";      cin >> resp;      cout << endl << endl; } //   program_id    bank4.cpp //   author      don voils //   date written 9/23/2006 // //   program description   This program simulates a bank //                 account using the class bank_account. //                 It initializes the objects with //                 two constructor function which are //                 overloaded. // #include<iostream> using namespace std; class BankAccount {      private:           float amount;      public:           BankAccount()           {                amount = 0;           }           BankAccount(float starting_amount)           {                amount = starting_amount;           }           void depositSlip(float deposit)           {                amount += deposit;           }           void withdrawalSlip(float check_amount)           {                amount -= check_amount;           }           float showBalance(void)           {              return amount;           } }; void main() {      cout << "I started my checking account at the bank" << endl << endl;      BankAccount CheckingAccount;      cout << "I deposited $2,000.00 in my checking account" << endl << endl;      CheckingAccount.depositSlip(2000.00);      cout << "I wrote checks for $700.00 against my account." << endl <<endl;      CheckingAccount.withdrawalSlip(700.00);      cout << "My account balance is $"         << CheckingAccount.showBalance() << endl << endl;      cout << "I started my savings account at the bank with $5,000" << endl << endl;      BankAccount SavingsAccount(5000);      cout << "I desposited $3,000.00 in my savings account" << endl << endl;      SavingsAccount.depositSlip(3000.00);      cout << "I withdrew $1,700.00 from my savings account" << endl << endl;      SavingsAccount.withdrawalSlip(1700.00);      cout << "My savings balance is $"         << SavingsAccount.showBalance() << endl << endl;      char resp;      cout << endl << endl << "Continue? ";      cin >> resp;      cout << endl << endl; } //   program_id    bank5.cpp //   author      don voils //   date written 9/23/2006 // //   program description   This program simulates a bank //                 account using the class bank. //                 It initializes the objects with //                 a constructor function with a //                 default value. // #include<iostream> using namespace std; class BankAccount {       private:            float amount;       public:            BankAccount(float startingAmount=0)            {                amount = startingAmount;            }            void depositSlip(float deposit)            {                 amount += deposit;            }            void withdrawalSlip(float check_amount)            {                 amount -= check_amount;            }            float showBalance()            {               return amount;            } }; void main() {      cout << "I started my checking account at the bank" << endl << endl;      BankAccount checkingAccount;      cout << "I deposited $2,000.00 in my checking account" << endl << endl;      checkingAccount.depositSlip(2000.00);      cout << "I wrote checks for $700.00 against my account." << endl <<endl;      checkingAccount.withdrawalSlip(700.00);      cout << "My checking account balance is $" << checkingAccount.showBalance() << endl << endl;      cout << "I started my savings account at the bank with $5,000" << endl << endl;      BankAccount savingsAccount(5000);      cout << "I desposited $3,000.00 in my savings account" << endl << endl;      savingsAccount.depositSlip(3000.00);      cout << "I withdrew $1,700.00 from my savings account" << endl << endl;      savingsAccount.withdrawalSlip(1700.00);      cout << "My savings balance is $" << savingsAccount.showBalance() << endl << endl; } // program_id      bank6.cpp // author        don voils // date written   9/23/2006 // // program description This program simulates a bank //             account using the class //             BankAccount. The class has a //             static member number_accounts //             which is shared by all objects //             and it is used to keep track of //             the number of new accounts the //             customer has opened. // #include<iostream> using namespace std; class BankAccount {    private:       float    amount;       static int numberAccounts;    public:       BankAccount(void)       {         amount = 0;         ++numberAccounts;       }       BankAccount(float startingAmount)       {         amount = startingAmount;         ++numberAccounts;       }       void depositSlip(float deposit)       {          amount += deposit;       }       void withdrawalSlip(float checkAmount)       {          amount -= checkAmount;       }       float showBalance(void)       {          return amount;       }       int showNumberAccounts(void)       {           return numberAccounts;       } }; int BankAccount::numberAccounts = 0; void main() {    cout << "I started my checking account at the bank"       << endl << endl;    BankAccount checkingAccount;    cout << "I deposited $2,000.00 in my checking account"       << endl << endl;    checkingAccount.depositSlip(2000.00);    cout << "I wrote checks for $700.00 against my account."       << endl <<endl;    checkingAccount.withdrawalSlip(700.00);    cout << "My account balance is $"       << checkingAccount.showBalance() << endl << endl;    cout << "I started my savings account at the bank with "       << "$5,000" << endl << endl;    BankAccount savingsAccount(5000);    cout << "I desposited $3,000.00 in my savings account"       << endl << endl;    savingsAccount.depositSlip(3000.00);    cout << "I withdrew $1,700.00 from my savings account"       << endl << endl;    savingsAccount.withdrawalSlip(1700.00);    cout << "My savings balance is $"       << savingsAccount.showBalance() << endl << endl;    cout << "Thank you for opening the "       << checkingAccount.showNumberAccounts() << " accounts."       << endl << "We have "       << savingsAccount.showNumberAccounts()       << " gifts for you one for each account."       << endl << "You will be receiving them within "       << "the next few days. Again thank you for your "       << "business." << endl << endl; } // program_id      bank7.cpp // author        don voils // date written   9/23/2006 // //   program description This program simulates a bank //               account using the class //               BankAccount. Has a data member //               which is an array. #include<string> #include<conio.h> #include<iostream> using namespace std; class BankAccount {  private:      char   customer[30];      float  amount;  public:      BankAccount()      {         strcpy_s(customer,"");         amount = 0.00;      }      BankAccount(float new_amount)      {         strcpy_s(customer,"");         amount = new_amount;      }      BankAccount(char * newCustomer,float newAmount)      {         strcpy_s(customer,newCustomer);         amount = newAmount;      }      void setName(char * newCustomer)      {          strcpy_s(customer,newCustomer);      }      void depositSlip(float deposit)      {          amount += deposit;      }      void withdrawalSlip(float checkAmount)      {          amount -= checkAmount;      }      float showBalance()      {          return amount;      }      char* showCustomer()      {          return customer;      } }; void main() {          char customer[30];          float amount;          short index;          for(index=0;index<25;++index)               _putch('\n');          cout   << "What is the customer's name? ";          char resp = _getche();          for(index=0;index<29 && resp!='\r';++index)          {               customer[index] = resp;               resp = _getche();          }          customer[index] = '\0';          cout  << endl << endl << endl;          cout << "How much did " << customer              << " start the checking account with? ";          cin >> amount;          cout << endl << endl;          BankAccount checkingAccount(customer,amount);          cout << "How much did " << checkingAccount.showCustomer()              << " deposit in the checking account? ";          float deposit;          cin   >> deposit;          cout  << endl << endl;          checkingAccount.depositSlip(deposit);          cout  << "How much did " << checkingAccount.showCustomer()              << " write the check for? ";          float check;          cin   >> check;          cout  << endl <<endl;          checkingAccount.withdrawalSlip(check);          cout  << checkingAccount.showCustomer()              << " has a checking account balance of $"              << checkingAccount.showBalance() << endl << endl;          cout  << "How much did " << checkingAccount.showCustomer()              << " started a savings account at the bank with? ";          cin >> deposit;          cout << endl << endl;        BankAccount savingsAccount(deposit);        savingsAccount.setName(customer);        cout << "How much did " << savingsAccount.showCustomer()           << " deposited in the savings account? ";        cin >> amount;        cout << endl << endl;        savingsAccount.depositSlip(amount);        cout << "How much did " << savingsAccount.showCustomer()           << " withdrew the savings account? " ;        cin >> amount;        cout << endl << endl;        savingsAccount.withdrawalSlip(amount);        cout << savingsAccount.showCustomer()           << " has a savings balance of $"           << savingsAccount.showBalance() << endl << endl;        cout << "Thank you "<< checkingAccount.showCustomer()           << endl << "for opening a checking and a savings account at our bank."           << endl << "Your checking account balance is $"           << checkingAccount.showBalance()           << endl << "You have a savings balance of $"           << savingsAccount.showBalance()           << endl << endl << "Again thank you "           << savingsAccount.showCustomer()           << " for your business." << endl << endl; } // program_id      bank9.cpp // author        don voils // date written   9/23/2006 // //   program description This program simulates a bank //               account using the class //               BankAccount. It illustrates the use //               of class pointers. #include<string> #include<conio.h> #include<iostream> using namespace std; class BankAccount {       private:       char customer[30];       float amount;       public:       BankAccount()       {           strcpy_s(customer,"");           amount = 0.00;       }       BankAccount(char * newCustomer,float newAmount)       {           strcpy_s(customer,newCustomer);           amount = newAmount;       }       void getName(char * newCustomer)       {           strcpy_s(customer,newCustomer);       }       void depositSlip(float deposit)       {           amount += deposit;       }       void withdrawalSlip(float checkAmount)       {           amount -= checkAmount;       }       float showBalance()       {           return amount;       }       char* showCustomer()       {           return customer;       } }; void main() {      char customer[30];      float amount;      BankAccount* ptr = new BankAccount[2];      short index;      for(short index=0;index<25;++index)           _putch('\n');      cout << "What is the customer's name? ";      char resp = _getche();      for(index=0;(index<29 && resp!='\r');++index)      {           customer[index] = resp;           resp = _getche();      }      customer[index] ='\0';      cout  << endl << endl << endl;      ptr->getName(customer);      (ptr+1)->getName(customer);      cout  << "How much did the customer start the checking account with? ";      cin  >> amount;      cout  << endl << endl;      ptr->depositSlip(amount);      cout  << "How much did " << (ptr+1)->showCustomer()          << " start with in the savings account?";      cin  >> amount;      cout  << endl << endl;      (ptr+1)->depositSlip(amount);      cout << "Thank you "<< ptr->showCustomer()          << endl << "for opening a checking and a savings account at our bank."          << endl << "Your checking account balance is $"          << ptr->showBalance() << " accounts."          << endl << "You have a savings balance of $"          << (ptr+1)->showBalance()          << endl << endl << "Again thank you "          << (ptr+1)->showCustomer()          << " for your business." << endl << endl; //   don't forget to destroy the dynamically created memory //      delete[]ptr; } // program_id      bank10.cpp // author        don voils // date written   9/23/2006 // //   program description This program simulates a bank //               account using the class //               bank_account. It illustrates the use //               of class pointers and pointers as data //               members. #include<string> #include<conio.h> #include<iostream> using namespace std; class BankAccount {    private:        char* ptr;        float amount;    public:       BankAccount()       {          ptr = new char[30];          strcpy(ptr,"");          amount = 0.00;       }       BankAccount(char * newCustomer,float newAmount)       {          ptr = new char[30];          strcpy(ptr,newCustomer);          amount = newAmount;       }       ~BankAccount()       {          delete[]ptr;       }       void getName(char * newCustomer)       {           strcpy(ptr,newCustomer);       }       void depositSlip(float deposit)       {          amount += deposit;       }       void withdrawalSlip(float checkAmount)       {         amount -= checkAmount;       }       float showBalance()       {         return amount;       }       char* showCustomer()       {           return ptr;       } }; void main() {      char customer[30];      float amount;      BankAccount* ptr = new BankAccount[2];      short index;      for(index=0;index<25;++index)           _putch('\n');      cout  << "What is the customer's name? ";      char resp = _getche();      for(index=0;(index<29 && resp!='\r');++index)      {           customer[index] = resp;           resp = _getche();      }      customer[index] ='\0';      cout << endl << endl << endl;      ptr->getName(customer);      (ptr+1)->getName(customer);      cout  << "How much did " << ptr->showCustomer()<< " start the checking account with? ";      cin  >> amount;      cout  << endl << endl;      ptr->depositSlip(amount);      cout  << "How much did " << (ptr+1)->showCustomer()           << " start with in the savings account? ";      cin   >> amount;      cout   << endl << endl;      (ptr+1)->depositSlip(amount);      cout  << "Thank you "<< ptr->showCustomer()          << endl << "for opening a checking and a savings account at our bank."          << endl << "Your checking account balance is $"          << ptr->showBalance() << " accounts."          << endl << "You have a savings balance of $"          << (ptr+1)->showBalance()          << endl << endl << "Again thank you "          << (ptr+1)->showCustomer()          << " for your business." << endl << endl; //   don't forget to destroy the dynamically created memory //      delete [] ptr; } // program_id       bank.h // author         don voils // date written    10/15/2006 // // program description    This header contains the definition of the //                class bank_account. It is to be used with //                programs which require its objects. // class BankAccount {    private:     float     amount;     static int numberAccounts;     static int numberDeposits;     static int numberWithdrawals;    public:       BankAccount(float startingAmount=0)       {         ++numberAccounts;         amount = startingAmount;       }       void depositSlip(float deposit)       {          ++numberDeposits;          amount += deposit;       }       void withdrawalSlip(float checkAmount)       {          ++numberWithdrawals;          amount -= checkAmount;       }       float showBalance()       {          return amount;       }       int showAccounts()       {          return numberAccounts;       }       int showDeposits()       {          return numberDeposits;       }       int showWithdrawals()       {          return numberWithdrawals;       } }; int BankAccount::numberAccounts=0; int BankAccount::numberDeposits=0; int BankAccount::numberWithdrawals=0; // program_id     bankaccount.cpp // written_by    don voils // date_writtten  11/11/2006 // description:   This program inputs data into an array of object of the class //           transactions and then displays the data on the screen. // #include<iostream> #include<fstream> #include<iomanip> using namespace std; class Transactions { private:      char type;      double amount; public:      void setType(char theType)      {           type = theType;      }      void setAmount(double theAmount)      {           amount = theAmount;      }      char getType()      {           return type;      }      double getAmount()      {           return amount;      } }; void main() {      short numberTransactions = 0;      char theType;      double theAmount;      double theBalance;      Transactions transactionAmount[100];      ifstream inFile("transactions.txt");      if(!inFile)      {         cout << "File did not open" << endl;         exit(1);      }      inFile >> theType;      while(inFile)      {          inFile >> theAmount;          transactionAmount[numberTransactions].setType(theType);          transactionAmount[numberTransactions].setAmount(theAmount);          ++numberTransactions;          inFile >> theType;      }      inFile.close();      cout << fixed << setprecision(2);      for(short index=0;index < numberTransactions;++index)      {           if(transactionAmount[index].getType()=='b')           {                 theBalance = transactionAmount[index].getAmount();                 cout << left << "Starting Balance" << right;                 cout << setw(25) << transactionAmount[index].getAmount() << endl;           }           else                 if(transactionAmount[index].getType()=='d')                 {                       theBalance += transactionAmount[index].getAmount();                       cout << left << "Deposit" << right;                       cout << setw(27) << transactionAmount[index].getAmount() << endl;                 }                 else                 {                       theBalance -= transactionAmount[index].getAmount();                       cout << left << "Withdrawal" << right;                       cout << setw(15) << transactionAmount[index].getAmount() << endl;                 }      }      cout << right << setw(41)<< " ____________" << endl;      cout << left << "Ending Balance" << right;      cout << setw(27) << theBalance << endl;      cout << endl << endl; } //  program_id    bankacnt.cpp //  author      don voils //  date written 9/23/2006 // //  program description   This program simulates a bank //                account using the class bank. //                It initializes the objects with //                a constructor function with a //                default value. This example provides //                for user input. // #include<iostream> using namespace std; class BankAccount {      private:           float amount;      public:           BankAccount(float startingAmount=0)           {               amount = startingAmount;           }           void depositSlip(float deposit)           {               amount += deposit;           }           void withdrawalSlip(float checkAmount)           {               amount -= checkAmount;           }           float showBalance()           {              return amount;           } }; void main() {      char resp;      float amount;      cout << "Thank you for starting an account with our bank." << endl         << "How much will you open your account with? ";      cin >> amount;      BankAccount checkingAccount(amount);      do      {          cout << endl << endl << "How much was the deposit? ";          cin >> amount;          if (amount >=0)               checkingAccount.depositSlip(amount);          do          {               cout << endl << endl << "Another deposit? (Y/N) ";               cin >> resp;          }while((resp!='Y') && (resp!='N'));      }while(resp=='Y');      do      {          cout << endl << endl << "How much was the withdrawal? ";          cin >> amount;          if (amount >=0)               checkingAccount.withdrawalSlip(amount);          do          {               cout << endl << endl << "Another withdrawal? (Y/N) ";               cin >> resp;          }while((resp!='Y') && (resp!='N'));      }while(resp=='Y');      cout << endl << "Your checking account balance is $" << checkingAccount.showBalance() << endl << endl; } // program_id       bankactv.cpp // author         don voils // date written    9/23/2006 // // program description   This program simulates a bank //               account using the class bank. //               This example illustrates how //               static class members //               can be used to keep track //               of the number of deposits //               and withdrawals in all //               accounts both checking and //               savings. // #include<iostream> using namespace std; class BankAccount {    private:       float       amount;       static int   numberAccounts;       static int   numberDeposits;       static int   numberWithdrawals;    public:       BankAccount(float startingAmount=0)       {          ++numberAccounts;          amount = startingAmount;       }       void depositSlip(float deposit)       {          ++numberDeposits;          amount += deposit;       }       void withdrawalSlip(float checkAmount)       {          ++numberWithdrawals;          amount -= checkAmount;       }       float showBalance()       {          return amount;       }       int showAccounts()       {          return numberAccounts;       }       int showDeposits()       {          return numberDeposits;       }       int showWithdrawals()       {          return numberWithdrawals;       } }; int BankAccount::numberAccounts=0; int BankAccount::numberDeposits=0; int BankAccount::numberWithdrawals=0; void main() {    char resp;    float amount;    cout << "Thank you for starting a checking account with our"       << " bank." << endl << endl       << "How much will you open your checking account "       << "with? ";    cin >> amount;    BankAccount checkingAccount(amount);    do    {       cout << endl << endl << "How much was the deposit "         << "to your checking account? ";       cin >> amount;       if (amount >=0)           checkingAccount.depositSlip(amount);       do       {           cout << endl << endl << "Another deposit to your "             << "checking account? (Y/N) ";           cin >> resp;       }while((resp!='Y') && (resp!='N'));    }while(resp=='Y');    do    {      cout << endl << endl << "How much was the check? ";      cin >> amount;      if (amount >=0)          checkingAccount.withdrawalSlip(amount);      do      {          cout << endl << endl << "Another check? (Y/N) ";          cin >> resp;      }while((resp!='Y') && (resp!='N'));    }while(resp=='Y');    cout << endl << "Your checking account balance is $"       << checkingAccount.showBalance() << endl << endl;    cout << endl << endl << "Thank you for starting a savings "       << "account with our bank." << endl << endl       << "How much will you open your savings account "       << "with? ";    cin >> amount;    BankAccount savingsAccount(amount);    do    {      cout << endl << endl << "How much was the deposit to "         << "your savings account? ";      cin >> amount;      if (amount >=0)          savingsAccount.depositSlip(amount);      do      {          cout << endl << endl << "Another deposit to your "             << "savings account? (Y/N) ";          cin >> resp;      }while((resp!='Y') && (resp!='N'));    }while(resp=='Y');    do    {      cout << endl << endl << "How much was the withdrawal "         << "from your savings account? ";      cin >> amount;      if (amount >=0)          savingsAccount.withdrawalSlip(amount);      do      {          cout << endl << endl << "Another savings account "             << "withdrawal? (Y/N) ";          cin >> resp;       }while((resp!='Y') && (resp!='N'));    }while(resp=='Y');    cout << endl << "Your savings account balance is $"       << savingsAccount.showBalance() << endl << endl       << "You have had " << checkingAccount.showDeposits()       << " deposits this month from your " << endl       << checkingAccount.showAccounts()       << " accounts and "       << savingsAccount.showWithdrawals()       << " withdrawals." << endl << endl; } //   program_id    banktotl.cpp //   author      don voils //   date written 9/23/2006 // //   program description   This program simulates a bank //                 account using the class bank. //                 It initializes the objects with //                 a constructor function with a //                 default value. This example provides //                 for user input for a checking and //                 a savings account. At the end it //                 prints out the total amount on //                 deposit in both account. This example //                 illustrates class objects as arguments //                 of a member function. // #include<iostream> using namespace std; class BankAccount {      private:           float amount;      public:           BankAccount(float startingAmount=0)           {               amount = startingAmount;           }           void depositSlip(float deposit)           {               amount += deposit;           }           void withdrawalSlip(float checkAmount)           {               amount -= checkAmount;           }           float showBalance(void)           {              return amount;           }           void totalOfAccount(BankAccount c, BankAccount s)           {               amount = c.amount + s.amount;           } }; void main(void) {      char resp;      float amount;      BankAccount bothAccounts;      cout << "Thank you for starting a checking account with our bank." << endl << endl         << "How much will you open your checking account with? ";      cin >> amount;      BankAccount checkingAccount(amount);      do      {          cout << endl << endl << "How much was the deposit to your checking account? ";          cin >> amount;          if (amount >=0)               checkingAccount.depositSlip(amount);          do          {               cout << endl << endl << "Another deposit to your checking account? (Y/N) ";               cin >> resp;          }while((resp!='Y') && (resp!='N'));      }while(resp=='Y');      do      {          cout << endl << endl << "How much was the check? ";          cin >> amount;          if (amount >=0)               checkingAccount.withdrawalSlip(amount);          do          {               cout << endl << endl << "Another check? (Y/N) ";               cin >> resp;          }while((resp!='Y') && (resp!='N'));      }while(resp=='Y');      cout << endl << "Your checking account balance is $" << checkingAccount.showBalance()         << endl << endl;      cout << endl << endl << "Thank you for starting a savings account with our bank."         << endl << endl << "How much will you open your savings account with? ";      cin >> amount;      BankAccount savingsAccount(amount);      do      {          cout << endl << endl << "How much was the deposit to your savings account? ";          cin >> amount;          if (amount >=0)               savingsAccount.depositSlip(amount);         do         {              cout << endl << endl << "Another deposit to your savings account? (Y/N) ";              cin >> resp;         }while((resp!='Y') && (resp!='N'));     }while(resp=='Y');     do     {         cout << endl << endl << "How much was the withdrawal from your savings account? ";         cin >> amount;         if (amount >=0)              savingsAccount.withdrawalSlip(amount);         do         {              cout << endl << endl << "Another savings account withdrawal? (Y/N) ";              cin >> resp;         }while((resp!='Y') && (resp!='N'));     }while(resp=='Y');     cout << endl << "Your savings account balance is $"        << savingsAccount.showBalance() << endl << endl;     bothAccounts.totalOfAccount(checkingAccount,savingsAccount);     cout << endl << "Your total funds on deposit at our bank is $"         << bothAccounts.showBalance() << endl << endl; } //   program_id    bankttl2.cpp //   author      don voils //   date written 9/23/2006 // //   program description   This program simulates a bank //                 account using the class bank. //                 It initializes the objects with //                 a constructor function with a //                 default value. This example provides //                 for user input for a checking and //                 a savings account. At the end it //                 prints out the total amount on //                 deposit in both account. This example //                 illustrates class objects as arguments //                 and output of a member function. // #include<iostream> using namespace std; class BankAccount {      private:           float amount;      public:           BankAccount(float startingAmount=0)           {               amount = startingAmount;           }           void depositSlip(float deposit)           {               amount += deposit;           }           void withdrawalSlip(float checkAmount)           {               amount -= checkAmount;           }           float showBalance(void)           {              return amount;           }           BankAccount plus(BankAccount s)           {               BankAccount temp;               temp.amount = amount + s.amount;               return temp;           } }; void main(void) {      char resp;      float amount;      BankAccount bothAccounts;      cout << "Thank you for starting a checking account with our bank." << endl << endl         << "How much will you open your checking account with? ";      cin >> amount;      BankAccount checkingAccount(amount);      do      {          cout << endl << endl << "How much was the deposit to your checking account? ";          cin >> amount;          if (amount >=0)               checkingAccount.depositSlip(amount);          do          {               cout << endl << endl << "Another deposit to your checking account? (Y/N) ";               cin >> resp;          }while((resp!='Y') && (resp!='N'));      }while(resp=='Y');      do      {          cout << endl << endl << "How much was the check? ";          cin >> amount;          if (amount >=0)               checkingAccount.withdrawalSlip(amount);          do          {               cout << endl << endl << "Another check? (Y/N) ";               cin >> resp;          }while((resp!='Y') && (resp!='N'));      }while(resp=='Y');      cout << endl << "Your checking account balance is $" << checkingAccount.showBalance()         << endl << endl;      cout << endl << endl << "Thank you for starting a savings account with our bank."         << endl << endl << "How much will you open your savings account with? ";      cin >> amount;      BankAccount savingsAccount(amount);      do      {          cout << endl << endl << "How much was the deposit to your savings account? ";          cin >> amount;          if (amount >=0)               savingsAccount.depositSlip(amount);          do          {               cout << endl << endl << "Another deposit to your savings account? (Y/N) ";               cin >> resp;          }while((resp!='Y') && (resp!='N'));      }while(resp=='Y');      do      {          cout << endl << endl << "How much was the withdrawal from your savings account? ";          cin >> amount;          if (amount >=0)               savingsAccount.withdrawalSlip(amount);          do          {               cout << endl << endl << "Another savings account withdrawal? (Y/N) ";               cin >> resp;          }while((resp!='Y') && (resp!='N'));      }while(resp=='Y');      cout << endl << "Your savings account balance is $"         << savingsAccount.showBalance() << endl << endl;      bothAccounts = checkingAccount.plus(savingsAccount);      cout << endl << "Your total funds on deposit at our bank is $"         << bothAccounts.showBalance() << endl << endl; } // program_id         bnkacnts2.cpp // author           don voils // date written      10/26/2006 // //  program description This program simulates a bank //              account using the classes checking, //              savings and money. It illustrates the //              use of friend functions. // //              This program is the same as bnkacnts.cpp //              except the declaration of the friend function //              is in the private access section and this causes //              no problems. #include<string> #include<conio.h> #include<iostream> using namespace std; // If these classes are not declared here, then the // program will not compile because the friend function approved() // needs to know that these classes are defined elsewhere. // class Savings; class Money; class Checking {    private:        char  customer[30];        char  custId[10];        float amount;        bool friend approved(Checking c,Savings s, Money m);    public:    Checking()    {       strcpy_s(customer,"");       strcpy_s(custId,"01-");       amount = 0.00;    }    Checking(char * newCustomer,char *newId, float newAmount)    {       strcpy_s(customer,newCustomer);       strcpy_s(custId,"01-");       strcat_s(custId,newId);       amount = newAmount;    }    void getName(char * newCustomer)    {        strcpy_s(customer,newCustomer);    }    void getId(char *newId)    {        strcat_s(custId,newId);    }    void depositSlip(float deposit)    {        amount += deposit;    }    void withdrawalSlip(float checkAmount)    {        amount -= checkAmount;    }    float showBalance()    {        return amount;    }    char * showId()    {        return custId;    }    char* showCustomer()    {        return customer;    } }; class Savings {    private:        char  customer[30];        char  custId[10];        float amount;        bool friend approved(Checking c, Savings s, Money m);    public:       Savings()       {           strcpy_s(customer,"");           strcpy_s(custId,"02-");           amount = 1000.00;       }       Savings(char * newCustomer,char *newId, float newAmount)       {           strcpy_s(customer,newCustomer);           strcpy_s(custId,"02-");           strcat_s(custId,newId);           amount = newAmount;       }       void getName(char * newCustomer)       {           strcpy_s(customer,newCustomer);       }       void getId(char *newId)       {           strcat_s(custId,newId);       }       void depositSlip(float deposit)       {           amount += deposit;       }       void withdrawalSlip(float checkAmount)       {           amount -= checkAmount;       }       float showBalance()       {          return amount;       }       char * showId()       {           return custId;       }       char* showCustomer()       {           return customer;       } }; class Money {  private:      char  customer[30];      char  custId[10];      float amount;      bool friend approved(Checking c, Savings s, Money m);  public:      Money()      {         strcpy_s(customer,"");         strcpy_s(custId,"03-");         amount = 0.00;      }      Money(char * newCustomer,char *newId, float newAmount)      {         strcpy_s(customer,newCustomer);         strcpy_s(custId,"03-");         strcat_s(custId,newId);         amount = newAmount;      }      void getName(char * newCustomer)      {          strcpy_s(customer,newCustomer);      }      void getId(char *newId)      {          strcat_s(custId,newId);      }      void depositSlip(float deposit)      {          amount += deposit;      }      void withdrawalSlip(float checkAmount)      {          amount -= checkAmount;      }      float showBalance()      {          return amount;      }      char * showId()      {          return custId;      }      char* showCustomer()      {          return customer;      } }; bool approved(Checking c, Savings s, Money m) {      bool isApproved = false;      if((c.amount+s.amount+m.amount)>10000)            isApproved = true;      return isApproved; } void main() {      char customer[30];      char custId[7];      float amount;      short index;      for(index=0;index<25;++index)           _putch('\n');      cout << "What is the customer's name? ";      char resp = _getche();      for(index=0;(index<29 && resp!='\r');++index)      {           customer[index] = resp;           resp = _getche();      }      customer[index] ='\0';      cout << endl << endl << endl;      cout << "What is the customer's Id? ";      resp = _getche();      for(index=0;(index<6 && resp!='\r');++index)      {           custId[index] = resp;           resp = _getche();      }      custId[index] ='\0';      cout << endl << endl << endl;      cout << "How much did " << customer         << " start with in the checking account?";      cin >> amount;      cout << endl << endl;      Checking cAccount(customer,custId,amount);      cout << "How much did " << customer         << " start with in the savings account?";      cin >> amount;      cout << endl << endl;      Savings sAccount(customer,custId,amount);      cout << "How much did " << customer         << " start with in the money market account?";      cin >> amount;      cout << endl << endl;      Money mAccount(customer,custId,amount);      cout << "Thank you "<< cAccount.showCustomer()         << " for opening a checking,"         << endl << "a savings and a money account at our bank."         << endl << "Your checking account id is "<< cAccount.showId()         << endl << "and your checking balance is $"         << cAccount.showBalance()         << endl << endl << "Your savings account id is "<< sAccount.showId()         << endl << "and your savings balance is $"         << sAccount.showBalance()         << endl << endl << "Your money market account id is "<< mAccount.showId()         << endl << "and your money market balance is $"         << mAccount.showBalance();      if(approved(cAccount,sAccount,mAccount)==true)           cout << endl << endl              << "You have been approved for a free VISA account";      else           cout << endl << endl << "I am sorry but your balance does not entitle"              << endl << "you for a free VISA account";      cout << endl << endl << "Again thank you "         << mAccount.showCustomer()         << " for your business." << endl << endl; } // program_id        bnkacnts.cpp // author          don voils // date written      10/26/2006 // //   program description  This program simulates a bank //                account using the classes checking, //                savings and money. It illustrates the //                use of friend functions. // #include<string> #include<conio.h> #include<iostream> using namespace std; // If these classes are not declared here, then the // program will not compile because the friend function approved() // needs to know that these classes are defined elsewhere. // class Savings; class Money; class Checking {    private:       char  customer[30];       char  custId[10];       float amount;    public:       Checking()       {          strcpy_s(customer,"");          strcpy_s(custId,"01-");          amount = 0.00;       }       Checking(char * newCustomer,char *newId, float newAmount)       {          strcpy_s(customer,newCustomer);          strcpy_s(custId,"01-");          strcat_s(custId,newId);          amount = newAmount;       }       void getName(char * newCustomer)       {           strcpy_s(customer,newCustomer);       }       void getId(char *newId)       {           strcat_s(custId,newId);       }       void depositSlip(float deposit)       {           amount += deposit;       }       void withdrawalSlip(float checkAmount)       {           amount -= checkAmount;       }       float showBalance()       {           return amount;       }       char * showId()       {           return custId;       }       char* showCustomer()       {           return customer;       }       bool friend approved(Checking c, Savings s, Money m); }; class Savings {    private:       char  customer[30];       char  custId[10];       float amount;    public:       Savings()       {          strcpy_s(customer,"");          strcpy_s(custId,"02-");          amount = 1000.00;       }       Savings(char * newCustomer,char *newId, float newAmount)       {           strcpy_s(customer,newCustomer);           strcpy_s(custId,"02-");           strcat_s(custId,newId);           amount = newAmount;       }       void getName(char * newCustomer)       {           strcpy_s(customer,newCustomer);       }       void getId(char *newId)       {           strcat_s(custId,newId);       }       void depositSlip(float deposit)       {           amount += deposit;       }       void withdrawalSlip(float checkAmount)       {           amount -= checkAmount;       }       float showBalance()       {           return amount;       }       char * showId()       {           return custId;       }       char* showCustomer()       {           return customer;       }       bool friend approved(Checking c, Savings s, Money m); }; class Money {  private:      char  customer[30];      char  custId[10];      float amount;  public:      Money()      {         strcpy_s(customer,"");         strcpy_s(custId,"03-");         amount = 0.00;      }      Money(char * newCustomer,char *newId, float newAmount)      {         strcpy_s(customer,newCustomer);         strcpy_s(custId,"03-");         strcat_s(custId,newId);         amount = newAmount;      }      void getName(char * newCustomer)       {          strcpy_s(customer,newCustomer);       }       void getId(char *newId)       {           strcat_s(custId,newId);       }       void depositSlip(float deposit)       {           amount += deposit;       }       void withdrawalSlip(float checkAmount)       {           amount -= checkAmount;       }       float showBalance()       {           return amount;       }       char * showId()       {           return custId;       }       char* showCustomer()        {           return customer;        }       bool friend approved(Checking c, Savings s, Money m); }; bool approved(Checking c, Savings s, Money m) {      bool isApproved = false;      if((c.amount+s.amount+m.amount)>10000)            isApproved = true;      return isApproved; } void main() {      char customer[30];      char custId[7];      float amount;      short index;      for(index=0;index<25;++index)           _putch('\n');      cout << "What is the customer's name? ";      char resp = _getche();      for(index=0;(index<29 && resp!='\r');++index)      {           customer[index] = resp;           resp = _getche();      }      customer[index] ='\0';      cout << endl << endl << endl;      cout << "What is the customer's Id? ";      resp = _getche();      for(index=0;(index<6 && resp!='\r');++index)      {           custId[index] = resp;           resp = _getche();      }      custId[index] ='\0';      cout << endl << endl << endl;      cout << "How much did " << customer        << " start with in the checking account? ";      cin >> amount;      cout << endl << endl;      Checking cAccount(customer,custId,amount);      cout << "How much did " << customer        << " start with in the savings account? ";      cin >> amount;      cout << endl << endl;      Savings sAccount(customer,custId,amount);      cout << "How much did " << customer        << " start with in the money market account? ";      cin >> amount;      cout << endl << endl;      Money mAccount(customer,custId,amount);      cout << "Thank you "<< cAccount.showCustomer()        << " for opening a checking,"        << endl << "a savings and a money account at our bank."        << endl << "Your checking account id is "        << cAccount.showId()        << endl << "and your checking balance is $"        << cAccount.showBalance()        << endl << endl << "Your savings account id is "<< sAccount.showId()        << endl << "and your savings balance is $"        << sAccount.showBalance()        << endl << endl << "Your money market account id is "<< mAccount.showId()        << endl << "and your money market balance is $"        << mAccount.showBalance();      if(approved(cAccount,sAccount,mAccount)==true)           cout << endl << endl               << "You have been approved for a free VISA account";      else           cout << endl << endl << "I am sorry but your balance does not entitle"              << endl << "you for a free VISA account";      cout << endl << endl << "Again thank you "        << mAccount.showCustomer()        << " for your business." << endl << endl; } // program_id        bnkwhedr.cpp // author          don voils // date written     9/23/2006 // // program description    This program simulates a bank //                account using the class bank. //                This example takes the program //                BANDACTV.CPP and removes the //                definition of the class BankAccount. //                It then adds the class definition //                by including the header BANK.H. #define AND && #define OR || #include<iostream> using namespace std; #include"bank.h" void main(void) {    char resp;    float amount;    cout << "Thank you for starting a checking account with our"       << " bank." << endl << endl       << "How much will you open your checking account "       << "with? ";    cin >> amount;    BankAccount checkingAccount(amount);    do    {       cout << endl << endl << "How much was the deposit "       << "to your checking account? ";    cin >> amount;    if (amount >=0)        checkingAccount.depositSlip(amount);    do    {        cout << endl << endl << "Another deposit to your "           << "checking account? (Y/N) ";        cin >> resp;    }while((resp!='Y') AND (resp!='N')); }while(resp=='Y'); do {    cout << endl << endl << "How much was the check? ";    cin >> amount;    if (amount >=0)        checkingAccount.withdrawalSlip(amount);    do    {        cout << endl << endl << "Another check? (Y/N) ";        cin >> resp;    }while((resp!='Y') AND (resp!='N')); }while(resp=='Y'); cout << endl << "Your checking account balance is $"    << checkingAccount.showBalance() << endl << endl; cout << endl << endl << "Thank you for starting a savings "    << "account with our bank." << endl << endl    << "How much will you open your savings account "    << "with? "; cin >> amount; BankAccount savingsAccount(amount); do {   cout << endl << endl << "How much was the deposit to "      << "your savings account? ";   cin >> amount;   if (amount >=0)       savingsAccount.depositSlip(amount);   do   {    cout << endl << endl << "Another deposit to your "      << "savings account? (Y/N) ";    cin >> resp;   }while((resp!='Y') AND (resp!='N')); }while(resp=='Y'); do {    cout << endl << endl << "How much was the withdrawal "      << "from your savings account? ";    cin >> amount;    if (amount >=0)        savingsAccount.withdrawalSlip(amount);    do    {        cout << endl << endl << "Another savings account "           << "withdrawal? (Y/N) ";       cin >> resp;     }while((resp!='Y') AND (resp!='N')); }while(resp=='Y');   cout << endl << "Your savings account balance is $"     << savingsAccount.showBalance() << endl << endl     << "You have had " << checkingAccount.showDeposits()     << " deposits this month from your " << endl     << checkingAccount.showAccounts()     << " accounts and "     << savingsAccount.showWithdrawals()     << " withdrawals." << endl << endl; } // program_id    bookInventory.gif // written_by    don voils // date_written  5/5/2006 // description   This is the UML chart for the class: BookInventory. 

image from book

 // program_id    bookInventory.cpp // written_by    don voils // date_written  5/25/2006 // // description    This file contains the method definitions //           for the class bookInventory. // #include "bookInventory.h" // The following methods are initilizing and // access methods for each of the attributes // of the class bookInventory. // void BookInventory::setbookName(string theName) {      bookName = theName; } string BookInventory::getbookName() {      return bookName; } void BookInventory::setISBN(string theISBN) {      ISBN = theISBN; } string BookInventory::getISBN() {      return ISBN; } void BookInventory::setyearPublished(string theYear) {      yearPublished = theYear; } string BookInventory::getyearPublished() {      return yearPublished; } void BookInventory::setnumberOnHand(string theNumber) {      numberOnHand = theNumber; } string BookInventory::getnumberOnHand() {      return numberOnHand; } void BookInventory::setcostBook(string theCost) {      costBook = theCost; } string BookInventory::getcostBook() {      return costBook; } void BookInventory::setpriceBook(string thePrice) {      priceBook = thePrice; } string BookInventory::getpriceBook() {      return priceBook; } void BookInventory::setbookAuthors(int theNumber,string theName) {      bookAuthors[theNumber] = theName; } string BookInventory::getbookAuthors(int theNumber) {      return bookAuthors[theNumber]; } // program_id     bookInventory.h // written-by    Don Voils // date_written   5/25/2006 // // Description:   This header contains the definition //           of the class bookInventory. // #include<iostream> #include<string> using namespace std; #ifndef INVENTORY #define INVENTORY // Although some of the attributes would normally // be numeric rather than strings, string data // type was chosen because of the way C++ handles // file I/O. // class BookInventory {   private:     string bookName;     string ISBN;     string yearPublished;     string numberOnHand;     string costBook;     string priceBook;     string bookAuthors[4];   public:     void setbookName(string theName);     string getbookName();     void setISBN(string theISBN);     string getISBN();     void setyearPublished(string theYear);     string getyearPublished();     void setnumberOnHand(string theNumber);     string getnumberOnHand();     void setcostBook(string theCost);     string getcostBook();     void setpriceBook(string thePrice);     string getpriceBook();     void setbookAuthors(int theNumber,string theName);     string getbookAuthors(int theNumber); }; #endif // program_id        CALLCONS.CPP // author          don voils // date written     10/09/2006 // // program description    This program demonstrates that //               a constructor may be called //               directly. // #include<iostream> using namespace std; class Date {   private:      int month,          day,          year;   public:     Date(int m, int d, int y){month=m;day=d;year=y;}     int showMonth(){ return month;}     int showDay(){return day;}     int showYear(){return year;} }; void main() {    char dash;    int month,       day,       year;    cout << "What is the date? ";    cin >> month >> dash >> day >> dash >> year;    Date FirstDate(month,day,year);    Date SecondDate = Date(month,day+1,year);    cout << endl << endl << "Did you say the date was "       << FirstDate.showMonth() << "/"       << FirstDate.showDay() << "/"       << FirstDate.showYear();    cout << endl << endl << "or did you say the date was "       << SecondDate.showMonth() << "/"       << SecondDate.showDay() << "/"       << SecondDate.showYear() << endl;    char resp;    cout << endl << endl << "Continue? ";    cin >> resp;    cout << endl << endl; } // program_id    circles.cpp // author      Don Voils // date_written  10/26/2006 // // description  Demonstration of the this pointer. // const double PI = 3.14159; #include<iostream> using namespace std; struct Circle {     double radius;     double area()     {        return (radius * radius * PI);     }     double circumference()     {        return (2 * radius * PI);     } }; void getRadius(Circle *thisPtr, double input) {    thisPtr->radius = input; } class Acircle {    private:     double   radius;    public:     void getRadius(double input)     {        this->radius = input;     }     double area()     {        return (radius * radius * PI);     }     double circumference()     {        return (2 * radius * PI);     } }; void main() {    Circle *thisPtr = new Circle;    Acircle secondCircle;    double theInput;    cout << "What is the radius of the circle? ";    cin >> theInput;    getRadius(thisPtr, theInput);    secondCircle.getRadius(theInput);    cout << endl << endl << "The area of the first circle is "       << thisPtr->area();    cout << endl << endl << "The circumference of the first circle is "       << thisPtr->circumference();    cout << endl << endl << "The area of the first circle is "       << secondCircle.area();    cout << endl << endl << "The circumference of the first circle is "       << secondCircle.circumference()       << endl << endl;    delete thisPtr; } //    program_id     CLOCK.CPP //    author       don voils //    date written  9/15/2006 // //    program description    This program simulates //                   the movement of a clock. // #include<conio.h> #include<iostream> #include<string> using namespace std; char backspace; struct Block {      char spacer[2]; }spacerZero={"0"}, spacerBlank={""}; class Time {    private:       int hours,           minutes,           seconds;    public:       void startClock();       void tickClock();       void displayClock(); }; void main() {    unsigned long counter;    Time day1;    for(counter=1;counter<=250;++counter)       cout << endl;    cout << flush;    backspace = '\b';    for(counter=1;counter<=250;++counter)       cout << endl;    cout << flush;    day1.startClock();    for (counter=1;counter<=250;++counter)       cout << endl;    cout << flush;    // The function kbhit() returns false until a    // key on the keyboard is pressed.    //    while(!_kbhit())    {      day1.tickClock();      day1.displayClock();      for(counter=1;counter <= 450000000;++counter);    }    cout << endl << endl; } void Time::startClock() {    char mark;    cout << "Example: hh:mm:ss"<< endl << endl        << "Use a 24 hour clock" << endl << endl        << "What is the time in hours, minutes and seconds? ";    cin >> hours >> mark >> minutes >> mark >> seconds; } void Time::displayClock() {    int counter;    Block hoursZero,        minutesZero,        secondsZero;    if (hours<=9)        hoursZero=spacerZero;    else        hoursZero=spacerBlank;    if (minutes<=9)        minutesZero=spacerZero;    else        minutesZero=spacerBlank;    if (seconds<=9)        secondsZero=spacerZero;    else        secondsZero=spacerBlank;    for (counter=1;counter<=8;++counter)        _putch(backspace);    for (counter=1;counter<=8;++counter)        _putch(' ');    for (counter=1;counter<=8;++counter)        _putch(backspace);    cout << hoursZero.spacer << hours << ':'        << minutesZero.spacer        << minutes << ':' << secondsZero.spacer << seconds; } void Time::tickClock() {    ++seconds;    if (seconds >=60)    {        seconds -= 60;        ++minutes;    }    if (minutes >=60)    {        minutes -= 60;        ++hours;    }    if(hours >=24)    {       hours = 0;    } } // program_id       consdesc.cpp // author         don voils // date written    10/8/2006 // // program description    This program demonstrates how //                constructors and destructors are //                called in relationship to the //                calling into existence of main(). // // #include<iostream> using namespace std; class Date {    private:       int month,           day,           year;    public:       // The following constructor provides the data members       // with default values if none are provided when an       // object is defined in the program.       //       Date(int m=1,int d=1,int y=1994)       {         month=m; day=d; year=y;         cout<< "Initialized " << month << "/"            << day << "/" << year << endl << endl;       }       ~Date()       {         cout << "Destroying " << month << "/" << day             << "/" << year << endl << endl;       }       void showDate()       { cout << month << "/" << day             << "/" << year;       } }StartDate; // This defines the object outside of main() void main() {    cout << "The beginning of main()." << endl << endl;    Date InsideDate(7,4,1776);    cout << "The end of main()." << endl << endl;    char resp;    cout << endl << endl << "Continue? ";    cin >> resp;    cout << endl << endl; } // program_id    const.cpp // written_by    don voils // date_written   10/29/2006 // // program_description  This program demonstrates //            constant class objects and //            constant member functions. // #include<iostream> using namespace std; class Stuff {      private:           int number;      public:           Stuff(int aNumber)           {             number = aNumber;           }           ~Stuff(){}           //The constant method below does not compile           //because it is attempting to change           //the attribute number           // void changeConst(int aNumber)const           // {  number = aNumber;}           void changeIt(int aNumber)           {             number = aNumber;           }           int showNumber() const           {             return number;           } }; void main() {      int number1 = 20;      int number2 = 150;      Stuff stuff1(number1);      Stuff const stuff2(number2);      //The following will not compile because stuff2 is a contant      //object and the method change_it() is attempting to change      //the attribute.      //      //stuff2.changeIt(500);      cout << endl << endl << "The non-constant object accessing a "         << "constant method the value of number1 is " << stuff1.showNumber();      cout << endl << endl << "The constant object accessing a "         << "constant method the value of number2 is " << stuff2.showNumber();      cout << endl << endl; } // program_id         copy.cpp // written_by         don voils // date_written       10/29/2006 // // program_descripton     This program demonstrates //               the use of a copy constructor. // #include<iostream> using namespace std; class Stuff {      private:           int   number;      public:           Stuff() {}           Stuff(int aNumber)           {                number = aNumber;           }           Stuff(const Stuff &anObject)           {                number = anObject.number;           }           ~Stuff() {}           int showStuff()           {                 return number;           } }; void main() {      int aNumber = 10;      Stuff stuff1(aNumber);      cout << endl << endl << "stuff1 contains "         << stuff1.showStuff();      Stuff stuff2(stuff1);      cout << endl << endl << "stuff2 contains "         << stuff2.showStuff()         << endl << endl; } // program_id     crclclss.cpp // author       Don Voils // date_written  08/03/2006 // // description   Demonstration of a class // #include<iostream> using namespace std; const double PI = 3.14159; // Definition of a class class Circle {    // The private access section    private:       // This data member may only be accessed within the class       double   radius;    public:       // These member functions may be accessed any where an       // object of the class is defined.       void getRadius(double);       double showRadius();       double showArea();       double showCircumference(); }; void main() {    // Definition of an object to the class circle    Circle   theCircle;    double   theRadius;    cout << "What is the radius of the circle? ";    cin >> theRadius;    // Since the methods used below were declared in the public    // access section, it can be accessed anywhere the object    // is defined.    theCircle.getRadius(theRadius);    cout << endl << endl << "The radus is "        << theCircle.showRadius();    cout << endl << endl << "The area of the circle is "        << theCircle.showArea();    cout << endl << endl        << "The circumference of the circle is "        << theCircle.showCircumference();        char resp;        cout << endl << endl << "Continue? ";        cin >> resp;        cout << endl << endl; } // Notice the definitions outside of the class definition. // // Notice the scope resolution operator is required when // these functions are defined outside of the class so that // the compiler can determine to which object they belong. // // Notice that the data member radius is being accessed within // the methods. This is required because it was declared // in the private access section. // void Circle::getRadius(double r) {    radius = r; } double Circle::showRadius() {    return (radius); } double Circle::showArea() {    return (radius * radius * PI); } double Circle::showCircumference() {    return (2 * radius * PI); } // program_id     date.cpp // written_by    don voils // date_written   11/05/2006 // description    Contains the definitions of the methods of //            the class: date /// #include "date.h" void Date::setDate(int theMonth, int theDay, int theYear)     {dateMonth=theMonth; dateDay=theDay; dateYear=theYear;} int Date::showMonth()    {return dateMonth;} int Date::showDay()    {return dateDay;} int Date::showYear()    {return dateYear;} // program_id      date.h // written_by     don voils // date_written   11/03/2006 // description    Contains the definition of the //           class Date whose methods are //           in the file: date.cpp // #ifndef DATE #define DATE class Date {    private:       int dateMonth,          dateDay,          dateYear;    public:       void setDate(int, int, int);       int showMonth();       int showDay();       int showYear(); }; #endif // program_id     dateclas.cpp // author       Don Voils // date_written  08/04/2006 // // program description: The date class with member functions //             defined inside of the class. // #include<iostream> using namespace std; class Date {    private:       short month,           day,           year;    public:       void setDate(void)       {          char dash;          cout << "What is the date? (e.g. 8/31/2000) ";          cin >> month >> dash >> day >> dash >> year;          if(year < 1000)             if(year>10)                year += 1900;             else                year += 2000;       }       void showMonthName(void)       {          char monthName[][10] = {"","JANUARY", "FEBRUARY",             "MARCH", "APRIL", "MAY", "JUNE","JULY",             "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER",             "DECEMBER"};          cout << endl<< endl << "The date is "              << monthName[month]              << " " << day << ", " << year;       } }; void main(void) {      Date InvoiceDate;      InvoiceDate.setDate();      InvoiceDate.showMonthName();      char resp;      cout << endl << endl << "Continue? ";      cin >> resp;      cout << endl << endl; } // program_id      defltcon.cpp // author        don voils // date written   10/8/2006 // // program description   This program shows the use of //               a constructor with several default //               elements and the effect of //               initializing an object with //               various values supplied when //               defined. // #include<iostream> using namespace std; class Test {    private:       int element1,          element2,          element3,          element4;    public:       Test(int e1=1 , int e2=2, int e3=3, int e4=4)       {         element1=e1;         element2=e2;         element3=e3;         element4=e4;       }       ~Test(){ }       void showObject()       {       cout << " e1 = "<< element1          << " e2 = "<< element2          << " e3 = "<< element3          << " e4 = "<< element4;       } }; void main() {    Test test0;    cout << endl << endl << "Showing Test0 ";    test0.show_object();    Test test1(5);    cout << endl << endl << "Showing Test1 ";    test1.show_object();    Test test2(5,6);    cout << endl << endl << "Showing Test2 ";    test2.show_object();    Test test3(5,6,7);    cout << endl << endl << "Showing Test3 ";    test3.show_object();    Test test4(5,6,7,8);    cout << endl << endl << "Showing Test4 ";    test4.show_object();    cout << endl << endl; } // program_id    doInventory.cpp // written_by   don voils // date_written  5/25/2006 // // Description  This is the menu for a program that processes //        the inventory for Barnes and Nelson BookStores. // #include<iostream> using namespace std; // The following header contains the definition of the // class bookInventory. // #include "bookInventory.h" // The following header contains the functions that are // the modules for the program. // #include "theFunctions.h" void main() {      // Used to receive the input for the      // menu selection.      //      char index;      // Used to control the menu loop.      //      bool More = true;      // Used to define and control the      // array of inventory items.      //      const int numberItems = 500;      // The follwing array contains the inventory      // items that the program processes.      //      BookInventory inventory[numberItems];      // The following module loads the inventory from      // disk and places it into the array of inventory      // items. If there is no data in the array, then      // the array is filled with blank data.      //      loadInventory(inventory, numberItems);      do      {           clearScreen();           cout << "        Inventory Modification" << endl << endl << endl                << "   1.  Enter New Records" << endl << endl                << "   2.  Display by ISBN" << endl << endl                << "   3.  Edit Records" << endl << endl                << "   4.  Delete Records" << endl << endl                << "   5.  Exit" << endl << endl                << "        Which? ";           cin.get(index).get();           cout << endl << endl;      //   This is an example of late binding. The compiler does not specify      //   the location of the jump until the execution of the program.      //           switch(index)           {               case '1':                    // This option permits the entry of inventory                    // records into the inventory array.                    //                    enterNewRecords(inventory,numberItems);                    break;               case '2':                    // This option permits the display of an                    // inventory record given the ISBN of the book.                    //                    ISBNDisplay(inventory,numberItems);                    break;               case '3':                    // This option permits the editing of each                    // item of a specific book record given the                    // ISBN of the book.                    //                    editItems(inventory,numberItems);                    break;               case '4':                    // This option permits the deleting of an                    // item of a specific book record given the                    // ISBN of the book.                    //                    deleteItem(inventory,numberItems);                    break;               case '5':                    clearScreen();                    cout << "Data is being stored to file." << endl << endl;                    // This option terminates the program but                    // saves all of the data to a file prior                    // to ending.                    //                    saveInventory(inventory,numberItems);                    // Used to end the menu loop.                    //                    More = false;                    break;          }      } while(More);      clearScreen();      cout << "Data has been stored to file." << endl << endl; } // program_id       futrpas2.cpp // author         don voils // date written    10/15/2006 // program description     This program demonstrates the use of the //                   keyword operator with the increment operator //                   ++() and the decreament operator --() //                   with the ability to assign the new values //                   to another day in the definiion of the //                   class Date. // #include<iostream> using namespace std; class Date {       private:           long  month,               day,               year;       public:           void getDate();           void setDate(long m,long d,long y);           long lastDay(long m,long y);           long showDay();           long showMonth();           long showYear();           bool leapYear(long y);           Date operator ++();           Date operator --();           bool incorrectDate(long m,long d,long y); }; // MAIN PROGRAM // void main() {      Date  theDay,         nextDay,         aDay,         bDay;      cout << "What is the date today? ";      theDay.getDate();      cout << endl << endl << "If today is " << theDay.showMonth() << "/"          << (theDay.showDay()) << "/" << (theDay.showYear())          << ", then tomorrow will be ";      ++theDay;      cout << (theDay.showMonth()) << "/"          << (theDay.showDay()) << "/" << (theDay.showYear());      nextDay = ++theDay;      cout << endl << endl << "The day after that would be "          << (theDay.showMonth()) << "/" << theDay.showDay()          << "/" << (theDay.showYear()) << " or may be "          << (nextDay.showMonth()) << "/" << (nextDay.showDay())          << "/" << (nextDay.showYear());      cout << endl << endl << "What was the second day you wanted checked? ";      aDay.getDate();      cout << endl << endl << "If second day is " << (aDay.showMonth())          << "/" << (aDay.showDay()) << "/"          << (aDay.showYear()) << ", then the day before was ";      --aDay;      cout << aDay.showMonth() << "/"          << aDay.showDay() << "/" << (aDay.showYear());      bDay = --aDay;      cout << endl << endl << "The day before that would be "          << aDay.showMonth() << "/" << (aDay.showDay())          << "/" << (aDay.showYear()) << " or may be "          << (bDay.showMonth()) << "/" << (bDay.showDay())          << "/" << (bDay.showYear())          << endl << endl; } long Date::showDay() {   return day; } long Date::showMonth() {   return month; } long Date::showYear() {   return year; } void Date::getDate() {   char dash;   do   {     cin >> month >> dash >> day >> dash >> year;     if(year < 100)       if(year < 10)          year += 2000;       else          year += 1900;  }while(incorrectDate(month,day,year)); } void Date::setDate(long m,long d,long y) {   month = m;   day = d;   year = y; } Date Date::operator ++() {   Date temp;   if (day < lastDay(month,year))   {     day = day+1;   }   else   {     if(month<12)     {        month=month+1;        day = 1;     }     else     {        month=1;        day=1;        year=year+1;     }   }   temp.setDate(month,day,year);   return temp; } Date Date::operator --() {   Date temp;   if (day != 1)   {      day -= 1;   }   else   {     if(month !=1)     {        month -= 1;        day = lastDay(month,year);     }     else     {       month=12;       day = 31;       year -= 1;     }   }   temp.setDate(month,day,year);   return temp; } long Date::lastDay(long m,long y) {   int lastDay;   int daysInMonth[]={0,31,28,31,30,31,30,31,31,30,31,30,31};   if (m != 2)      lastDay=daysInMonth[int(m)];   else     if (leapYear(y))         lastDay =29;     else       lastDay=daysInMonth[int(m)];   return lastDay; } bool Date::leapYear(long y) {   bool leapTest;   if (((y%4==0) && (y%100!=0)) || (y%400==0))      leapTest=true;   else      leapTest=false;   return leapTest; } bool Date::incorrectDate(long m,long d,long y) {   bool notCorrect;   if ((m>=1) && (m<=12) && (d>=1) && (d<=lastDay(m,y)))       notCorrect = false;   else      notCorrect = true;   return notCorrect; } //  program_id   haim3.cpp //  written_by  Don Voils //  date_writte 4/6/2006 // //  Program Description: This program demonstrates that the size //              of a class does not include the size of //              any static attributes. // #include<iostream> #include<string> using namespace std; class It { private:      char theChar;      static int theStatic; public:     It()     {          theChar = 'A';     }     char showChar()     {          return theChar;     }     int showStatic()     {          return theStatic;     } }; int It::theStatic = 5; void main() {   It theObject;   cout << "The size of theObject = " << sizeof(theObject) << endl;   cout << "The size of the class it " << sizeof(It) << endl << endl; } //  program_id          INVCLASS2.CPP //  author            don voils //  date written       2/14/2006 // //  program description   This program demonstrates the //                concept of classes in header files //                by placing the class definition in //                one file and the method definition //                in another file. // #include<iomanip> #include<iostream> #include<string> using namespace std; #include "invoice.h" void main() {    char dash;    int theMonth,       theDay,       theYear;    float theAmount;    Invoice newInvoice;    cout << "What was the date? ";    cin >> theMonth >> dash >> theDay >> dash >> theYear;    newInvoice.setDate(theMonth, theDay, theYear);    cout << endl<< endl<< "What was the amount of the invoice? ";    cin >> theAmount;    newInvoice.setAmount(theAmount);    for(int index=1;index<=50;++index)       cout << endl;    cout << "Did you say that the invoice date was: "        << newInvoice.showInvoiceMonth() << "/"        << newInvoice.showInvoiceDay() << "/"        << newInvoice.showInvoiceYear() << endl << endl        << "Did you say that the invoice amount was : $"        << setiosflags(ios::fixed) << setprecision(2)        << setiosflags(ios::showpoint) << newInvoice.showInvoiceAmount()        << endl << endl; } //  program_id         INVCLASS.CPP //  author           don voils //  date written      10/09/2006 // //  program description   This program demonstrates the //                 concept of nested classes. // #include<iomanip> #include<iostream> using namespace std; class Date {    private:       int month,          day,          year;    public:       void setDate(int m, int d, int y)       {month=m; day=d; year=y;}       int showMonth(){return month;}       int showDay(){return day;}       int showYear(){return year;} }; class Invoice {    private:       float invAmount;       Date invDate;    public:       void setDate(int m, int d, int y)       {         invDate.setDate(m,d,y);       }       void setAmount(float amount)      {        invAmount=amount;      }      int showInvMonth()      {        return invDate.showMonth();      }      int showInvDay()      {        return invDate.showDay();      }      int showInvYear()      {        return invDate.showYear();      }      float showInvAmount()      {         return invAmount;      } }; void main() {    char dash;    int month,       day,       year;    float amount;    Invoice invoice1234;    cout << "What was the date? ";    cin >> month >> dash >> day >> dash >> year;    invoice1234.setDate(month, day, year);    cout <<endl<<endl<< "What was the amount of the invoice? ";    cin >> amount;    invoice1234.setAmount(amount);    for(int index=1;index<=250;++index)       cout << endl;    cout << "Did you say that the invoice date was: "         << invoice1234.showInvMonth() << "/"         << invoice1234.showInvDay() << "/"         << invoice1234.showInvYear() << endl << endl         << "Did you say that the invoice amount was: "         << setiosflags(ios::fixed) << setprecision(2)         << setiosflags(ios::showpoint) << invoice1234.showInvAmount()         << endl << endl; } // program_id    invoice2.cpp // author      don voils // date_written  7/3/2006 // // description   This program shows functions where class objects //          are arguments of a non-member function and //          are output of a non-member function. // #include<iostream> #include<iomanip> using namespace std; class Invoice {   private:     long itemNumber;     short numberOrdered;     double unitPrice;   public:     void setitemNumber(long theNumber)     {          itemNumber = theNumber;     }     void setnumberOrdered(short theNumber)     {          numberOrdered = theNumber;     }     void setunitPrice(double theNumber)     {          unitPrice = theNumber;     }     long getitemNumber()     {          return itemNumber;     }     short getnumberOrdered()      {           return numberOrdered;      }      double getunitPrice()      {          return unitPrice;      } }; Invoice inputInvoice(); void display(Invoice theInvoice); void clearscreen(); void main() {      Invoice anInvoice;      anInvoice = inputInvoice();      clearscreen();      display(anInvoice);      clearscreen(); } Invoice inputInvoice() {      Invoice theInvoice;      long idNumber;      short theNumber;      double thePrice;      cout << endl << "What was the item number? ";      cin >> idNumber;      cout << endl << "What was the number ordered? ";      cin >> theNumber;      cout << endl << "What was the unit price? ";      cin >> thePrice;      theInvoice.setitemNumber(idNumber);      theInvoice.setnumberOrdered(theNumber);      theInvoice.setunitPrice(thePrice);      char resp;      cout << endl << endl << "Continue? ";      cin >> resp;      return theInvoice; } void display(Invoice theInvoice) {      cout << fixed << setprecision(2);      cout << endl << "The item number is " << theInvoice.getitemNumber()         << endl;      cout << endl << "The number ordered is "         << theInvoice.getnumberOrdered() << endl;      cout << endl << "The unit price is $" << theInvoice.getunitPrice()         << endl;      char resp;      cout << endl << endl << "Continue? ";      cin >> resp; } void clearscreen() {      for(int index=0;index<500;++index)            cout << endl; } // program_id   invoice3.cpp // author     don voils // date_written 4/3/2006 // description  This program shows functions where class objects //          are arguments of a non-member function and //          are output of a non-member function. One of the //          functions is passing the object by reference. // #include<iostream> #include<iomanip> using namespace std; class invoice { private:      long itemNumber;      short numberOrdered;      double unitPrice; public:      void setitemNumber(long iN)      {           itemNumber = iN;      }      void setnumberOrdered(short oN)      {           numberOrdered = oN;      }      void setunitPrice(double uP)      {           unitPrice = uP;      }      long getitemNumber()      {           return itemNumber;      }      short getnumberOrdered()      {          return numberOrdered;      }      double getunitPrice()      {          return unitPrice;      } }; void inputInvoice(invoice& invoice); void display(invoice theInvoice); void clearscreen(); void main() {      invoice anInvoice;      inputInvoice(anInvoice);      clearscreen();      display(anInvoice);      clearscreen(); } void inputInvoice(invoice& theInvoice) {      long idNumber;      short theNumber;      double thePrice;      cout << endl << "What was the item number? ";      cin >> idNumber;      cout << endl << "What was the number ordered? ";      cin >> theNumber;      cout << endl << "What was the unit price? ";      cin >> thePrice;      theInvoice.setitemNumber(idNumber);      theInvoice.setnumberOrdered(theNumber);      theInvoice.setunitPrice(thePrice);      char resp;      cout << endl << endl << "Continue? ";      cin >> resp; } void display(invoice theInvoice) {      cout << fixed << setprecision(2);      cout << endl << "The item number is " << theInvoice.getitemNumber() << endl;      cout << endl << "The number ordered is " << theInvoice.getnumberOrdered() << endl;      cout << endl << "The unit price is $" << theInvoice.getunitPrice() << endl;      char resp;      cout << endl << endl << "Continue? ";      cin >> resp; } void clearscreen() {      for(int index=0;index<500;++index)            cout << endl; } // program_id    invoice4.cpp // written_by    don voils // date_written  5/20/2006 // description   This program shows functions where arrays of class objects //           are passed to a non-member function. // #include<iostream> #include<iomanip> using namespace std; class invoice { private:      long itemNumber;      short numberOrdered;      double unitPrice; public:      void setitemNumber(long iN)      {           itemNumber = iN;      }      void setnumberOrdered(short oN)      {           numberOrdered = oN;      }      void setunitPrice(double uP)      {           unitPrice = uP;      }      long getitemNumber()      {           return itemNumber;      }      short getnumberOrdered()      {            return numberOrdered;      }      double getunitPrice()      {          return unitPrice;      } }; void inputInvoice(invoice theInvoices[],short& numberItems); void display(invoice theInvoices[],short numberItems); void clearscreen(); void main() {      invoice anInvoice[100];      short theNumber = 0;      inputInvoice(anInvoice,theNumber);      clearscreen();      display(anInvoice,theNumber);      clearscreen(); } void inputInvoice(invoice theInvoice[],short& numberItems) {      long idNumber;      short theNumber;      double thePrice;      char resp;      clearscreen();      do      {         cout << endl << "Entering informaton for invoice item "            << numberItems+1 << endl;         cout << endl << "What was the item number? ";         cin >> idNumber;         cout << endl << "What was the number ordered? ";         cin >> theNumber;         cout << endl << "What was the unit price? ";         cin >> thePrice;         theInvoice[numberItems].setitemNumber(idNumber);         theInvoice[numberItems].setnumberOrdered(theNumber);         theInvoice[numberItems].setunitPrice(thePrice);         numberItems++;        cout << endl << endl << "Continue? (Y/N) ";        cin >> resp;        clearscreen();      }while(resp=='y' || resp=='Y'); } void display(invoice theInvoice[],short numberItems) {      cout << fixed << setprecision(2);      cout << left         << setw(15)<< "Invoice number"         << setw(15) << "Item number"         << setw(15) << "Number Ordered"         << setw(15) << "Unit Price" << right << endl;      for(short index = 0;index<numberItems;++index)      {  cout << setw(14) << index+1;         cout << setw(15) << theInvoice[index].getitemNumber();         cout << setw(15) << theInvoice[index].getnumberOrdered();         cout << " $" << setw(14) << theInvoice[index].getunitPrice()            << endl;      }      char resp;      cout << endl << endl << "Continue? ";      cin >> resp; } void clearscreen() {      for(int index=0;index<500;++index)            cout << endl; } // program_id    invoice.cpp // written_by    don voils // date_written  8/21/2006 // description   Contains the definitions of the methods //          of the class Invoice #include "invoice.h" void Invoice::setDate(int theMonth, int theDay, int theYear)          {invoiceDate.setDate(theMonth,theDay,theYear);} void Invoice::setAmount(float theAmount)       {invoiceAmount=theAmount;} int Invoice::showInvoiceMonth()       {return invoiceDate.showMonth();} int Invoice::showInvoiceDay()       {return invoiceDate.showDay();} int Invoice::showInvoiceYear()       {return invoiceDate.showYear();} float Invoice::showInvoiceAmount()       {return invoiceAmount;} // program_id     invoice.h // written_by     don voils // date_written   8/21/2006 // description    Contains the definition of the class //            Invoice. // #include "date.h" #ifndef INVOICE #define INVOICE   class Invoice   {    private:        float invoiceAmount;        Date invoiceDate;    public:       void setDate(int,int,int);       void setAmount(float);       int showInvoiceMonth();       int showInvoiceDay();       int showInvoiceYear();       float showInvoiceAmount();    }; #endif // program_id       newdate.cpp // author         don voils // date written    10/15/2006 // program description //             This program demonstrates the use of the //             keyword operator with the increment operator //             ++() and the decreament operator --() //             with the ability to assign the new values //             to another day in the definiion of the //             class date. In addtion it demonstrates //             the use of the this pointer. // #include<iostream> using namespace std; class Date {       private:           long month,                day,                year;       public:           void getDate(void);           void setDate(long m,long d,long y);           long lastDay(long m,long y);           long showDay();           long showMonth();           long showYear();           bool leapYear(long y);           Date operator ++();           Date operator --();           bool incorrectDate(long m,long d,long y); }; // MAIN PROGRAM // void main() {    Date theDay,       nextDay,       aDay,       bDay;    cout << "What is the date today? ";    theDay.getDate();    cout << endl << endl << "If today is " << theDay.showMonth() << "/"       << (theDay.showDay()) << "/" << (theDay.showYear())       << ", then tomorrow will be ";    ++theDay;    cout << (theDay.showMonth()) << "/"        << (theDay.showDay()) << "/" << (theDay.showYear());    nextDay = ++theDay;    cout << endl << endl << "The day after that would be "       << (theDay.showMonth()) << "/" << theDay.showDay()       << "/" << (theDay.showYear()) << " or may be "       << (nextDay.showMonth()) << "/" << (nextDay.showDay())       << "/" << (nextDay.showYear());    cout << endl << endl << "What was the second day you wanted checked? ";    aDay.getDate();    cout << endl << endl << "If second day is " << (aDay.showMonth())       << "/" << (aDay.showDay()) << "/"            << (aDay.showYear()) << ", then the day before was ";    --aDay;    cout << aDay.showMonth() << "/"      << aDay.showDay() << "/" << (aDay.showYear()-1900);    bDay = --aDay;    cout << endl << endl << "The day before that would be "      << aDay.showMonth() << "/" << (aDay.showDay())      << "/" << (aDay.showYear()) << " or may be "           << (bDay.showMonth()) << "/" << (bDay.showDay())           << "/" << (bDay.showYear());      cout << endl << endl << "Continue? (Y/N) ";      char resp;      cin >> resp;      cout << endl << endl; } long Date::showDay() {    return day; } long Date::showMonth() {    return month; } long Date::showYear() {    return year; } void Date::getDate() {    char dash;    do    {      cin >> month >> dash >> day >> dash >> year;      if(year <100)        if(year < 30)          year +=2000;        else          year+=1900;   }while(incorrectDate(month,day,year)); } void Date::setDate(long m,long d,long y) {    month = m;    day = d;    year = y; } Date Date::operator ++() {    if (day < lastDay(month,year))    {       day = day+1;    }    else    {      if(month<12)      {         month=month+1;         day = 1;      }      else      {         month=1;         day=1;         year=year+1;      }    }    return *this; } Date Date::operator --() {    if (day != 1)    {       day -= 1;    }    else    {      if(month !=1)      {         month -= 1;         day = lastDay(month,year);     }     else     {       month=12;       day = 31;       year -= 1;     }   }   return *this; } long Date::lastDay(long m,long y) {    int lastDay;    int daysInMonth[]={0,31,28,31,30,31,30,31,31,30,31,30,31};    if (m!=2)       lastDay=daysInMonth[int(m)];    else      if (leapYear(y))         lastDay = 29;      else        lastDay = daysInMonth[int(m)];    return lastDay; } bool Date::leapYear(long y) {   bool leapTest;   if (((y%4==0) && (y%100!=0)) || (y%400==0))      leapTest=true;   else      leapTest=false;   return leapTest; } bool Date::incorrectDate(long m,long d,long y) {   bool notCorrect;   if ((m>=1) && (m<=12) && (d>=1) && (d<=lastDay(m,y)))      notCorrect = false;   else     notCorrect = true;   return notCorrect; } // program_id               nlinclas.cpp // author                 don voils // date written            10/08/2006 // // program description     This program illustrates the use //               of inline definitions outside of //               the class definition. // #include<iostream> using namespace std; class stuff {    private:       int stuff_int;       float stuff_float;    public:       void set(int i);       void set(float f);       void display_object(); }; inline void stuff::set(int i) {    stuff_int=i; } inline void stuff::set(float f) {    stuff_float=f; } inline void stuff::display_object() { cout<<"integer="<<stuff_int    << " and float="<<stuff_float<< endl; } void main(void) {    int i = 5;    float f = 25.50;    stuff stuff1;    stuff1.set(i);    stuff1.set(f);    stuff1.display_object();    cout << endl << endl; } // program_id    pc_doInventory.txt // written_by    don voils // date_written 4/3/2006 // description   This is the pseudo code for the program doInventory.cpp. // doInventory     Set More = true;     Set numberItems = 500;     Process loadInventory(inventory[], numberItems);     Do          Process clearScreen();          Display "          Inventory Modification"               "   1.  Enter New Records"               "   2.  Display by ISBN"               "   3.  Edit Records"               "   4.  Delete Records"               "   5.  Exit" << endl               "        Which? "          Receive Choice          CASE of Choice             '1':                  Process enterNewRecords(inventory[],numberItems)             '2':                  Process ISBNDisplay(inventory[],numberItems)             '3':                  Process editItems(inventory[],numberItems)             '4':                  Process deleteItem(inventory[],numberItems)             '5':                  Process clearScreen();                  Display "Data is being stored to file."                  Process saveInventory(inventory[],numberItems)                  Set More = false          ENDCASE     }while(More)     Process clearScreen();     Display "Data has been stored to file." END clearScreen()      FOR(loop_counter=0;loop_counter<=100;++loop_counter)       Display carriageReturn      ENDFOR RETURN loadInventory(inventory[],numberItems)      Open inFile(inventory.txt)      IF(!inFile)THEN           Set startString = "Start"           Set aString = "****"           FOR(index = 0; index < numberItems;++index)              inventory[index].setbookName(startString)              inventory[index].setISBN(aString)              inventory[index].setyearPublished(aString)              inventory[index].setnumberOnHand(aString)              inventory[index].setcostBook(aString)              inventory[index].setpriceBook(aString)              inventory[index].setbookAuthors(0,aString)              inventory[index].setbookAuthors(1,aString)              inventory[index].setbookAuthors(2,aString)              inventory[index].setbookAuthors(3,"end")           ENDFOR        ELSE           FOR(index = 0;index<numberItems;++index)              Receive aString              inventory[index].setbookName(aString)              Receive aString              inventory[index].setISBN(aString)              Receive aString              inventory[index].setyearPublished(aString)              Receive aString              inventory[index].setnumberOnHand(aString)              Receive aString              inventory[index].setcostBook(aString)              Receive aString          inventory[index].setpriceBook(aString)          Receive aString          inventory[index].setbookAuthors(0,aString)          Receive aString          inventory[index].setbookAuthors(1,aString)          Receive aString          inventory[index].setbookAuthors(2,aString)          Receive aString          inventory[index].setbookAuthors(3,aString)       ENDFOR    ENDIF    Close inFile RETURN enterNewRecords(inventory[],numberItems) {      Set recordNumber = -1      FOR(index = 0; index < numberItems;++index)         IF(inventory[index].getISBN() == "****")THEN           recordNumber = index           break         ENDIF      ENDFOR      IF(recordNumber == -1)THEN           Process clearScreen()           Display "Error file is full. Continue? "           Receive resp      ELSE         Process clearScreen()         Request "What is the book name? "         Receive aString         inventory[index].setbookName(aString)         Request "What is the ISBN? "         Receive aString         inventory[index].setISBN(aString)         Request "What is the year the book was published? "         Receive aString         inventory[index].setyearPublished(aString)         Request "How many of this book do we have on hand? "         Receive aString         inventory[index].setnumberOnHand(aString);         Request "What was the cost of the book? "         Receive aString         inventory[index].setcostBook(aString)         Request "What is the price of the book? "         Receive aString         inventory[index].setpriceBook(aString)         Request "What is the name of the first author? "         Receive aString         inventory[index].setbookAuthors(0,aString)         Request "What is the name of the second author? "         Receive aString         inventory[index].setbookAuthors(1,aString)         Request "What is the name of the third author? "         Receive aString         inventory[index].setbookAuthors(2,aString)         Request "What is the name of the fourth author? "         Receive aString         inventory[index].setbookAuthors(3,aString)      ENDIF RETURN ISBNDisplay(bookInventory inventory[],int const &numberItems)     Process clearScreen()     Display"What is the ISBN? "     Receive aString     Set recordNumber = -1     FOR(index = 0; index < numberItems;++index)        IF(inventory[index].getISBN() == aString)THEN          Set recordNumber = index          break        ENDIF     ENDFOR     IF(recordNumber == -1)THEN          Process clearScreen()          Display "Error. There is no book with that ISBN. Continue? "          Receive resp     ELSE          Process clearScreen()          Display "The book name is: " << inventory[index].getbookName()          Display "The ISBN is: " << inventory[index].getISBN()          Display "The year the book was published: "          Display inventory[index].getyearPublished()          Display "The number of this book that we have on hand is: "          Display inventory[index].getnumberOnHand()          Display "The cost of the book was $: "          Display inventory[index].getcostBook()          Display "The total cost is: $"          Display atof((inventory[index].getcostBook()).c_str())*              atoi((inventory[index].getnumberOnHand()).c_str())          Display "The price of the book is: $"          Display inventory[index].getpriceBook()          Display "The total selling price is: $"          Display atof((inventory[index].getpriceBook()).c_str())*              atoi((inventory[index].getnumberOnHand()).c_str())          Display "The name of the first author is: "          Display inventory[index].getbookAuthors(0)          Display "The name of the second author is: "          Display inventory[index].getbookAuthors(1)          Display "The name of the third author is: "          Display inventory[index].getbookAuthors(2)          Display "The name of the fourth author? "          Display inventory[index].getbookAuthors(3)          Display "Continue? "          Receive resp     ENDIF RETURN editItems(inventory[],numberItems)       Set recordNumber = -1       Process clearScreen()       Display "What is the ISBN? "       Receive aString       FOR(int index = 0; index < numberItems;++index)          IF(inventory[index].getISBN() == aString)THEN            Set recordNumber = index            break          ENDIF       ENDFOR       IF(recordNumber == -1)THEN          Process clearScreen()          Display "Error!! There is no such book on record. Continue? "          Receive resp       ELSE          Process clearScreen();          Display "The current data on that book is:" << endl << endl          Display "The book name is: " << inventory[index].getbookName()          Display "The ISBN is: " << inventory[index].getISBN()          Display "The year the book was published: "          Display inventory[index].getyearPublished()          Display "The number of this book that we have on hand is: "          Display inventory[index].getnumberOnHand()          Display "The cost of the book was: $"          Display inventory[index].getcostBook()          Display "The price of the book is: $"          Display inventory[index].getpriceBook()          Display "The name of the first author is: "          Display inventory[index].getbookAuthors(0)          Display "The name of the second author is: "          Display inventory[index].getbookAuthors(1)          Display "The name of the third author is: "          Display inventory[index].getbookAuthors(2)          Display "The name of the fourth author? "          Display inventory[index].getbookAuthors(3) << endl << endl          Display "Continue? "          Receive resp          Display "What is the book name? "          Receive aString          inventory[index].setbookName(aString)          Display "What is the ISBN? "          Receive aString          inventory[index].setISBN(aString)          Display "What is the year the book was published? "          Receive aString          inventory[index].setyearPublished(aString)          Display "How many of this book do we have on hand? "          Receive aString          inventory[index].setnumberOnHand(aString)          Display "What was the cost of the book? "          Receive aString          inventory[index].setcostBook(aString)          Display "What is the price of the book? "          Receive aString          inventory[index].setpriceBook(aString)          Display "What is the name of the first author? "          Receive aString          inventory[index].setbookAuthors(0,aString)          Display "What is the name of the second author? "          Receive aString          inventory[index].setbookAuthors(1,aString)          Display "What is the name of the third author? "          Receive aString          inventory[index].setbookAuthors(2,aString)          Display "What is the name of the fourth author? " ;          Receive aString          inventory[index].setbookAuthors(3,aString)          Display "Continue? "          Receive resp       ENDIF RETURN deleteItem(bookInventory inventory[],int const &numberItems)       Set recordNumber = -1       Process clearScreen();       Display "What is the ISBN of the book you want to delete? "       Receive aString       FOR(index = 0; index < numberItems;++index)          IF(inventory[index].getISBN() == aString)THEN               SetrecordNumber = index;               break;          ENDIF       ENDFOR       IF(recordNumber == -1)THEN          Process clearScreen()          Display "Error!! There is no such book on record. Continue? "          Receive resp)       ELSE          Process clearScreen()          Display "The current data on the book to be deleted is:"          Display "The book name is: " << inventory[index].getbookName()          Display "The ISBN is: " << inventory[index].getISBN()          Display "The year the book was published: "          Display inventory[index].getyearPublished()          Display "The number of this book that we have on hand is: "          Display inventory[index].getnumberOnHand()          Display "The cost of the book was: $"          Display inventory[index].getcostBook()          Display "The price of the book is: $"          Display inventory[index].getpriceBook()          Display "The name of the first author is: "          Display inventory[index].getbookAuthors(0)          Display "The name of the second author is: "          Display inventory[index].getbookAuthors(1)          Display "The name of the third author is: "          Display inventory[index].getbookAuthors(2)          Display "The name of the fourth author? "          Display inventory[index].getbookAuthors(3)          Display "Continue to delete? (Y/N)"          Receive resp)          IF((resp=='Y') | (resp == 'y'))THEN               Set startString = "Start";               Set aString = "****";               Set endString = "End"               inventory[index].setbookName(startString)               inventory[index].setISBN(aString)               inventory[index].setyearPublished(aString)               inventory[index].setnumberOnHand(aString)               inventory[index].setcostBook(aString)               inventory[index].setpriceBook(aString)               inventory[index].setbookAuthors(0,aString)               inventory[index].setbookAuthors(1,aString)               inventory[index].setbookAuthors(2,aString)               inventory[index].setbookAuthors(3,endString)          ENDIF       ENDIF RETURN saveInventory(inventory[],numberItems)     OPEN outFile("inventory.txt");     FOR(index = 0; index < numberItems; ++index)        Set aString = inventory[index].getbookName()        Save aString to outFile        Set aString = inventory[index].getISBN()        Save aString to outFile        Set aString = inventory[index].getyearPublished()        Save aString to outFile        Set aString = inventory[index].getnumberOnHand()        Save aString to outFile        Set aString = inventory[index].getcostBook()        Save aString to outFile        Set aString = inventory[index].getpriceBook()        Save aString to outFile        Set aString = inventory[index].getbookAuthors(0)        Save aString to outFile        Set aString = inventory[index].getbookAuthors(1)        Save aString to outFile        Set aString = inventory[index].getbookAuthors(2)        Save aString to outFile        Set aString = inventory[index].getbookAuthors(3)        Save aString to outFile     ENDFOR     outFile.close(); RETURN // program_id       prvtfnct.cpp // author         don voils // date written    10/9/2006 // // program description    This program show an example //                where functions can be in the //                private section as well as data. // #include<iostream> using namespace std; const short START_YEAR = 2000; class Date {    private:       short month,           day,           year;       // The following functions are hidden from main().       // Only date class members may access them.       //       bool testDay(const short d)       {         return ((d>31) || (d < 1))? false : true;       }       bool testMonth(const short m)       {         return ((m>12) || (m<1))? false: true;       }       bool testYear(const int y)       {         return (y<START_YEAR)? false: true;       }    public:       // The following three functions are called access       // functions because they permit access to the data elements       // from main() through these functions.       //       short showMonth() {return (month);}       short showDay() {return (day);}       short showYear() {return (year);}       // This function sets the data elements of the date.       // A constructor could not be used here because there       // is a return which is not permitted for a constructor.       //       bool setDate(const short m, const short d, const short y)       {  bool good_day;         if((testMonth(m)) && (testDay(d)) && (testYear(y)))         {  day = d;            month = m;            year = y;            good_day = true;         }         else            good_day = false;         return (good_day);       } }; void main(void) {    Date invoiceDate;    bool    not_correct_date;    char    dash;    short   month,          day,          year;    do    {      cout << endl << endl << "What is the invoice date? (MM/DD/YYYY) ";      cin >> month >> dash >> day >> dash >> year;      if (invoiceDate.setDate(month,day,year))        not_correct_date = false;      else      {        not_correct_date = true;        cout << endl << endl << "Check date entered.";      }    }while(not_correct_date);    cout << endl << endl << "The invoice date entered is "        << invoiceDate.showMonth() << "/" << invoiceDate.showDay()        << "/" << invoiceDate.showYear();       char resp;       cout << endl << endl << "Continue? ";       cin >> resp;       cout << endl << endl; } // program_id    sc_doInventory.gif // written_by    don voils // date_written  5/5/2006 // description   This is the structure chart for the program: doInventory.cpp. 

image from book

 // program_id       STACFNCT.CPP // author         don voils // date written    10/11/2006 // // program description   This program contains a static //                member function. // #include<iostream> using namespace std; class Counter {    private:       static int count;       static int showIt();    public:       Counter();       static void showCount(); }; int Counter::count=0; Counter::Counter() {    ++count; } void Counter::showCount() {    cout << "count = " << count << endl << endl; } int Counter::showIt() {      return count; } void main() {      // The statement below will not compile because of the access      //      // Counter::show_it();      cout << "Before any objects are defined " << endl;      Counter::showCount();      Counter numb1, numb2, numb3;      cout << "Three objects have been defined. " << endl << endl;      cout << endl << "Using numb1 and the static method show_count()" << endl;      numb1.showCount();      cout << endl << "Using numb2 and the static method show_count()" << endl;      numb2.showCount();      cout << endl << "Using numb3 and the static method show_count()" << endl;      numb3.showCount();      cout << endl;      cout << "Using the class name and the static method show_count()" << endl;      Counter::showCount(); } // program_id       staticAccount2.cpp // author         don voils // date written    9/23/2006 // // program description  This program demonstrates //             the access of static attributes //             by the class name if it is declared //             in the public access section. // #include<iostream> using namespace std; class BankAccount {    private:       float amount;    public:       static int numberAccounts;       BankAccount()       {         amount = 0;         ++numberAccounts;       }       BankAccount(float startingAmount)       {         amount = startingAmount;         ++numberAccounts;       }       void depositSlip(float deposit)       {         amount += deposit;       }       void withdrawalSlip(float checkAmount)       {         amount -= checkAmount;       }       float showBalance()       {         return amount;       }       int showNumberAccounts()       {         return numberAccounts;       } }; int BankAccount::numberAccounts = 0; void main() {    cout << "I started my checking account at the bank"       << endl << endl;    BankAccount checkingAccount;    cout << "I deposited $2,000.00 in my checking account"       << endl << endl;    checkingAccount.depositSlip(2000.00);    cout << "I wrote checks for $700.00 against my account."       << endl <<endl;    checkingAccount.withdrawalSlip(700.00);    cout << "My account balance is $"       << checkingAccount.showBalance() << endl << endl;    cout << "I started my savings account at the bank with "       << "$5,000" << endl << endl;    BankAccount savingsAccount(5000);    cout << "I desposited $3,000.00 in my savings account"       << endl << endl;    savingsAccount.depositSlip(3000.00);    cout << "I withdrew $1,700.00 from my savings account"       << endl << endl;    savingsAccount.withdrawalSlip(1700.00);    cout << "My savings balance is $"       << savingsAccount.showBalance() << endl << endl;    cout << "Thank you for opening the "       << BankAccount::numberAccounts << " accounts."       << endl << endl << "We have "       << savingsAccount.showNumberAccounts()       << " gifts for you one for each account."       << endl << endl << "You will be receiving them within "       << "the next few days. Again thank you for your "       << "business." << endl << endl; } // program_id      staticAccount.cpp // author           don voils // date written    9/23/2006 // //   program description  This program demonstrates //                         that a static attribute //                         may be accessed by the //                         class but not if it is //                         declared in the private //                         access section. // #include<iostream> using namespace std; class BankAccount {    private:       float      amount;       static int   numberAccounts;    public:      BankAccount()      {         amount = 0;         ++numberAccounts;      }      BankAccount(float startingAmount)      {         amount = startingAmount;         ++numberAccounts;      }      void depositSlip(float deposit)      {         amount += deposit;      }      void withdrawalSlip(float checkAmount)      {         amount -= checkAmount;      }      float showBalance()      {         return amount;      }      int showNumberAccounts()      {         return numberAccounts;      } }; int BankAccount::numberAccounts = 0; void main() {    cout << "I started my checking account at the bank"       << endl << endl;    BankAccount checkingAccount;    cout << "I deposited $2,000.00 in my checking account"       << endl << endl;    checkingAccount.depositSlip(2000.00);    cout << "I wrote checks for $700.00 against my account."       << endl <<endl;    checkingAccount.withdrawalSlip(700.00);    cout << "My account balance is $"       << checkingAccount.showBalance() << endl << endl;    cout << "I started my savings account at the bank with "       << "$5,000" << endl << endl;    BankAccount savingsAccount(5000);    cout << "I desposited $3,000.00 in my savings account"       << endl << endl;    savingsAccount.depositSlip(3000.00);    cout << "I withdrew $1,700.00 from my savings account"       << endl << endl;    savingsAccount.withdrawalSlip(1700.00);    cout << "My savings balance is $"       << savingsAccount.showBalance() << endl << endl;    cout << "Thank you for opening the "       << BankAccount::numberAccounts << " accounts."       << endl << "We have "       << savingsAccount.showNumberAccounts()       << " gifts for you one for each account."       << endl << "You will be receiving them within "       << "the next few days. Again thank you for your "       << "business." << endl << endl; } /*   program_id       theAccount.h   written_by       don voils   date_written     3/3/2006   Description:     This file contains the definition               of the class theAccount. The member functions               for the class are placed in the               source file: theAccount.cpp */ #ifndef ACCOUNT #define ACCOUNT class Account {    private:       float theBalance;    public:       void settheBalance(float);       float gettheBalance();       void doDeposit(float);       void doWithdrawal(float); }; #endif /* program_id       theAccount.cpp    written_By       don voils    date_written     4/3/2006    description:     This file contains the member functions                for the class Account whose definition is contained                in the header file: theAccount.h. This file                should be a source file in the project. */ #include "theAccount.h" void Account::settheBalance(float theAmount) {   theBalance = theAmount; } float Account::gettheBalance() {       return theBalance; } void Account::doDeposit(float theAmount) {    theBalance += theAmount; } void Account::doWithdrawal(float theAmount) {    theBalance -= theAmount; } // program-id   theFunctions.h // written-by   Don Voils // date written 5/27/2006 // // Description This file contains the definition of the //         function that are the modules for the //         program doInventory.cpp. // #include<iostream> #include<string> #include<fstream> #include<iomanip> #include<cstdlib> using namespace std; // The defintion of the bookInventory class // must be included into the program. // #include"bookInventory.h" // This function is used to clear the screen for // a better user presentation. // void clearScreen() {      for(int loop_counter=0;loop_counter<=150;++loop_counter)                 cout << endl; } // This function is used to load from file the book records // and then stores them into the inventory array. // void loadInventory(BookInventory inventory[],int const &numberItems) {      // The data file that holds the inventory is opened      //      ifstream inFile("inventory.txt");      // If the file is empty, then it is filled with      // empty data.      //      if(!inFile)      {  string startString = "Start";           string aString = "****";           //cout << "Starting." << endl;           //char resp;           //cin.get(resp).get();           for(int index = 0; index < numberItems;++index)           {                inventory[index].setbookName(startString);                inventory[index].setISBN(aString);                inventory[index].setyearPublished(aString);                inventory[index].setnumberOnHand(aString);                inventory[index].setcostBook(aString);                inventory[index].setpriceBook(aString);                inventory[index].setbookAuthors(0,aString);                inventory[index].setbookAuthors(1,aString);                inventory[index].setbookAuthors(2,aString);                inventory[index].setbookAuthors(3,"end");           }      }      else      {           // If the file is not empty, it is input into           // the array of inventory items array.           //           string aString;           for(int index = 0;index<numberItems;++index)           {                getline(inFile,aString);                inventory[index].setbookName(aString);                getline(inFile,aString);                inventory[index].setISBN(aString);                getline(inFile,aString);                inventory[index].setyearPublished(aString);                getline(inFile,aString);                inventory[index].setnumberOnHand(aString);                getline(inFile,aString);                inventory[index].setcostBook(aString);                getline(inFile,aString);                inventory[index].setpriceBook(aString);                getline(inFile,aString);                inventory[index].setbookAuthors(0,aString);                getline(inFile,aString);                inventory[index].setbookAuthors(1,aString);                getline(inFile,aString);                inventory[index].setbookAuthors(2,aString);                getline(inFile,aString);                inventory[index].setbookAuthors(3,aString);           }      }      inFile.close(); } // This function permits the entry of a book records. It first // finds an empty record in the inventory array and then permits // the individual data items to be entered into the particular record. // void enterNewRecords(BookInventory inventory[],int const &numberItems) {      // The inventory array is searched for an empty record.      //      int recordNumber = -1;      for(int index = 0; index < numberItems;++index)      {           if(inventory[index].getISBN() == "****")           {                recordNumber = index;                break;           }      }      // If the inventory array has no more empty records, the      // user is notified of that case.      //      if(recordNumber == -1)      {           clearScreen();           cout << "Error file is full. Continue? " << endl;           char resp;           cin.get(resp).get();      }      else      {           // If the inventory array has an empty record,           // the data is entered into that record.           //           clearScreen();           string aString;           cout << "What is the book name? ";           getline(cin,aString);           inventory[recordNumber].setbookName(aString);           cout << endl << "What is the ISBN? ";           getline(cin,aString);           inventory[recordNumber].setISBN(aString);           cout << endl << "What is the year the book was published? ";           getline(cin,aString);           inventory[recordNumber].setyearPublished(aString);           cout << endl << "How many of this book do we have on hand? ";           getline(cin,aString);           inventory[recordNumber].setnumberOnHand(aString);           cout << endl << "What was the cost of the book? ";           getline(cin,aString);           inventory[recordNumber].setcostBook(aString);           cout << endl << "What is the price of the book? ";           getline(cin,aString);           inventory[recordNumber].setpriceBook(aString);           cout << endl << "What is the name of the first author? ";           getline(cin,aString);           inventory[recordNumber].setbookAuthors(0,aString);           cout << endl << "What is the name of the second author? ";           getline(cin,aString);           inventory[recordNumber].setbookAuthors(1,aString);           cout << endl << "What is the name of the third author? ";           getline(cin,aString);           inventory[recordNumber].setbookAuthors(2,aString);           cout << endl << "What is the name of the fourth author? ";           getline(cin,aString);           inventory[recordNumber].setbookAuthors(3,aString);      } } // This function displays the data values of a particular record // given the ISBN of the book. // void ISBNDisplay(BookInventory inventory[],int const &numberItems) {      string aString;      clearScreen();      // The ISBN of the record to be displayed is requested.      //      cout << "What is the ISBN? ";      getline(cin,aString);      // The manipulators for output is set up.      //      cout << setprecision(2);      cout << fixed;      // The inventory array is searched to determine      // whether a record exists with the requested      // ISBN.      //      int recordNumber = -1;      for(int index = 0; index < numberItems;++index)      {           if(inventory[index].getISBN() == aString)           {                recordNumber = index;                break;           }      }      // If no record exists for the requested ISBN,      // an error message is returned.      //      if(recordNumber == -1)      {           clearScreen();           cout << "Error. There is no book with that ISBN. Continue? ";           char resp;           cin.get(resp).get();      }      else      {           // When the record for the requested ISBN book exists,           // the data for the book is displayed.           //           clearScreen();           cout << "The book name is: " << inventory[recordNumber].getbookName()              << endl << "The ISBN is: " << inventory[recordNumber].getISBN()              << endl << "The year the book was published: "              << inventory[recordNumber].getyearPublished()              << endl << "The number of this book that we have on hand is: "              << inventory[recordNumber].getnumberOnHand()              << endl << "The cost of the book was $: "              << inventory[recordNumber].getcostBook()              << endl << "The total cost is: $"              << atof((inventory[recordNumber].getcostBook()).c_str())*                        atoi((inventory[recordNumber].getnumberOnHand()).c_str())              << endl << "The price of the book is: $"              << inventory[recordNumber].getpriceBook()              << endl << "The total selling price is: $"              << atof((inventory[recordNumber].getpriceBook()).c_str())*                        atoi((inventory[recordNumber].getnumberOnHand()).c_str())              << endl << "The name of the first author is: "              << inventory[recordNumber].getbookAuthors(0)              << endl << "The name of the second author is: "              << inventory[recordNumber].getbookAuthors(1)              << endl << "The name of the third author is: "              << inventory[recordNumber].getbookAuthors(2)              << endl << "The name of the fourth author? "              << inventory[recordNumber].getbookAuthors(3) << endl << endl;           cout << "Continue? ";           char resp;           cin.get(resp).get();      } } // This function permits the editing of the individual record items // one at a time given an the ISBN of the book. // void editItems(BookInventory inventory[],int const &numberItems) {      string aString;      char resp;      int recordNumber = -1;      // The ISBN for the record to be edited is requested.      //      clearScreen();      cout << "What is the ISBN? ";      getline(cin,aString);      for(int index = 0; index < numberItems;++index)      {           if(inventory[index].getISBN() == aString)           {                recordNumber = index;                break;           }      }      // If no book exists in the inventory array with the      // requested ISBN, an error message is returned.      //              if(recordNumber == -1)      {            clearScreen();            cout << "Error!! There is no such book on record. Continue? ";            cin.get(resp).get();      }      else      {           // The current data for the book with the requested           // ISBN is displayed.           //           clearScreen();           cout << "The current data on that book is:" << endl << endl              << "The book name is: " << inventory[recordNumber].getbookName()              << endl << "The ISBN is: " << inventory[recordNumber].getISBN()              << endl << "The year the book was published: "              << inventory[recordNumber].getyearPublished()              << endl << "The number of this book that we have on hand is: "              << inventory[recordNumber].getnumberOnHand()              << endl << "The cost of the book was: $"              << inventory[recordNumber].getcostBook()              << endl << "The price of the book is: $"              << inventory[recordNumber].getpriceBook()              << endl << "The name of the first author is: "              << inventory[recordNumber].getbookAuthors(0)              << endl << "The name of the second author is: "              << inventory[recordNumber].getbookAuthors(1)              << endl << "The name of the third author is: "              << inventory[recordNumber].getbookAuthors(2)              << endl << "The name of the fourth author? "              << inventory[recordNumber].getbookAuthors(3) << endl << endl;           cout << "Continue? ";           cin.get(resp).get();           // The new data for the record is requested.           //           cout << endl << endl << "What is the book name? ";           getline(cin,aString);           inventory[recordNumber].setbookName(aString);           cout << endl << "What is the ISBN? ";           getline(cin,aString);           inventory[recordNumber].setISBN(aString);           cout << endl << "What is the year the book was published? ";           getline(cin,aString);           inventory[recordNumber].setyearPublished(aString);           cout << endl << "How many of this book do we have on hand? ";           getline(cin,aString);           inventory[recordNumber].setnumberOnHand(aString);           cout << endl << "What was the cost of the book? ";           getline(cin,aString);           inventory[recordNumber].setcostBook(aString);           cout << endl << "What is the price of the book? ";           getline(cin,aString);           inventory[recordNumber].setpriceBook(aString);           cout << endl << "What is the name of the first author? ";           getline(cin,aString);           inventory[recordNumber].setbookAuthors(0,aString);           cout << endl << "What is the name of the second author? ";           getline(cin,aString);           inventory[recordNumber].setbookAuthors(1,aString);           cout << endl << "What is the name of the third author? ";           getline(cin,aString);           inventory[recordNumber].setbookAuthors(2,aString);           cout << endl << "What is the name of the fourth author? ";           getline(cin,aString);           inventory[recordNumber].setbookAuthors(3,aString);           cout << endl << "Continue? ";           cin.get(resp).get();      } } // This function permits the deleting from a record that has been // selected by using the ISBN. It first asks for the ISBN and then // if the user desires it to be deleted the record is filed with // empty data. // void deleteItem(BookInventory inventory[],int const &numberItems) {      string aString;      char resp;      int recordNumber = -1;      clearScreen();      // The ISBN for the book to be deleted is requested.      //      cout << "What is the ISBN of the book you want to delete? ";      getline(cin,aString);      // The records of the inventory array are searched to      // find the record with the requested ISBN.      //      for(int index = 0; index < numberItems;++index)      {           if(inventory[index].getISBN() == aString)           {                recordNumber = index;                break;           }      }      // If no record exists with the requested ISBN,      // an error message is returned.      //      if(recordNumber == -1)      {           clearScreen();           cout << "Error!! There is no such book on record. Continue? ";                      cin.get(resp).get();      }      else      {           clearScreen();           // If the record exists, the data is displayed in order           // for the user to check to ensure that the record found           // is the record to be deleted.           //           cout << "The current data on the book to be deleted is:" << endl << endl             << "The book name is: " << inventory[recordNumber].getbookName()             << endl << "The ISBN is: " << inventory[recordNumber].getISBN()             << endl << "The year the book was published: "             << inventory[recordNumber].getyearPublished()             << endl << "The number of this book that we have on hand is: "             << inventory[recordNumber].getnumberOnHand()             << endl << "The cost of the book was: $"             << inventory[recordNumber].getcostBook()             << endl << "The price of the book is: $"             << inventory[recordNumber].getpriceBook()             << endl << "The name of the first author is: "             << inventory[recordNumber].getbookAuthors(0)             << endl << "The name of the second author is: "             << inventory[recordNumber].getbookAuthors(1)             << endl << "The name of the third author is: "             << inventory[recordNumber].getbookAuthors(2)             << endl << "The name of the fourth author? "             << inventory[recordNumber].getbookAuthors(3) << endl << endl;           cout << "Continue to delete? (Y/N)";           cin.get(resp).get();           // The user is requested to confirm that the displayed data           // is the record to be deleted. If it is, then the           // record is filled with empty data.           //           if((resp=='Y') || (resp == 'y'))           {                 string startString = "Start";                 string aString = "****";                 string endString = "End";                 inventory[recordNumber].setbookName(startString);                 inventory[recordNumber].setISBN(aString);                 inventory[recordNumber].setyearPublished(aString);                 inventory[recordNumber].setnumberOnHand(aString);                 inventory[recordNumber].setcostBook(aString);                 inventory[recordNumber].setpriceBook(aString);                 inventory[recordNumber].setbookAuthors(0,aString);                 inventory[recordNumber].setbookAuthors(1,aString);                 inventory[recordNumber].setbookAuthors(2,aString);                 inventory[recordNumber].setbookAuthors(3,endString);           }      } } // This function stores the data that is contained in the // inventory array into the file for later use. This is // called prior to the program ending. // void saveInventory(BookInventory inventory[],int const &numberItems) {      // The data file is opened for outputing the records      // that are stored in the inventory array prior to      // ending the program.      //      string aString;      ofstream outFile("inventory.txt");      // Each record in the inventory array is sent to      // the data file.      //      for(int index = 0; index < numberItems; ++ index)      {           aString = inventory[index].getbookName();           outFile << aString << endl;           aString = inventory[index].getISBN();           outFile << aString << endl;           aString = inventory[index].getyearPublished();           outFile << aString << endl;           aString = inventory[index].getnumberOnHand();           outFile << aString << endl;           aString = inventory[index].getcostBook();           outFile << aString << endl;           aString = inventory[index].getpriceBook();           outFile << aString << endl;           aString = inventory[index].getbookAuthors(0);           outFile << aString << endl;           aString = inventory[index].getbookAuthors(1);           outFile << aString << endl;           aString = inventory[index].getbookAuthors(2);           outFile << aString << endl;           aString = inventory[index].getbookAuthors(3);           outFile << aString << endl;      }      outFile.close(); } //program_id    THIS.CPP //author      don voils //date_written  10/26/2006 // //program_description This program demonstrates the class //            pointer this. // #include<iostream> using namespace std; class AClass {      private:           float amount;      public:           AClass(float anAmount)           {               this->amount = anAmount;           }           float getAmount()           {               return this->amount;           }           void showAddress()           {               cout << this << endl;           } }; void main() {      AClass a1(10.0);      AClass a2(20.0);      AClass a3(30.0);      cout << "The amount in a1 is " << a1.getAmount() << endl;      cout << "The amount in a2 is " << a2.getAmount() << endl;      cout << "The amount in a3 is " << a3.getAmount() << endl << endl;      cout << "The address of a1 is ";      a1.showAddress();      cout << "The address of a2 is ";      a2.showAddress();      cout << "The address of a3 is ";      a3.showAddress();      cout << endl << "The address of a1 is " << &a1 << endl;      cout << "The address of a2 is " << &a2 << endl;      cout << "The address of a3 is " << &a3 << endl << endl; } b 100.23 d 423.22 w 43.15 w 64.23 w 55.83 d 534.65 w 438.32 




Intermediate Business Programming with C++
Intermediate Business Programming with C++
ISBN: 738453099
EAN: N/A
Year: 2007
Pages: 142

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net