Nova Southeastern UniversityThe Farquhar Center for Undergraduate
Studies
Department of Math, Science and Technology
In the course of this assignment you will be completing a small project. You may need to answer one or more questions; answers must be placed in the source code. Be sure your name appears at the top of the source file.
Open Microsoft Visual Studio 6.0's Visual C++ 6.0 IDE. Create a New Project (use the File Menu) and select the Projects tab if necessary. Choose a Win32 Console Application for this assignment. You must give each project a name and a location. Set the location first to C:\YourLastName\ (remember to substitute your name), then enter the project name as Lab_2. The project name will be appended to the location entry, creating a folder for the project. Click OK and select Empty Project in the next dialog, then click Finish. A confirmation dialog should appear requiring one more click.
Again, use the File menu and select New. This time, we want a new File - a new C++ Source File, named Lab_2. Make it so! The focus should go to a new document window in the IDE where you can begin entering your source code.
Begin by entering the following:
//Lab 2 - A simple bank account project //Programmer: your name goes here //Date: the date goes here //Compiler: Microsoft Visual C++ 6.0 #include <iostream> #include "baccount"int main(){ bankAccount one("Ima Merchant", 1000.00); one.withdraw(400.66); cout << one.name() + " has balance: " << one.balance() << endl; return 0; }
Compile this file (see the Build menu) and verify that it compiles properly. Hmmm... There may be a problem with the inclusion of baccount.
--------------------Configuration: Lab_2 - Win32 Debug-------------------- Compiling... Lab_2.cpp c:\YourLastName\lab_2\lab_2.cpp(7) : fatal error C1083: Cannot open include file: 'baccount': No such file or directory Error executing cl.exe.
When an include file is specified inside quotes (rather than angle brackets), the compiler looks in the project folder for the specified file. In this case, it probably is not there. There are actually three files that need to be placed in the folder (because the file baccount includes two other files), baccount, baccount.h, and baccount.cpp. Get these files and place them in the project folder. They will need to be unzipped. Two free zip utilities can be obtained at these URL's. Both are called Freezip, but they are different products. This one has a windows style interface and takes forever to download if you have a slow connection. This one is small and works by right-clicking on files and folders after it is installed.
You should be able to compile the project at this time.
To run the program, we need to link (to create the exe file) and then ask the operating system to load and run the result. Click the Build command (Build menu) and verify that linking takes place. This is what I see in my Build window:
The Build menu has an item to Execute the program. Do that now. Does the output appear to be correct?
Modify the program so the name on the account and the initial deposit can be entered by the user (at run-time). A sample session appears next:
Enter the account name: Iampoor Enter the starting balance: 100 Iampoor has balance: -299.34
Be sure that you specify only a single word for the account name. Later we will learn how to read a name with spaces into a single string variable.
Assuming you are successful, modify the program so a single deposit and then a single withdrawal can be entered by the user (remove the line that makes a 400.66 withdrawal).
Enter the account name: Singlewordsonlyplease Enter the starting balance: 100 Deposit: 100 Withdrawal: 25 Singlewordsonlyplease has balance: 175
Here is a question. Is it necessary to place the line, #include <string>, in your program? The correct answer is "No." Explain why it is unnecessary in this case. Place the include statement in the program and add a comment next to with your explanation as to why it can be left out. (Incidentally, you should have this line even if it is not technically necessary because you are using the string class - always include the includes needed by your program.)
Can you format the output so it is displayed as money? If not, find out how, then do it! You might need to include an additional set of files.
Be sure your name has been included at the top of the program in a comment and then obtain a printed copy of your program and turn it in at the end of class.
Save, Clean, and then exit Visual Studio. If you want to save your work to floppy, copy the folder in C:\YourLastName to your floppy disk. You should delete your project folder from the hard drive before leaving your workstation.