Starting from:

$34.99

CSE131 1st Mid-term Exam Solution

C COMPUTER PROGRAMMING(I)

Exam rules
● Only Dev-C++ can be used for the exam.
● If your codes cannot be compiled by Dev-C++, it is considered as syntax error.
● Please write all your codes as a c source file named after your student ID.
● If your codes cannot output the desired result, your points will be deducted.
● It is forbidden to search for information during the exam.
● The cheaters will get zero point.


Please design a program to complete the following problems.

a. (20 points)
Roman numerals are represented by seven symbols: I, V, X, L, C, D and M.

Symbol Value
I 1
V 5
X 10
L 50
C 100
D 500
M 1000
For example, 2 is written as II in Roman numeral, just two one's added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II.
However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX.

There are six instances where subtraction is used:
⚫ I can be placed before V and X to get IV (4) and IX (9).
⚫ X can be placed before L and C to get XL (40) and XC (90).
⚫ C can be placed before D and M to get CD (400) and CM (900).
Please let the user give an integer, convert it to a roman numeral.
Note:
(1) 1 <= integer <= 3999.
(2) This question only can use the switch statement to do decisionmaking.
(3) Go to next question if the user enters 0.

Sample output:



A palindromic number is a number that remains the same when its digits are reversed. For example, 12321 is a palindrome while 1232 is not. Because 12321 reads the same forward and backward.


Please let the user give an integer, determine whether it is a palindrome.
Note:
(1) 1 <= integer <= 214748364.
(2) Go to next question if the user enters 0.

Sample output:




⚫ The first day of the given year
Note:
(2) The first day of the perpetual calendar is 0001/01/01.
(4) If a year has 366 days, it is called a leap year.
(5) If the year is divisible by 4 and 400, but not by 100, it is a leap year.
(6) Go to next question if the user enters 0/0/0.

Sample output:

A base n system is a number system that uses n symbols to represent values. For example, the base 16 system uses the digits 0 through 9 with additional symbols: A, B, C, D, E, and F. These symbols represent the decimal values 10, 11, 12, 13, 14 and 15 respectively.

Symbol 0 1 2 3 4 5 6 7 8 9 A B C D E F
Value 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Please let the user give two integers M and N, use N symbols to represent M.
Note:
(1) 1 <= M <= 65535.
(2) 2 <= N <= 16.
(3) The base 15 system uses 0 to 9 with A, B, C, D, and E to represent values.
(4) The base 14 system uses 0 to 9 with A, B, C, and D to represent values.
(5) The base 13 system uses 0 to 9 with A, B, and C to represent values.
(6) The base 12 system uses 0 to 9 with A and B to represent values.
(7) The base 11 system uses 0 to 9 with A to represent values.
(8) Go to next question if the user enters (0,0).

Sample output:




Please let the user give a string of length 4 and an integer N, calculate the value of the string in the base N system.
Note:
(1) 2 <= N <= 16.
(2) Go to next question if the user enters (0000,0).

Sample output:


f. (20 points)
Please let the user give a number, determine whether it is an integer or a floating-point number.
Note:
(1) -99.999999 <= number <= 99.999999.
(2) End the program if the user enters 0.

Sample output:

More products