The purpose of this lab includes
• practice using pointers; and
• practice reading and writing to a file.
Let’s build an ATM! In this lab, we are going to create a pointer and pass the pointer to the methods. In addition, we are going to read and write to a file. Type the code so you can learn as much as possible. If you copy/paste the code, you will not get the hands-on practice that you need to learn programming. As you type the code, be sure that you understand what is happening and how the code works. Be especially cognizant of the three keys to pointers.
& means “address of”, and gets the memory address: &balance
* when creating a variable creates a pointer: double* ptrBalance;
* when reading a variable gets the content at that address: *ptrBalance
Create a new C++ project and enter the starting code. If you need help creating a new C++ project.
Run the code II you have any errors, debug your application. If you do not remember how to debug using Visual Studio, please open a browser, and go to http://www.google.com. Then, type “debug C++ code using Visual Studio 2015” (no quotes) in the search box. Read the websites and follow the tutorials that you find. Next, go to http://www.youtube.com and type “debug C++ code using Visual Studio 2015” (again, no quotes) into the search box. Watch the videos that describe debugging using Visual Studio 2015.
Create constants at the top of the main method. Constants make your application easier to maintain. Also, create your balance variable.
If the account.txt file exists, get the starting balance. Otherwise, create a random number for the starting balance. You will need to add some libraries so you can read/write to files and so you have access to the randomizer. Add these libraries with your includes at the top.
Now, let’s look for the file. If it exists, read the starting balance into the balance variable. If it doesn’t exist, create a random number for the starting balance.
Set a pointer to the balance. This way, we will only use four bytes of memory as we pass the balance to each of our methods. In addition, let’s add a pause so the user can see the starting balance.
Let’s create the application loop. The loop should run until the user hits the exit value that we set as a constant at the top of the main method. Also, move the pause code to the inside of the loop. The return 0; ends the method so it needs to be located after the while loop.
Run your application now. How does it look? When you press 1, you will receive a temporary message called a stub. Each choice gives you a message about what the choice will eventually do. This structure is called stubs programming. You create a stub for each branch. You have all experienced stubs programming. Do you remember going to a website and clicking on a link only to get an ‘Under Construction’ message? The website builders are using stubs programming.
Now, let’s do the first stub. In the switch statement, replace the first case with a method call.
Go to the top and create a prototype just above the main method Prototypes are also caned method forwards. Prototypes let us point to the method and then create the method below the main method. I will include the top of the main method (header) so you can see where the code should be added
Go below the main and create the first method. Notice that we are passing a pointer so the double which is eight bytes, will only require four bytes to pass across the system bus. Four bytes for the pointer is hall the size of the double. When we create pointers to our objects, we will take hundredsof bytes and point to the objects with four bytes pointers.
Go to your second case in the switch. Replace the stub with a method call to the withdrawal method.
Go to your prototypes section just above the main method and add two prototypes for the withdrawl method. We are going to overload the withdrawl method to give us more flexibility. Remember, if you have two methods with the same name but different parameters, the two methods are called an overload method.
Go to the very bottom, below the main method and below the deposit method. Add the code for the two overloads of the withdrawl method.
Go to your switch statement and delete the stubs. Replace them with the third and fourth cases.
When the user hits the exit value and the loop ends, you need to save the current balance to the file. Add this code to the very bottom. The end of the while statement and the return 0; line will be included, so you can see where the code should be added.
Run your application and test it. What happens when you choose each item on the menu? What happens if you choose a number that is not on the menu? Make a screenshot of the application running. Hold down the Alt key as you press the Print Screen key (All + Print Screen). This way you will only copy the active window (console window). Paste the screenshot into a Word document. Then copy your code from Visual Studio and paste it into the Word document below the screenshot.
Your final programming document should contain
1. a screen capture of the console with the program running, and
2. the source code for the program.
Submit the deliverables to the Week 1 Lab page underneath Assignments.
* You can also use 2CO option if you want to purchase through Credit Cards/Paypal but make sure you put the correct billing information otherwise you wont be able to receive any download link.
* Your paypal has to be pre-loaded in order to complete the purchase or otherwise please discuss it with us at firstname.lastname@example.org.
* As soon as the payment is received, download link of the solution will automatically be sent to the address used in selected payment method.
* Please check your junk mails as the download link email might go there and please be patient for the download link email. Sometimes, due to server congestion, you may receive download link with a delay.
* All the contents are compressed in one zip folder.
* In case if you get stuck at any point during the payment process, please immediately contact us at email@example.com and we will fix it with you.
* We try our best to reach back to you on immediate basis. However, please wait for atleast 8 hours for a response from our side. Afterall, we are humans.
* Comments/Feedbacks are truely welcomed and there might be some incentives for you for the next lab/quiz/assignment.
* In case of any query, please donot hesitate to contact us at firstname.lastname@example.org.
* MOST IMPORTANT Please use the tutorials as a guide and they need NOT to be used for any submission. Just take help from the material.
******************************************** Good Luck ***************************************************
Any personal information received will only be used to fill your order. We will not sell or redistribute your information to anyone.
We will try our best to resolve the issue and if still persists we can discuss for a refund in case its required.