Important Notes: There are t wo parts in this assignment. The C source program for Part (a) of this assignment should be in a file called p2a.c . Similarly, the C source program for Part (b) of this assignment should be in a file called p2b.c

Description of Part (a):

You are required to write a C program that accepts t wo decimal integers, say d and r. You may assume that the first decimal integer d is nonnegative and that the second decimal integer r which represents the radix, will be one of 2, 3, 4, . . ., 15, 16. The program should convert the first decimal integer d into its representation in radix r and print the result.

Examples:

(i) Suppose the first decimal in t e ger is 138 and the second decimal integer is 16. In this case, the output produced by your program should be 8A, which is the hexadecimal (radix 16) representation of the decimal integer 138.

(ii) Suppose the first decimal integer is 284 and the second decimal integer is 13. In this case, the output produced by your program should be 18B , which is the radix 13 representation of the decimal integer 284. (In base 13, the digits used are 0, 1, 2, . . ., 9, A, B and C, where A, B and C represen t 10, 11 and 12 respectiv ely .)

Your program should be written so that it handles just one pair of integers. Thus, the ou tline for your program is as follows. (Note that no error checks are n e eded.

1. Prompt the user to t yp e t wo decimal integers.

2. Read the t wo integers.

3. Convert the first integer into its representation in the radix specified by the second integer.

4. Print the representation and s top .

Your program must read the t wo integers from stdin and write the answer to stdout. You may assume that when prompted, the user will t yp e t wo integers separated by one or more s p ac es.

Note: Recall that for any radix r 2, the digits to be used are 0, 1, . . ., r 1. Use the letters A, B, C, D, E and F to represen t 10, 11, 12, 13, 14 and 15 respectively, as done in the hexadecimal system. Thus, representations in radix 11 can use the digits 0, 1, . . ., 9, A; representations in radix 12 can use 0, 1, . . ., 9, A, B, and so on.

Description of Part (b):

You are required to write a C program to carry out a strict-left-to-righ t evaluation of an arithmetic expression consisting of integer constants and the operators +, , , and / . Here, the operator / denotes integer division; that is, the remainder is discarded. In a strict-left-to-righ t evaluation, there is no notion of precedence. For example, the value of the expression 6 + 4 3 when evaluated in a strict-left-to-righ t fashion is 30. (Under usual precedence rules, where multiplication has higher precedence than addition, the value of the above expression would be 18.) Similarly, the value of the expression 6 + 4 3 / 7 9 when evaluated in a strict-left-to-righ t fashion is 5. Here is some additional information about the input.

1. Each input expression is terminated by the newline ( n ) c haracter.

2. There may be zero or more spaces between successive non-blank characters of an expression.

3. You may assume that the given expression is valid; that is, it satisfies all of the following conditions.

(a) The expression consists only of integer constants, the operators +, , , / and spaces. In particular, the expression wont contain paren theses.

(b) Each integer constan t in the expression consists of only one decimal digit.

(c) The expression begins with an integer constan t , without any preceding sign.

(d) In the expression, integer constants and operators alternate.

Note that an expression consisting of a single digit integer constant, without any op erators, is a valid expression.

The outline of your C program is as follows.

1. Prompt the user for an e x pres sion .

2. Read the expression character by character and carry out a strict-left-to-righ t evaluation of the expression.

3. Print the value of the result obtained in Step 2 and stop .

Thus, each time your program for Part (b) is executed, it should handle just one expression. As in part (a), bear in mind that your program reads its input from stdin and writes its output to stdout . As in Part (a), no error checks are needed.

Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.