Assignment: The Piano Program
In this assignment you should use the pianoutl library to create a piano program. Your piano program should
display an introductory and informative message and the piano keys | |
react to keys pressed by playing a sound and flashing the appropriate piano keys | |
continue to play sounds until the user presses the designated exit key | |
once the exit key was hit, the program should clear the screen and display an appropriate "good-bye" message |
The pianoutl files can be downloaded below. A sample program might look as follows:
At the end of this file is an option to download a complete executable program to illustrate how the finished product could look.
There are several possibilities for extra credit in this assignment:
Step 1: You need to download the files pianoutl.h and pianoutl.cpp (the interface, or header, file and the implementation file).
Click here to view the header or interface file pianoutl.h Once you see the file on the screen, click on File | Save As ... and save the file under the name Z:\pianoutl.h | |
Click here to view the implementation file pianoutl.cpp Once you see the file on the screen, click on File | Save As ... and save the file under the name Z:\pianoutl.cpp |
Step 2: Once you downloaded the two files and named them appropriately, start Turbo C++ for DOS and open the file pianoutl.cpp that you just downloaded. Compile the file. If you get any errors:
Make sure you have set the C++ directory options correctly. Check by selecting Options | Directories and ensure that the Output Directory says Z:\ | |
Add the correct drive and directory to the include directive in the file pianoutl.cpp; in other words, change the line #include "pianoutl.h" to #include "Z:\pianoutl.h" in the file pianoutl.cpp |
Step 3: Type a small sample program to get a feeling for using the piano library. In other words, select File | New and type a program similar to the following:
#include "Z:\pianoutl.h" int main(void) { char cc = ' '; while (cc != ExitKey) { GetAKey(cc); TurnSoundOn(cc); WaitAWhile(400); TurnSoundOff(); } return 0; }
Save the file, compile it, and try to link it. It should compile successfully, but may not yet link correctly.
Step 4: To correctly link your program with the pianutl library you need to create a new project. To do that:
Select Project | Open Project and type a name for your project. For example, Z:\piano.prj might be appropriate. A new window titled "Project: Piano" will open at the bottom of the screen. | |
Select Project | Add Item. Select the name of your file and click on Add, then select the file pianoutl.cpp and click on Add again. When you have added these two files, click on Done. | |
If you have not yet set the C++ directory options yet, check by selecting Options | Directories and ensure that the Output Directory says Z:\. If not, type Z:\ into the Output Directory field and recompile the file Z:\pianoutl.cpp. |
Now your project should compile and link correctly to produce an executable program. Run the program and see what it does.
Step 5: Now work on completing the assignment by modifying your source code. Note that no matter which file is currently open, the files that will compile and link are only those that are in your currently open project. If you decide to rename your program file, you must remove the first file and add the new file to the current project. In other words, if you can not correctly link your program with the piano library, check whether the correct files are included in the current project, or recreate a new project.
For the first extra credit points, you need to add code to your own source code. For the second extra credit points, you need to mofify the pianoutl header file. For the third set of extra credit points, you need to modify the file pianoutl.cpp and maybe others as well.
To get a better idea about this assignment, you can download a working executable piano program that was created using the pianutl library.
Click here to download the file piano.exe. Netscape should ask you where you want to save the file. Pick an appropriate drive and directory (for example Z:\piano.exe) and save the file. You should now be able to run this file to see a working piano program.