subject

The program below represents decimal integers as a linked list of digits. It asks for 2 positive integers, stores them as linked lists, computes the sum, and outputs it. It then freeO's all nodes of all 3 lists. a. You must use my struct Digi tNode b. I strongly suggest that you represent the integers in little-endian order. That will make add 0) way easier. Please write: obtainPostiveInt 。numberList () o add printList o freeList Sample output: (No surprises here, it is just decimal integer addition, but these are some interesting boundary cases to make sure you handle.) C CODE (COPY/PASTE):
/**
*--- ---*
*--- byDigitAdder. c ---*
*--- ---*
*--- This file defines a C program that represents positive ---*
*--- decimal integers as linked lists of digits. It asks the user ---*
*--- for 2 integers, computes the sum, and outputs it. ---*
*--- ---*
*-*
*--- ---*
*--- Version 1a 2018 February 11 Joseph Phillips ---*
*--- ---*
**/
#include
#include
#include
#define NUM_TEXT_LEN 256// PURPOSE: To represent one digit of a decimal number.
struct DigitNode
{
int digit_; // I suggest you range this in [0..9]
struct DigitNode* nextPtr_; // I suggest you make this point to
// the next most significant digit.
};
// PURPOSE: To obtain the text of a decimal integer into array 'numberCPtr'
// of length 'numberTextLen'. 'descriptionCPtr' is printed because it
// tells the user the integer that is expected. Ending '\n' from
// 'fgets()' is replaced with '\0'. No return value.
void obtainPostiveInt(char* numberCPtr,
int numberTextLen,
const char* descriptionCPtr
)
{
// YOUR CODE HERE
}
// PURPOSE: To build and return a linked list IN LITTLE ENDIAN ORDER
// of the decimal number whose text is pointed to by 'numberCPtr'.
// If 'numberCPtr' points to the string "123" then the linked list
// returned is 'digit_=3' -> 'digit_=2' -> 'digit_=1' -> NULL.
struct DigitNode*
numberList (const char* numberCPtr
)
{
// YOUR CODE HERE
}
// PURPOSE: To build and return a linked list IN LITTLE ENDIAN ORDER
// of the decimal number that results from adding the decimal numbers
// whose digits are pointed to by 'list0' and 'list1'.
struct DigitNode*
add (const struct DigitNode* list0,
const struct DigitNode* list1
)
{
// YOUR CODE HERE
}
// PURPOSE: To print the decimal number whose digits are pointed to by 'list'.
// Note that the digits are IN LITTLE ENDIAN ORDER. No return value.
void printList (const struct DigitNode* list
)
{
// YOUR CODE HERE
}
// PURPOSE: To print the nodes of 'list'. No return value.
void freeList (struct DigitNode* list
)
{
// YOUR CODE HERE
}
// PURPOSE: To coordinate the running of the program. Ignores command line
// arguments. Returns 'EXIT_SUCCESS' to OS.
int main ()
{
char numberText0[NUM_TEXT_LEN];
char numberText1[NUM_TEXT_LEN];
struct DigitNode* operand0List = NULL;
struct DigitNode* operand1List = NULL;
struct DigitNode* sumList = NULL;
obtainPostiveInt(numberText0,NUM_TE XT_LEN,"first");
obtainPostiveInt(numberText1,NUM_TE XT_LEN,"second");
operand0List = numberList(numberText0);
operand1List = numberList(numberText1);
sumList = add(operand0List, operand1List);
printList(operand0List);
printf(" + ");
printList(operand1List);
printf(" = ");
printList(sumList);
printf("\n");
freeList(sumList);
freeList(operand1List);
freeList(operand0List);
return(EXIT_SUCCESS);
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 18:00
Determine whether the following careers would require training or college.
Answers: 1
question
Computers and Technology, 22.06.2019 21:10
Dameas communication challenge is due to which factor
Answers: 2
question
Computers and Technology, 24.06.2019 13:00
George heard about the benefits of a data warehouse. he wants to try implementing one for his organization. however, he is afraid that transferring data to the data warehouse will affect transaction time. which element ensures that transactions are not affected when moving data to a warehouse? when data is transferred to a data warehouse, the a area frees the source system to continue transaction processing.
Answers: 2
question
Computers and Technology, 24.06.2019 17:00
What are some examples of what can be changed through options available in the font dialog box? check all that apply. font family italicizing bolding pasting drop shadow cutting character spacing special symbols
Answers: 2
You know the right answer?
The program below represents decimal integers as a linked list of digits. It asks for 2 positive int...
Questions
question
Computers and Technology, 18.08.2019 17:30
question
Social Studies, 18.08.2019 17:30
question
Physics, 18.08.2019 17:30
question
World Languages, 18.08.2019 17:30
question
Mathematics, 18.08.2019 17:30
Questions on the website: 13722361