Project 2 Overview Start Part 1 Today Part 2 [Optional] later Due: On or before last class.
-
Upload
leo-parker -
Category
Documents
-
view
216 -
download
0
Transcript of Project 2 Overview Start Part 1 Today Part 2 [Optional] later Due: On or before last class.
![Page 1: Project 2 Overview Start Part 1 Today Part 2 [Optional] later Due: On or before last class.](https://reader036.fdocuments.net/reader036/viewer/2022062518/56649e7d5503460f94b8002f/html5/thumbnails/1.jpg)
Project 2 Overview
Start Part 1 Today
Part 2 [Optional] later
Due: On or before last class
![Page 2: Project 2 Overview Start Part 1 Today Part 2 [Optional] later Due: On or before last class.](https://reader036.fdocuments.net/reader036/viewer/2022062518/56649e7d5503460f94b8002f/html5/thumbnails/2.jpg)
Try the ATM Demo Program Again• Run ATM.exe and log in as test, 111
– Try all the menu choices– Exit
• Rerun and log in as admin, 999 – Choose hidden menu choice A to go to admin mode– view sorted and unsorted records– add a new customer, delete a customer
![Page 3: Project 2 Overview Start Part 1 Today Part 2 [Optional] later Due: On or before last class.](https://reader036.fdocuments.net/reader036/viewer/2022062518/56649e7d5503460f94b8002f/html5/thumbnails/3.jpg)
![Page 4: Project 2 Overview Start Part 1 Today Part 2 [Optional] later Due: On or before last class.](https://reader036.fdocuments.net/reader036/viewer/2022062518/56649e7d5503460f94b8002f/html5/thumbnails/4.jpg)
The ATM Simulator manages two files
![Page 5: Project 2 Overview Start Part 1 Today Part 2 [Optional] later Due: On or before last class.](https://reader036.fdocuments.net/reader036/viewer/2022062518/56649e7d5503460f94b8002f/html5/thumbnails/5.jpg)
New Skills Needed
• Working with ASCII Art
• How to append to an existing file– ofstream trans(“transactions.txt”, ios::app);
• Accessing Date/Time
![Page 6: Project 2 Overview Start Part 1 Today Part 2 [Optional] later Due: On or before last class.](https://reader036.fdocuments.net/reader036/viewer/2022062518/56649e7d5503460f94b8002f/html5/thumbnails/6.jpg)
Working with ASCII Art• Visit www.schnoggo.com/figlet.html
– Type in text and choose a font
• Copy into your program’s banner( ) fn – add cout<<" "<<endl;
• If a single \ appears in your figlet it may cause problems– Do a Global Replace of single \ with \\
![Page 7: Project 2 Overview Start Part 1 Today Part 2 [Optional] later Due: On or before last class.](https://reader036.fdocuments.net/reader036/viewer/2022062518/56649e7d5503460f94b8002f/html5/thumbnails/7.jpg)
Working with ASCII Art• For Example:
• After replacing \ with \\:
![Page 8: Project 2 Overview Start Part 1 Today Part 2 [Optional] later Due: On or before last class.](https://reader036.fdocuments.net/reader036/viewer/2022062518/56649e7d5503460f94b8002f/html5/thumbnails/8.jpg)
What does function deposit have to do?
• List the steps– – – – – – –
![Page 9: Project 2 Overview Start Part 1 Today Part 2 [Optional] later Due: On or before last class.](https://reader036.fdocuments.net/reader036/viewer/2022062518/56649e7d5503460f94b8002f/html5/thumbnails/9.jpg)
Pseudocode for Deposit Functiondeposit( ): let customer add money to their account
1. Ask the customer how much money to deposit2. read the customer’s money value (& check valid) 3. Get the current balance from transactions file4. Calculate new balance5. Print a a receipt (using receipt function)6. append an entry to the end of the transactions.txt file with the
appropriate information and transaction code
![Page 10: Project 2 Overview Start Part 1 Today Part 2 [Optional] later Due: On or before last class.](https://reader036.fdocuments.net/reader036/viewer/2022062518/56649e7d5503460f94b8002f/html5/thumbnails/10.jpg)
Appending Data to a File (step 6)• Normally, opening an output file stream
erases any existing file with the same name– ofstream outFile;– outfile.open(“transactions.txt”);
• Another way is to open the file
using the append option:– ofstream outFile;– outfile.open(“transactions.txt”, ios::app);
• Now anything you send to the file appears at the end of the pre-existing file
This would erase the existing transactions.txtfile
![Page 11: Project 2 Overview Start Part 1 Today Part 2 [Optional] later Due: On or before last class.](https://reader036.fdocuments.net/reader036/viewer/2022062518/56649e7d5503460f94b8002f/html5/thumbnails/11.jpg)
Example from deposit function
ofstream trans("transactions.txt", ios::app);
trans<<dateStr<<" "<<timeStr<<setw(8)
<<userID<<setw(6)<<'D'<<fixed<<setprecision(2)
<<setw(12)<<money<<setw(12)<<balance<<endl;
trans.close();
This information is added to the end of the file
![Page 12: Project 2 Overview Start Part 1 Today Part 2 [Optional] later Due: On or before last class.](https://reader036.fdocuments.net/reader036/viewer/2022062518/56649e7d5503460f94b8002f/html5/thumbnails/12.jpg)
Reading System Date and Timechar dateStr[9], timeStr[9]; // time and date vars
// (old style C-strings)
_strdate(dateStr); // dateStr now has date_strtime(timeStr); // timeStr now has time
cout<<dataStr<<" "<<timeStr<<endl; // display
You also must include this library #include<ctime>
![Page 13: Project 2 Overview Start Part 1 Today Part 2 [Optional] later Due: On or before last class.](https://reader036.fdocuments.net/reader036/viewer/2022062518/56649e7d5503460f94b8002f/html5/thumbnails/13.jpg)
This is the easy way!
void getDateAndTime(string & date, string & time){
char dateStr[9], timeStr[9]; // time and date information_strdate(dateStr); // dateStr now has date_strtime(timeStr); // timeStr now has timedate=dateStr;time=timeStr;
}
string date, time;
getDateAndTime(date, time);
![Page 14: Project 2 Overview Start Part 1 Today Part 2 [Optional] later Due: On or before last class.](https://reader036.fdocuments.net/reader036/viewer/2022062518/56649e7d5503460f94b8002f/html5/thumbnails/14.jpg)
There is a lot more to learn…
• Read the project 2 handout carefully and follow the instructions
• Rest of the class is yours
• Challenge students– Recommend finishing part 1 by next week
• Foundation students– Only need to complete part 1