Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C code (3 methods) no print statements Return the character corresponding to a value. @param radix - the base you are working in (2-36) @param

C code (3 methods) no print statements

Return the character corresponding to a value. @param radix - the base you are working in (2-36) @param value - a value in the range of 0 - (radix-1) @return - character '0'..'9' or 'A'..'Z' corresponding to the given value if the value is legal in the given radix. Otherwise return character '?' char int2char (int radix, int value);

----------------------------------------------------------------------------------------

Return the value corresponding to a character. @param radix - the base you are working in (2-36) @param digit - character '0'..'9' or 'A'..'Z' or 'a'..'z' @return - value in the range of 0 - (radix-1) corresponding to the given digit if the digit is valid in the given radix. Otherwise return -1 int char2int (int radix, char digit);

--------------------------------------------------------------------------------------------------

Calculate both the quotient and remainder of a division and return the values via pointers. You may use the C operators for division ( / ) and modulus ( % ). However, you might want to write a loop to perform repeated subtraction to help you understand how you would implement this in LC3 assembly language (which has no operators for division or modulus). @param numerator - non-negative value for numerator @param divisor - a positive value to divide by @param quotient - a pointer to the location in which to store the quotient @param remainder - a pointer to the location in which to store the remainder

void divRem (int numerator, int divisor, int* quotient, int* remainder);

----------------------------------------------------------------------------------

/** Convert a string to an integer value. The string comes from the standard * input. You must read one character at a time by using the * built-in getchar() function which simply returns the next * character available in the standard input. The end of the string is signaled * by a newline character ('\ '). You MUST implement this function * recursively. That means you shouldn't have loops. For information on the * algorithm, see the Example revisited (page 3) on Sanjay's handout titled * "Number Systems" (referenced in the main page). You may assume that the * string is legal in the given radix (letters may be uppercase or lowercase). * You can also assume that the string represents a non-negative number. * Here's an example for how to test this function: *

echo "48A6" | ./testConv a2i 12

* This ensures that the string "48A6" is available for you to read from the * standard input. The first time you call getchar(), it will * return '4'. The second time, it will return '8', and so on. Eventually, it * will return '\ ' (because the echo command automatically * appends a newline character). *

This function should not print anything (you * will lose all points for this function if it does). However, you may print * stuff for your own debugging purposes as long as you remove any printing * statements before you submit.

* @param radix - the base you are working in (2-36) * @param valueOfPrefix - the integer value of the digits processed so far (the * prefix). For example, if the string is "48A6" in base 12 and you're about to * read 'A', the prefix is "48" and the integer value of this prefix is 56. * When your function is called by the main program (the testConv.c file), * this parameter is 0. * @return the number represented by the string */ int ascii2int (int radix, int valueOfPrefix);

/** Print a number in the specified radix. Use the C call putchar() * to print a single character obtained using int2char(). Do not * use any other output functions. This function MUST be implemented * recursively. Your program can not use arrays or strings in C, even if you * know about them. For information on the algorithm, see Section 3 (page * 5) on Sanjay's handout titled "Number Systems" (referenced in the main * page). See also Section A2 in the "Number Conversion" notes by Fritz * (referenced in the main page). *

This function should only print the digits * of the number. If it prints extra stuff, you will lose all points for this * function. Do not print a newline character at the end. You may print stuff * for your own debugging purposes as long as you remove any extra printing * statements before you submit.

*

Also, make sure this function does not * print leading zeroes (if it does, you will lose all points for this * function).

* @param radix - the base you are working in (2-36) * @param value - the number to convert (it will be non-negative) */ void int2ascii (int radix, int value);

--------------------------------------------------------------------

char int2char (int radix, int value) {

//Check for valid radix and value.

if (value >= 0 && value <= radix - 1){

if (value <= 9){

char c = value + 48;

return c;

}

else{

char c = 'A';

c = c + (value - 10);

return c;

}

}

return '?';

}

/** @todo implement in numconv.c based on documentation contained

* in numconv.h.

*/

int char2int (int radix, char digit) {

return -1;

}

/** @todo implement in numconv.c based on documentation contained

* in numconv.h.

*/

void divRem (int numerator, int divisor, int* quotient, int* remainder) {

}

/** @todo implement in numconv.c based on documentation contained

* in numconv.h.

*/

int ascii2int (int radix, int valueOfPrefix) {

return -1;

}

/** @todo implement in numconv.c based on documentation contained

* in numconv.h.

*/

void int2ascii (int radix, int value) {

}

/** @todo implement in numconv.c based on documentation contained

* in numconv.h.

*/

double frac2double (int radix) {

return -1.0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions

Question

2. What, according to Sergey, was strange at this meeting?

Answered: 1 week ago

Question

3. Are our bosses always right? If not, what should we do?

Answered: 1 week ago