

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Programming assignment 1 for csci 2230, where students will become familiar with the linux environment, text editor, and compiler. The goal is to write an object-oriented program that reads a binary file and displays its content in decimal, octal, or hexadecimal. Students must handle errors and display the ascii character equivalent of the previous 10 bytes, aligning them with the previous line.
Typology: Assignments
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Goals You will become familiar with the Linux environment, text editor, and compiler. Additionally, you will learn how to open, read, and close binary files. The program will read a file and display the result in decimal, octal or hexadecimal. You shall implement your solution on the einstein Linux server. Your solution shall be object oriented. Your main function must be minimal; only instantiate the necessary objects, invoke the member functions of those objects, and possibly invoke a few free functions. This program is to be written individually.
1. Startup On program startup, the first argument will be a dash, followed by either a d , o , or x , indicating the mode of the display. A d indicates base 10, o indicates base 8 and x indicates base 16. The second argument is the name of the file to be displayed. If the command line arguments are incorrect or missing, you shall provide an informative error message and terminate your program. Do not prompt for any additional information from the user. Open and read the file, displaying 10 bytes in the indicated mode with 2 spaces between each byte. Display 5 spaces and then the ASCI character equivalent of the previous 10 bytes. Do not attempt to display the ASCII character equivalent for bytes with a value less than 32 10. These characters are generally regarded as control characters and some have “nasty” side effects if displayed. Display a “space” for these characters. Move to a new output line and continue until encountering the end-of-file. The ASCII character equivalent for the last line shall align with the ASCII character equivalent for the previous line. 2. Example The following is an example of how your program will be called hw1 -d testfile.dat If testfile.dat contains abcABC12345def your program should display 97 98 99 65 66 67 49 50 51 52 abcABC 53 100 101 102 10 5def depending upon how the file was created, you may or may not see the new-line character (decimal 10) at the end of the file. 3. Deliverables Be sure to test your program carefully. It should handle most reasonable errors - when in doubt, ask. Submit a printout of your program, and a copy of your makefile in a manila envelope with a completed coversheet attached to the front. The required coversheet is available on my web site. Copy an executable version of your program named hw1 into your home directory. (Note: you cannot name your working homework 1 directory ” hw1 ”, since you will be moving the executable file to your home directory.) Make sure the permissions for hw1 are set correctly by executing the command chmod go+rx hw1 after you copy the executable to your home directory. You must also set read and execute permission on your home directory, by entering the following two commands from your home directory. cd chmod go+rx.
4. Additional Information Command Line Arguments As defined in the C++ standard, there are only two valid forms of the function header for function main : int main( void ) **int main( int argc, char argv ) The first form is the form used throughout CSCI 1250 - CSCI 1260. However, if you need to retrieve the parameters entered on the command line, you must use the second form, where argc is the number of command line arguments argv may be interpreted as an array of c-style strings Note that both argc and argv both include the name of the file that is currently being executed. For example, the following command myprogram 5 Pine will result in the following values: argc: 3 argv[0]: myprogram argv[1]: 5 argv[2]: Pine For further information, see the demonstration program in my directory: ~pine/2230/command_line Converting String Values to Integers and Doubles Two functions are available in the C standard library to convert c-style strings to numeric values: **strtol( char *aStr, char endCh, int base ) returns the long integer value of aString *strtod( char aStr, char ** endCh ) returns the double value of aString where aStr is a pointer to a c-style string endCh is a pointer to the character in the string that terminated the conversion. If you don’t want the pointer supply NULL base is the number base to use Note: you must include the header file stdlib.h Processing Binary Files Under Unix/Linux, all files are just a stream of bytes. For this program, the significance of processing the file as a “binary” file is that no conversion takes place on reading the file, i.e. no conversion takes place on the control characters. See the handout “ C++ File Classes ” for details and examples of open , close , and read member function of the class fstream as well as the public member data of class ios.