a | b | c | d | a | b |
b | c | d | a | b | c |
c | d | a | b | c | d |
d | a | b | c | d | a |
a | b | c | d | a | b |
Your job is to write the program src/checkerboard.cpp, which reads five integers from standard input. The first four are the parameters R, C, SC and CS, as defined above. The fifth parameter is a width W. Your program should print out the specified checkerboard such that each element of the grid is printed as a (W * W) square. Here are some examples:
UNIX> bin/checkerboard 5 6 a 4 1 abcdab bcdabc cdabcd dabcda abcdab UNIX> bin/checkerboard 5 6 a 4 3 aaabbbcccdddaaabbb aaabbbcccdddaaabbb aaabbbcccdddaaabbb bbbcccdddaaabbbccc bbbcccdddaaabbbccc bbbcccdddaaabbbccc cccdddaaabbbcccddd cccdddaaabbbcccddd cccdddaaabbbcccddd dddaaabbbcccdddaaa dddaaabbbcccdddaaa dddaaabbbcccdddaaa aaabbbcccdddaaabbb aaabbbcccdddaaabbb aaabbbcccdddaaabbb UNIX> bin/checkerboard 4 40 J 20 3 JJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]JJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]] JJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]JJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]] JJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]JJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]] KKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]JJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]JJJ KKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]JJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]JJJ KKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]JJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]JJJ LLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]JJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]JJJKKK LLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]JJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]JJJKKK LLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]JJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]JJJKKK MMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]JJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]JJJKKKLLL MMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]JJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]JJJKKKLLL MMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]JJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]JJJKKKLLL UNIX> bin/checkerboard 4 40 0 2 3 000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111 000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111 000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111 111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000 111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000 111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000 000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111 000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111 000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111 111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000 111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000 111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000111000 UNIX>Error checking: Your program should print the same output as mine on standard error if too few arguments are given, or if they are not numbers. It should exit silently if any of the parameters is less than or equal to zero, and if the ASCII value of the starting character plus the cycle size is greater than 127.
Fortunately, you're in CS202, and Sheri has offered you a quarter of her grant money to convert those files into a more palatable format. $25 isn't a huge amount of money, but you love your sister, and this shouldn't take you long, so you agree. You are to write the program src/moonglow.cpp which reads a file in Moonglow's format on standard input, and prints a very simple output.
Here's Moonglow's format. The text file is composed of words. If a word is a number, then that is a student's score on a question, so you add it to the student's exam score. If the word is not a number, but is the word "NAME", then the next word is the student's name (Moonglow only uses first names -- last names are corporate and impersonal). If the word is "AVERAGE", then you start reading numbers until you read a word that is not a number (or is the end of the file). You average all of those numbers and add that to the score. Since Moonglow is a little scatterbrained, sometimes a number does not follow "AVERAGE." In that case, you ignore the "AVERAGE".
When you are done reading the file, your program should print the student's name, a space, and the student's score. Just use cout for this -- nothing exciting.
File | Contents | Correct output |
data/test-1.txt | NAME Fred |
Fred 0 |
data/test-2.txt | NAME Dontonio 8.6 16.2 |
Dontonio 24.8 |
data/test-3.txt | I miss Starrlight!! 15 NAME Frank |
Frank 15 |
data/test-4.txt | AVERAGE 10 15 20 NAME Luther 10 Starrlite!! |
Luther 25 |
data/test-5.txt | NAME Baby-Daisy AVERAGE 3 4 5 6 AVERAGE 7 8 9 Where's Starrlite!! |
Baby-Daisy 12.5 |
data/test-6.txt | Starrlite AVERAGE Starrlite!!! NAME Starrlite AVERAGE 55 Starrlite!!! Starrlite AVERAGE Starrlite 5 6 7 |
Starrlite 73 |
Some comments on the examples. First, the file doesn't have to have any scores, like data/test-1.txt. Second, you should use doubles and not integers. Third, the "NAME" can appear anywhere, and can be on a different line than the name, as in data/test-3.txt. Last, the "AVERAGE" can have zero numbers after it, as it does twice in data/test-6.txt. Thus, in the file, the score is 55, from the second "AVERAGE", plus 5, 6 and 7, which equals 73.
The first 30 tests are for checkerboard. The remaining 70 are for moonglow.