hw2 2
hw2 2
Homework 2
Due: 1/17/2023 (Tuesday) (11:55 PM)
How to turn in: Write two programs in either C++ or Java and submit them on Canvas before
the due.
You can submit your programs multiple times before the due. However, the last submission will be
used for grading.
You have to submit two programs together, especially at your last submission. If you submit, for
example, only one program at the last submission, we are able to see only that program when we
grade your homework.
Due time is 11:55(PM). Since there could be a long delay between your computer and Canvas, you
should submit it early.
When you submit your homework program, don’t forget to include "Title", "Abstract", "Name", and
"Date".
• For hw2_1, rename the source file named “main.cpp” to “main_hw2_1.cpp” (for C++)
or rename the source file named “Main.java” to “Main_hw2_1.java” for Java.
• For hw2_2, rename the source file named “main.cpp” to “main_hw2_2.cpp” (for C++)
or rename the source file named “Main.java” to “Main_hw2_2.java” for Java.
• After that, upload the renamed files on Canvas.
• If you submit your source program without changing the filenames, we can’t
differentiate different programs in a homework.
– Thus, we can’t grade your program properly.
• Please DO NOT change the name of the main procedure (“main()” for C++ and “class
Main” for Java)
1. Write a C++ (or Java) program for hw2_1 that reads two timestamps of two events from a user and
displays the difference between the two timestamps. For the program, you can assume that each
timestamp is composed of the hour (0 ~ 23), minute (0 ~ 59), and second (0 ~ 59) format. Your program
should present the difference from the second event (= second timestamp) to the first event (= first
timestamp). Note that the second event always happens after the first event and your program should
display the time difference of the events.
Sample Run 0: Assume that the user typed the following two lines.
18:45:30
20:50:59
02:05:29
20:18:59
04:25:17
08:06:18
Sample Run 2: Assume that the user typed the following two lines.
02:00:25
15:30:00
13:29:35
2. Write a C++ (or Java) program for hw2_2 that reads a number of elements in a set first. Then, your
program should read the elements of the set. After that, your program should display all possible decimal
numbers, corresponding binary numbers, and subsets one by one. For the program, you can assume that
the number of elements in a set is less than 10.
Sample Run 0: Assume that the user typed the following input. Note that there are three elements in the
set with the elements A, B, and C.
3
A B C
0:000:EMPTY
1:001:C
2:010:B
3:011:B C
4:100:A
5:101:A C
6:110:A B
7:111:A B C
Sample Run 1: Assume that the user typed the following input.
2
CST238 CST370
0:00:EMPTY
1:01:CST370
2:10:CST238
3:11:CST238 CST370
Sample Run 2: Assume that the user typed the following input.
0:0:EMPTY
[Hint]: Refer to this program to convert a decimal number to corresponding binary number -
https://www.geeksforgeeks.org/program-decimal-binary-conversion/