C o m p u t e r   S c i e n c e   D e p a r t m e n t

2005 NJIT High School Programming Contest

Friday, March 18, 2005

Sample Code

Attached you may find some sample code that one could use to read simple data (integers) from a disk file and write information into another disk file. The default file name for reading for all these programs is njit and the output file is for some programs njito. Each one of the programs reads an integer n from the input file, and subsequently reads n integers from the input file, adds these n numbers up, and prints their sum into the output file or the standard output.

We tested the C code (njit.c) and C++ code (njitcpp.cpp) under Visual C++ 6.0. All C and C++ code, including njitcc.cc also compiles and executes fine under other compilers (e.g. gcc under Sun/Solaris or PC/Linux). We tested the java code under Sun/Java using command line options.

Attached you may also find some sample code that one could use to read simple data (pairs of strings) from a disk file and write back the pairs into another disk file. The default file name for reading for all these programs is njit2 and the output file is njito2. Each one of the programs reads an integer n from the input file, and subsequently reads n pairs of strings from the input file, and prints them into the output file. The java program uses Java Strings, the C++ program uses character strings (and assumes that string pairs are at most 10 characters long).

We didn't do much of serious testing, so beware.