CISC 181 Project 3 Designing Classes for Bank Accounts



Similar documents
It has a parameter list Account(String n, double b) in the creation of an instance of this class.

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

El Dorado Union High School District Educational Services

Computer Programming C++ Classes and Objects 15 th Lecture

An Incomplete C++ Primer. University of Wyoming MA 5310

Ch 7-1. Object-Oriented Programming and Classes

Project 2: Bejeweled

Moving from CS 61A Scheme to CS 61B Java

Introduction to Programming II Winter, 2014 Assignment 2

PIC 10A. Lecture 7: Graphics II and intro to the if statement

MS Visual C++ Introduction. Quick Introduction. A1 Visual C++

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

Lab 2: Swat ATM (Machine (Machine))

CpSc212 Goddard Notes Chapter 6. Yet More on Classes. We discuss the problems of comparing, copying, passing, outputting, and destructing

CS 111 Classes I 1. Software Organization View to this point:

Member Functions of the istream Class

C++ Outline. cout << "Enter two integers: "; int x, y; cin >> x >> y; cout << "The sum is: " << x + y << \n ;

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

D06 PROGRAMMING with JAVA. Ch3 Implementing Classes

CS193D Handout 06 Winter 2004 January 26, 2004 Copy Constructor and operator=

Object Oriented Software Design II

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

IS0020 Program Design and Software Tools Midterm, Feb 24, Instruction

Software Engineering Concepts: Testing. Pointers & Dynamic Allocation. CS 311 Data Structures and Algorithms Lecture Slides Monday, September 14, 2009

Object Oriented Software Design

csce4313 Programming Languages Scanner (pass/fail)

Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

3 Pillars of Object-oriented Programming. Industrial Programming Systems Programming & Scripting. Extending the Example.

CS170 Lab 11 Abstract Data Types & Objects

Compiler Construction

CMSC Fundamentals of Computer Programming II (C++)

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

Introduction to C++ Introduction to C++ Week 7 Dr Alex Martin 2013 Slide 1

Dalhousie University CSCI 2132 Software Development Winter 2015 Lab 7, March 11

CS 101 Computer Programming and Utilization

Introduction to Object-Oriented Programming

CS 241 Data Organization Coding Standards

Chulalongkorn University International School of Engineering Department of Computer Engineering Computer Programming Lab.

Lecture 5: Java Fundamentals III

Management Information Systems 260 Web Programming Fall 2006 (CRN: 42459)

CS 106 Introduction to Computer Science I

Formatting Numbers with C++ Output Streams

System Calls Related to File Manipulation

The C Programming Language course syllabus associate level

Assignment # 2: Design Patterns and GUIs

13 Classes & Objects with Constructors/Destructors

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

C++ Input/Output: Streams

C++FA 5.1 PRACTICE MID-TERM EXAM

J a v a Quiz (Unit 3, Test 0 Practice)

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Sources: On the Web: Slides will be available on:

Binary storage of graphs and related data

Fondamenti di C++ - Cay Horstmann 1

EP241 Computer Programming

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

C++ Programming Language

Curriculum Map. Discipline: Computer Science Course: C++

Conditions & Boolean Expressions

C++ INTERVIEW QUESTIONS

Sample CSE8A midterm Multiple Choice (circle one)

1001ICT Introduction To Programming Lecture Notes

I. INTRODUCTION. International Journal of Computer Science Trends and Technology (IJCST) Volume 3 Issue 2, Mar-Apr 2015

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists

public static void main(string[] args) { System.out.println("hello, world"); } }

Appendix K Introduction to Microsoft Visual C++ 6.0

CP Lab 2: Writing programs for simple arithmetic problems

Classes and Objects. Agenda. Quiz 7/1/2008. The Background of the Object-Oriented Approach. Class. Object. Package and import

CS193j, Stanford Handout #10 OOP 3

Advanced compiler construction. General course information. Teacher & assistant. Course goals. Evaluation. Grading scheme. Michel Schinz

Comp151. Definitions & Declarations

Illustration 1: Diagram of program function and data flow

Software documentation systems

Connecting to an Excel Workbook with ADO

Basics of I/O Streams and File I/O

Polymorphism. Problems with switch statement. Solution - use virtual functions (polymorphism) Polymorphism

5 CLASSES CHAPTER. 5.1 Object-Oriented and Procedural Programming. 5.2 Classes and Objects 5.3 Sample Application: A Clock Class

Fast Arithmetic Coding (FastAC) Implementations

Lab 2 : Basic File Server. Introduction

Variable Base Interface

Module 816. File Management in C. M. Campbell 1993 Deakin University

The programming language C. sws1 1

Introduction to Matlab

SMTP-32 Library. Simple Mail Transfer Protocol Dynamic Link Library for Microsoft Windows. Version 5.2

Operator Overloading. Lecture 8. Operator Overloading. Running Example: Complex Numbers. Syntax. What can be overloaded. Syntax -- First Example

Programming Languages CIS 443

Fundamentals of Computer Programming CS 101 (3 Units)

Object Oriented Software Design II

Brent A. Perdue. July 15, 2009

CPSC 226 Lab Nine Fall 2015

No no-argument constructor. No default constructor found

CPSC 2800 Linux Hands-on Lab #7 on Linux Utilities. Project 7-1

Sequential Program Execution

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

PHP Debugging. Draft: March 19, Christopher Vickery

/* File: blkcopy.c. size_t n

Channel Access Client Programming. Andrew Johnson Computer Scientist, AES-SSG

Transcription:

CISC 181 Project 3 Designing Classes for Bank Accounts Code Due: On or before 12 Midnight, Monday, Dec 8; hardcopy due at beginning of lecture, Tues, Dec 9 What You Need to Know This project is based on the material assigned through chapter 8. Specifications In your job as chief system analyst at the Diamond State Bank, you are asked to design and implement some new software for processing bank accounts. Fortunately, you know about object-oriented programming in C++ and know that a well-designed set of classes will be the right way to implement the new software. The Class BankAcct Design a class BankAcct. Each object of the class should contain the private data Name name; int acctno; double balance; The type Name will be a full-fledged class. That is, class Name { friend ostream& operator<<(ostream& out, const Name& n); friend istream& operator>>(istream& in, Name& n); Adapted from exercise 7.8 in D&D. 1

public: Name(const char* fname = "", const char* lname = ""); // Constructor Name(const Name& n); ~Name(); // Copy constructor // Destructor char* getfirstname() const; char* getlastname() const; private: }; char *firstname; char *lastname; The two constructors should dynamically allocate char[] arrays for the first and last names that are the exact size needed to hold the names. The destructor, ~Name(), should deallocate the dynamically allocated arrays. Overload the assignment operator if you wish to use assignment statements with Names. Overload the comparison operators, ==, <, and >, as is appropriate. Write and debug this class before beginning the implementation of the next class. The constructor for BankAcct should take four arguments: (1) a character string for the first name, (2) a character string for the last name, (3) an integer for the account number, and (4) a double (for the balance) with default value = 0.0. The default values for the first and last names should be the empty string "". The default value for the account number should be zero. The constructor should not allow initial balances to be negative. If a user of the class tries to set the initial balance to a negative value, issue an error message and set the balance to zero. Provide the following public member functions. For simplicity, use the type double for money amounts. 1. Name getname() const; Returns the account holder s name. 2. int getacctno() const; Returns the account s account number. 3. double getcurrentbal() const; Returns the current balance. 4. void deposit(double amt); Deposits amt. Make sure that amount is not negative. If the amount is negative, void the deposit. 5. double withdraw(double amt); Withdraws amt. Make sure that amount is greater than or equal zero and less than or equal the account balance. If not, make the withdrawal amount zero. Return the amount withdrawn. 2

6. void monthlyint(double annualrate); that calculates monthly interest by multiplying the balance by the annual rate divided by 12; this interest should be added to the balance. 7. friend istream& operator>>(istream& in, BankAcct& A); Overload the operator >> to read data for an individual account in the form given in the files $CLASSHOME/programming-projs/atm-acct-data and $CLASSHOME/programming-projs/passbook-acct-data. That is, in the form first-name last-name account-no balance 8. friend ostream& operator<<(ostream& out, const BankAcct& A); Overload the operator << to write individual account data. It writes data for an individual account in the format needed for input. Use the overloaded I/O operators to read/write an object of type Name when implementing the I/O operators for the class BankAcct. A smart programmer would now write a main driver program to test out the BankAcct class before proceeding with the rest of the project. Usually when implementing a large software project, it is a good strategy to implement the input and output functions first so that they can be used to help debug the other functions. See the section on debugging tips at the end of this write-up for more helpful information about how to debug your code. The Class AcctArray Now design a class AcctArray to process the bank s files of different accounts. Each file begins with a line like the following CurrentInterestRate = x.y% where x.y is the annual interest rate for this account. This line is then followed by lines for individual accounts in form given in the previous section. See the files atm-acct-data and passbook-acct-data. Each member of the class AcctArray should contain the private data BankAcct* Acct; int noaccts; int currentarraysize; double annualinterestrate; Acct is a pointer to a dynamically allocated array of accounts. noaccts is the current number of accounts, and annualinterestrate is the annual interest rate paid by this kind of account. The class should provide the following public member functions in addition to a constructor and destructor. The constructor should take two arguments, the size of the array to create with default value = 10 and the annual interest rate 3

with default value = 0.06. The destructor (see the constructors/destructors in the class String, Fig08-7 of D&D for an example that does something similar) should deallocate the dynamic memory allocated by the constructor and nothing more. 1. friend istream& operator>>(istream& in, AcctArray& A); Overload the operator>> to read a file of bank accounts (until EOF is encountered). This function should reallocate the array Acct as needed so that it is big enough to hold all the data. The file $CLASSHOME/example-progs/array-dynamic-read.cc demonstrates how to do this. 2. friend ostream& operator<<(ostream& out const AcctArray& A); Overload the operator<< to write a file of bank accounts. The implementation of the overloaded I/O operators for the AcctArray class should use the overloaded operators >> and << defined for the class BankAcct. 3. void processtransactionfile( char filename[] ); Process a file of transactions for the accounts. Each item in the file is of the form transactiontype accountnumber amount where the transaction type is the string deposit or the string withdraw, account number is a customer s account number, and amount is the amount to be deposited or withdrawn from the account. 4. void calcmonthlyint(); Calculates the monthly interest for each account in the array and adds (deposits) it to the account. 5. void SortByName(); Sorts array Acct by name. 6. void SortByAcctNo(); Sorts array Acct by account numbers with smallest first. The main() Program Use the class AcctArray to write a main program to process files for two different kinds of bank accounts one of ATM accounts and the other of pass book accounts. The program should read the information for the two kinds of accounts as found in the external files $CLASSHOME/programming-projs/atm-acct-data and $CLASSHOME/programming-projs/passbook-acct-data. Use the default initialization values for each variable declared of type AcctArray. For each input file main() performs the following functions. Prints the file as originally read. The bank might do this for accounting purposes. Processes the corresponding file of transactions. That is, the file $CLASSHOME/programming-progs/atm-transactions or the file $CLASSHOME/programming-progs/passbook-transactions. 4

Computes and adds the monthly interest to each account. Prints the file sorted by name and then prints it again sorted by account number. All functions for the classes should be member functions (i.e., do not use friends except when overloading operators). Use separate.h and.cc files for each class and a seventh file main.cc for the main program. What to Hand-in Via email Send a copy of each of your files of code to your TA 1 no later than 12 midnight on Monday, Dec 8. Hardcopy Hand-in a hard copy of a single file containing the following: the hardcopy is due at the beginning of lecture on Tuesday, Dec. 9. The file should be created using the Unix command script as done previously for projects and in lab. 1. A completed cover sheet (see the file $CLASSHOME/programming-projs/coversheet). Please note the distribution of points on the coversheet that shows how the project will be graded. It is important that you include this page. To do so, copy it to your directory, fill in the assignment name (i.e., Programming Project 3), your name, and your user number. Then use the Unix command cat to include the file in your script file. Not doing this properly can cost you up to five points. 2. A listing of all your program files. Your program should use appropriate variable names, contain clarifying comments and be well formatted. Use the programs given in class and in the text as models. Use the Unix command cat (do not use more, it does not work properly in script files) to list the file containing your program. 3. An execution of a.out to verify that the program executes correctly on the provided data. 4. Use the following commands to generate the script file. typescript cat coversheet cat name.h cat name.cc 1 That is either to gwaltz@cis.udel.edu, durandet@cis.udel.edu, or slyvers@udel.edu. 5

cat bankacct.h cat bankacct.cc cat acctarray.h cat acctarray.cc cat main.cc CC *.cc a.out exit Debugging Tips 1. Do not make the mistaken assumption that once your program compiles, it is almost finished. For anything except the most trivial examples, debugging is the most time consuming aspect of program development. Plan for it! 2. Do initial debugging of code as you write it. Individual pieces are much easier to debug than a big program. Write main programs for this purpose that you ultimately discard after all debugging is done. Once the individual pieces are known to work, it much easier to debug the end product. 3. Implement overloaded output operators (or provide print methods) for each class, if only to help with debugging. 4. Verify data inputs (that is, data read from a file, argument values for functions/methods). 5. A corollary to the previous tip: debug printing of function/method args provides an informative way to trace the flow of control through your program. 6. Precisely identify where errors are occurring via debugging statements. This makes the error(s) much easier to find, but even then there will be cases in which the error remains illusive. In some cases, it will be necessary to break complicated code into simpler statements to precisely identify where an error is occurring. 7. To identify exactly where an error is occurring, it is imperative that output be printed when an output statement is executed (instead of being buffered for later output). For this reason, beginning programmers should rarely if ever use " n" for new lines in output as these do not cause the output buffer to be flushed. Used the io manipulator endl instead. It always causes the output to be flushed and the output to immediately appear on the screen or in an output file. 6

8. Use simple data when debugging. That is, files with only a few inputs, numerical values for which it is easy to compute answers to be compared with output from debugging statements, etc. One of the most common mistakes of inexperienced programmers is using overly complicated data for debugging purposes. 9. Isolate your errors with debugging statements before asking the TA or Prof for help. 10. Finally, the most important tip of all: Start and finish before the deadline! Deadline pressures make debugging code much more error prone. Rules of the Game For programming projects, unlike labs, you are expected to do all the work on your own. Many students are tempted, especially later in the semester when they have much to do, to improperly obtain help from others. This is the most common form of academic dishonesty in computer science courses and is monitored carefully. Unfortunately, quite a few students have been referred to the Student Judicial System for such problems. So please do not resort to using the solutions of others as your own. Examples of actions that are specifically prohibited include: submitting another person s work as your own. using another person s solution as a model for your own work. except as explicitly directed, working together on an assignment, sharing the computer files or programs involved. knowingly allowing another student to look at, copy, or use one of your computer files. having a tutor or friend write code for you. Late projects will be penalized 2 n points where n is the number of days it is late. The penalty clock ticks each day at midnight. 7