Program 1

advertisement
COSC 522
Programming Assignment 1
Due date: 2/18/09
Your program should be able to read two sets of integers from the keyboard input and find the
union of the two sets. These two sets represent the ids of students whose major is COSC and
Math, respectively.
Your program should start by prompting the user, “Enter the ids for all COSC students separated
by a space:” Then it should read the integers entered by the user into an array named
CoscStudents. Next, the program should prompt, “Enter the ids for all the Math students:” This
set of integers should be read into an array named MathStudents. Your program should go
through the two arrays and find the union set and store it in another array named
CoscAndMathStudents. Finally, your program will print out “All students with Math and COSC
major are:” followed by the appropriate student ids. Note that instead of using arrays, you may
use linked lists. Also note that the two sets are not disjoint, i.e. some students may have double
majors. You can use either C++ or Java.
What to turn in: You have to submit a printed version of your complete program along with
sample outputs for the following test cases:
Test case 1: The first set of ids will be 11 12 13 2 22 23 45 21 55 99 89 34 55 93 37 and the
second set of ids will be 22 33 44 55 66 77 88 99 11 12 23 34 45 56 67 78
Test case 2: The first set of ids will be 342 34 23 543 654 235 756 42 5434 53 323 64355 243
and the second set of ids will be 3424 23 443 654 335 756 42 5434 53 323 64355 243 312 999
Test case 3: The first set of ids will be 11 12 13 2 22 23 342 34 23 543 654 235 and the second
set of ids will be 11 12 13 2 22 23 342 34 23 543 654.
Test case 4: The first set of ids will be 342 34 23 543 654 235 756 42 5434 53 323 64355 243
and the second set of ids will be 342 34 23 543 654 235 756 42.
Use the Print Screen function of your computer to show the output of a working program. This is
how you can do it:
1. Run your program from the command prompt.
2. Press Alt+Print Screen. That means press the Print Screen button on your keyboard while
holding the Alt button. This will copy a screenshot of the command prompt window.
3. Open up a word document and paste. This will paste the screenshot on the document.
4. I want to see the sample output from all four testcases. If all four runs don’t fit in one
window, then use multiple screen shots to paste them onto your output document.
5. Finally, print this document along with your source code to bring to class. Also submit
the source code and the output document using black board.
6. In the next page you can see a screen shot of a running program that asks for names and
exits when a blank name is entered.
COSC 522
Programming Assignment 1
Due date: 2/18/09
Bring printouts of the source code and the output document to class. Also turn in your
source code (.cpp or .java files) and the output document using the project link in
blackboard. A copy of this assignment is also available in blackboard under Course
Information. When you are submitting using blackboard, use the ‘Attach local file’ item to
attach your source code and output file.
In addition to the above test cases, I will run your program with other undisclosed test
cases.
Download