0% found this document useful (0 votes)
53 views3 pages

hw2 2

This document provides instructions for Homework 2 in CST370. Students must submit two programs, renaming source files as instructed. For the first program, students must write code to calculate the time difference between two timestamps. For the second program, students must write code that takes a set as input and displays all possible decimal numbers, corresponding binary numbers, and subsets. Sample runs are provided as examples.

Uploaded by

api-595755064
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views3 pages

hw2 2

This document provides instructions for Homework 2 in CST370. Students must submit two programs, renaming source files as instructed. For the first program, students must write code to calculate the time difference between two timestamps. For the second program, students must write code that takes a set as input and displays all possible decimal numbers, corresponding binary numbers, and subsets. Sample runs are provided as examples.

Uploaded by

api-595755064
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

CST 370-30 – Spring 2023

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".

Important Note about submissions

• 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

This is the correct output of your program.

02:05:29

CST370 Page 1 of 3 Homework 2


Sample Run 1: Assume that the user typed the following two lines.

20:18:59
04:25:17

This is the correct output of your program.

08:06:18

Sample Run 2: Assume that the user typed the following two lines.

02:00:25
15:30:00

This is the correct output of your program.

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

This is the correct output.

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

CST370 Page 2 of 3 Homework 2


The first line indicates that the first decimal number and its binary number are “0” and “000”. Note that
the first bit ‘0’ in the binary number is for the element ‘A’, the second bit ‘0’ for the element B, and the
last bit ‘0’ for the element C. Since all three bits in the binary number are ‘0’, the corresponding subset is
“EMPTY”.
The next line indicates that the second decimal number and its binary number are “1” and “001”. The
corresponding subset is {C} because only the last bit of the binary number is ‘1’.
This way, your program should display a decimal number, its binary number, and corresponding subset
one by one. For instance, the last line indicates that the last decimal number and its binary number are “7”
and “111”. The corresponding subset is {A, B, C} because all bits of the binary number are ‘1’.

Sample Run 1: Assume that the user typed the following input.

2
CST238 CST370

This is the correct output.

0:00:EMPTY
1:01:CST370
2:10:CST238
3:11:CST238 CST370

Sample Run 2: Assume that the user typed the following input.

This is the correct output of your program.

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/

CST370 Page 3 of 3 Homework 2

You might also like