Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Insectoid's Summer Programming Challenge
Index -> Contests
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Insectoid




PostPosted: Tue Apr 19, 2011 5:28 pm   Post subject: Insectoid's Summer Programming Challenge

So, I was watching a first-year Harvard lecture on C programming the other day. One of the assignments given to the students involved writing a program that takes a bmp file and a number n as input, and outputs the image multiplied in area by n to a bmp file. It was then that I realized that I had never done I/O on anything but text files. I didn't have a clue how other file types worked.


My challenge for compsci.ca users (primarily students, but other people to, if you want) this summer is to write a program that does something with a common file format. A bitmap is a good place to start, as it's a fairly basic format. Add a watermark, change the colors, be creative! After that, move into more involved formats such as ZIP files or other compression formats, MS Word documents, etc. Maybe even design your own format for something.

This isn't a contest. It's a challenge. Everybody wins, unless you don't learn anything. Then only everyone who learned something wins.

~Insectoid
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Tue Apr 19, 2011 5:59 pm   Post subject: RE:Insectoid\'s Summer Programming Challenge

Is turing legal? Razz
Tony




PostPosted: Tue Apr 19, 2011 6:05 pm   Post subject: RE:Insectoid\'s Summer Programming Challenge

As a file format?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Insectoid




PostPosted: Tue Apr 19, 2011 6:19 pm   Post subject: RE:Insectoid\'s Summer Programming Challenge

Use whatever language you want. The objective is that it isn't a text format- this includes .txt, .t, .cpp, .rb, etc.
Dratino




PostPosted: Wed Apr 20, 2011 8:55 pm   Post subject: RE:Insectoid\'s Summer Programming Challenge

I've worked with Microsoft BMP files before, but only to generate visual versions of certain types of output.
SNIPERDUDE




PostPosted: Thu Apr 21, 2011 12:09 pm   Post subject: RE:Insectoid\'s Summer Programming Challenge

Sounds fun, I might take a stab at it.
I haven't worked with anything other than text files as well (besides my own encrypted "text" files for program saves).
RandomLetters




PostPosted: Thu Apr 21, 2011 9:50 pm   Post subject: RE:Insectoid\'s Summer Programming Challenge

I'm trying to write the header input for a bmp file editor right now in java. How can one convert a byte array into an integer?

(stupid, stupid signed integers >>)
DemonWasp




PostPosted: Thu Apr 21, 2011 10:28 pm   Post subject: RE:Insectoid\'s Summer Programming Challenge

Err...

long i = b[3] << 24 | b[2] << 16 | b[1] << 8 | b[0]

You may have to fiddle with the indicies, depending on whether the source is big or little endian and whether or not I've screwed them up.

Alternately, DataInputStream, which you can extend to fill in the missing unsigned-int, unsigned-long logic (why they didn't include those is beyond me).
Sponsor
Sponsor
Sponsor
sponsor
btiffin




PostPosted: Thu Apr 21, 2011 11:14 pm   Post subject: Re: Insectoid's Summer Programming Challenge

Do me a favour;
code:

       identification division.
       program-id. indexing.

       environment division.
       configuration section.

       input-output section.
       file-control.
          select optional indexing
          assign to "indexing.dat"
          organization is indexed
          access mode is dynamic
          record key is keyfield of indexing-record
              alternate record key is splitkey of indexing-record
              with duplicates
          .

      *> ** OpenCOBOL does not yet support split keys **
      *>  alternate record key is newkey
      *>      source is first-part of indexing-record
      *>                last-part of indexing-record
      *>      with duplicates

       data division.
       file section.
       fd indexing.
       01 indexing-record.
          03 keyfield          pic x(8).
          03 splitkey.
             05 first-part     pic 99.
             05 middle-part    pic x.
             05 last-part      pic 99.
          03 data-part         pic x(54).


learn some of this. If you ever want to work at a bank, insurance company or government agency, understanding the above code can get you a great big resume++
Cheers
RandomLetters




PostPosted: Fri Apr 22, 2011 1:13 pm   Post subject: Re: RE:Insectoid\'s Summer Programming Challenge

DemonWasp @ Thu Apr 21, 2011 10:28 pm wrote:
Err...

long i = b[3] << 24 | b[2] << 16 | b[1] << 8 | b[0]

You may have to fiddle with the indicies, depending on whether the source is big or little endian and whether or not I've screwed them up.

Alternately, DataInputStream, which you can extend to fill in the missing unsigned-int, unsigned-long logic (why they didn't include those is beyond me).


Ah, I got it, thanks!
All the bytes were in reverse order Razz
DemonWasp




PostPosted: Fri Apr 22, 2011 1:43 pm   Post subject: Re: Insectoid's Summer Programming Challenge

btiffin @ Thu Apr 21, 2011 11:14 pm wrote:
learn some of this. If you ever want to work at a bank, insurance company or government agency, understanding the above code can get you a great big resume++


I suppose it's a good thing I never want to work for a bank, insurance company, or government agency, because that code is terrifyingly ugly. Not that these organizations generally do any better in any other language.
DtY




PostPosted: Fri Apr 22, 2011 7:44 pm   Post subject: Re: RE:Insectoid\'s Summer Programming Challenge

RandomLetters @ Fri Apr 22, 2011 1:13 pm wrote:
Ah, I got it, thanks!
All the bytes were in reverse order Razz
That's the endianess, this great computer science concept in which you can put the bytes in any order because it doesn't matter to the computer. You never put the individual bits in the byte backward though.

I might be missing something, but is there any useful reason to use little endian?
ultimatebuster




PostPosted: Sat Apr 23, 2011 11:40 am   Post subject: RE:Insectoid\'s Summer Programming Challenge

isn't this just non-text binary formats?
Insectoid




PostPosted: Sat Apr 23, 2011 11:52 am   Post subject: RE:Insectoid\'s Summer Programming Challenge

Pretty much. But you have to deal with things you usually don't with text files. Most languages have advanced functions for dealing with text (fscanf & getchar in C, for example). With non-text formats you're limited to raw byte reading and writing* (fread and fwrite in C), and all the formatting has to be done yourself. Also, doing this forces you to learn about how files are stored on a drive, which isn't really taught in school until 2nd year uni or higher (at least 2nd year- I still haven't been taught it).

*Yes, I know libraries exist to read popular formats, but that would defeat the purpose of this challenge.
ultimatebuster




PostPosted: Sat Apr 23, 2011 1:17 pm   Post subject: RE:Insectoid\'s Summer Programming Challenge

I'm not sure if Python can write non-text format via file.write

nm it can. though i think i has to be direct HEX code or via struct.

Following writes a text file in binary directly.
code:

with open("test.dat", "wb") as f: f.write('\x75\x6C\x74\x69\x6D\x61\x74\x65\x62\x75\x73\x74\x65\x72')
Display posts from previous:   
   Index -> Contests
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 25 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: