Due - SIUe

advertisement
Computer Science 145.002
Introduction to Computing for Engineers
Fall 2008
Programming Assignment 5
“Nested Functions”
Due: 7:30 AM, Thursday, October 16, 2008
In this programming assignment, you will break a large programming problem into ten self-contained functions, each of
which will solve a particular task as part of the overall programming effort. The program will deal with a technique
known as Code Division Multiple Access (CDMA), used in wireless communications to encode several simultaneous
binary transmissions in such a way that the individual messages can be deciphered upon arrival at a receiving station.
Essentially, each transmitted binary message is first converted from 0’s and 1’s into -1’s and 1’s, merely by changing
each 0 into a -1. Next, each ±1 value is multiplied by that transmitter’s “chip set” a sequence of ±1 values in the form of
a vector. The resulting vectors from all of the transmitters are then added and transmitted across the wireless media as
a CDMA signal.
For example, let’s assume that there are four transmitters using the chip sets illustrated at right: (1, 1, 1, 1), (1, 1, -1, -1),
(1, -1, -1, 1), and (1, -1, 1, -1). If the first transmitter’s original binary message is 01001111, that gets translated to -1 1 -1
-1 1 1 1 1, which, after multiplied by the first chip set (1, 1, 1, 1) yields:
-1 -1 -1 -1 1 1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
If the second transmitter’s original message is 01110101, that gets translated to -1 1 1 1 -1 1 -1 1,
which is multiplied by chip set (1, 1, -1, -1), producing:
-1 -1 1 1 1 1 -1 -1 1 1 -1 -1 1 1 -1 -1 -1 -1 1 1 1 1 -1 -1 -1 -1 1 1 1 1 -1 -1
Similarly, the third transmitter, with binary message 01100011, produces:
-1 1 1 -1 1 -1 -1 1 1 -1 -1 1 -1 1 1 -1 -1 1 1 -1 -1 1 1 -1 1 -1 -1 1 1 -1 -1 1
Finally, the fourth transmitter, with binary message 01101000, produces:
-1 1 -1 1 1 -1 1 -1 1 -1 1 -1 -1 1 -1 1 1 -1 1 -1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1
When these four vectors are added together, the final CDMA transmission is determined:
-4 0 0 0 4 0 0 0 2 -2 -2 -2 -2 2 -2 -2 0 0 4 0 0 4 0 0 0 0 0 4 2 2 -2 2
Since the transmission is wireless, every receiving station receives the entire CDMA message, but each station applies
the appropriate chip set to retrieve its intended message. The first receiving station multiplies the chip set (1, 1, 1, 1) as
a vector with each set of four incoming values, yielding (-4, 4, -4, -4, 4, 4, 4, 4). Converting every positive value to 1 and
every negative value to 0, this does, indeed, produce the first transmitting station’s binary signal of 01001111. Similarly,
the second receiving station multiplies the (1, 1, -1, -1) chip set with the incoming signal to produce (-4, 4, 4, 4, -4, 4, -4,
4), which converts to 01110101. The third receiving station multiplies the (1, -1, -1, 1) chip set with the incoming signal
to produce (-4, 4, 4, -4, -4, -4, 4, 4), which converts to 01100011. Finally, the fourth receiving station multiplies the (1, -1,
1, -1) chip set with the incoming signal to produce (-4, 4, 4, -4, 4, -4, -4, -4), which converts to 01101000.
Finally, notice that if each of the binary messages is treated as ASCII code, the four transmitted signals translate as:
Transmission #
Binary Code
Integer Version
Character
1
01001111
79
O
2
01110101
117
u
3
01100011
99
c
4
01101000
104
h
Your assignment is to write a program that uses ten functions to read in four user-specified input files, each of which
contains 32 integers with values of 0 or 1, representing four ASCII characters (eight bits per ASCII character) that are
being transmitted separately. Your program will use the chip sets on the previous page to produce a CDMA encoding of
these four signals, outputting that encoding to another user-specified file.
Once the output file is successfully produced, your program will close the output file and then, using that same file as an
input file, read in the CDMA encoding four times, applying one of the chip sets to it to recreate the original binary
transmission, which is then output to the user. A sample interaction is displayed on the reverse side of this page.
test1.txt
test2.txt
01000011
00110001
00110100
00110101
01010000
01110010
01101111
01100111
test3.txt
test4.txt
00100011
00110000
00110101
00111010
01000011
01000100
01001101
01000001
cdmaTest.txt
The ten required functions are laid out in the diagram below, followed by a table with details involving
their types, their parameters, and a description of what they should do.
main
retrieveInputFilenames
cdmaEncode
cdmaDecode
retrieveInputFilename
cdmaEncode
cdmaDecode
encodeNextBit
incrementSequence
cdmaDecodeNextChar
-4
2
-2
-2
-4
-4
2
2
-4
0
2
2
-4
-2
-2
-2
-4
0
2
0
0
4
-2
2
-4
0
2
0
-2
0
0
2
0
2
-2
2
0
0
-2
-2
0
0
2
2
0
-2
2
2
0
0
2
0
0
0
2
-2
0
0
2
0
-2
4
0
2
0
2
-2
-2
0
0
2
2
0
0
-2
-2
0
2
-2
2
0
0
-2
0
0
0
-2
-2
0
0
-2
0
-2
0
-4
2
0
-2
2
-2
0
0
2
2
0
-4
2
2
0
-2
-2
2
0
-4
2
4
-4
0
-2
-2
0
-4
2
4
2
0
0
-2
Function
Type
Parameters
Description
main
void
none
retrieveInputFilenames
retrieveInputFilename
cdmaEncode
void
string
string
4 strings, by reference
1 integer, by value
4 strings, by value
cdmaEncode
void
4 ifstreams, by reference
1 ofstream, by reference
encodeNextBit
void
incrementSequence
void
cdmaDecode
void
1 ifstream, by reference
4 integers, by value
4 integers, by reference
4 integers, by value
4 integers, by reference
5 strings, by value
Supervises the retrieval of the binary input, its
CDMA encoding, and its subsequent decoding
and output as ASCII characters.
Supervises the retrieval of the four input file names.
Handles the retrieval of one input file's name.
Opens the relevant input and oputput files, supervises the CDMA
encoding of the input files into the output file, and then closes all
of the files.
Supervises the repeated retrieval of the next bit from each of the
four input files, and the subsequent CDMA encoding and output
of the resulting four values.
Uses the parameterized chip set to retrieve the next bit from the
parameterized input file and encodes that bit into four values.
cdmaDecode
void
2 strings, by value
4 integers, by value
cdmaDecodeNextChar
void
1 ifstream, by reference
4 integers, by value
Adds the four parameterized values to the four respective sums.
Supervises the decoding of the output file with the parameterized
name by applying the four chip sets that are associated with the
four input files, whose names are also parameterized.
Supervises the character-by-character decoding of the four
characters whose ASCII representation was in the input file with
the parameterized file name, applying the parameterized chip set
to the CDMA encoding contained within the file with the pther
parameterized file name.
Retrieves eight quartets of values from the parameterized input
file, applies the parameterized chip set to each quartet, interprets
the result as a sequence of bits representing an ASCII character,
and outputs that ASCII character.
Name your project PA5_Lastname where Lastname is your last name (e.g., Fred Flintstone’s project would be
PA5_Flintstone). A zipped folder containing several sets of sample input files is available on the course Web page at
http://www.cs.siue.edu/wwhite/CS145/Syllabus.htm. Be sure to include adequate explanatory comments in your code.
Zip-compress the entire project folder and place the zipped folder on your Moodle dropbox by 7:30 AM on Thursday,
October 16, 2008.
Download