Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C programming Question. One function is already defined and is correct (as seen in photo). However, the code is incorrect. #include #include bool isShuffled(int); int

C programming Question. One function is already defined and is correct (as seen in photo). However, the code is incorrect.

image text in transcribed

#include

#include

bool isShuffled(int);

int getNumDigits(int);

int getSmallestDigit(int);

bool lookForDigit(int, int);

int main(void) {

int num;

printf("Enter the number to check: ");

scanf("%d", &num);

if (isShuffled(num)) {

printf("Shuffled!");

} else {

printf("Not shuffled!");

}

return 0;

}

bool isShuffled(int shuffledOrder) {

bool isShuffled = true;

int numOfDigits = getNumDigits(shuffledOrder);

int smallestDigit = getSmallestDigit(shuffledOrder);

for (int place = 1; place

if (!lookForDigit(shuffledOrder, smallestDigit + place)) {

isShuffled = false;

}

}

return shuffledOrder;

}

int getNumDigits(int num) {

int count = 1;

while (num

num = num / 10;

count++;

}

return count;

}

int getSmallestDigit(int num) {

int smallestDigit = 0;

int digit = 0;

while (num != 0) {

digit = num % 10;

if (digit

smallestDigit = digit;

}

num /= 10;

}

return digit;

}

bool lookForDigit(int num, int searchDigit) {

int digit = 0;

bool foundDigit = false;

while (num != 0 || foundDigit) {

digit = num % 10;

if (digit == searchDigit) {

foundDigit = true;

}

num /= 10;

}

return digit;

}

Part 3 - Debugging Rea, Dami and Hira are working for a Telecommunications company. They developed a function that checks if a number is a shuffled version of an ordered number. For example, 917865432 is a shuffled number of the ordered 123456789 number. The function is supposed to return true if a number is shuffled, and false if the number is missing one or more numbers. It also returns false if a number is repeated more than once. The function is tested in the main function as shown below, and in lab4par3-debugging-exercise.c file on Quercus. However, the function is not working as expected. Your task is to debug the program and fix the errors. Assume the user will not enter negative numbers or numbers with 0 digits. Hint: As you may have observed the program is long, and it can be difficult to know the source of errors. As a hint, we are telling you that some of the bugs are in getNumDigits function. We suggest you isolate it and test it separately in a different .c file. The following is an example of a program you can use to test "getNumDigits" function. As you can see we are passing different values to getNumDigits to check if it works. Once you fix getNumDigits function, check getSmallestDigit and lookForDigit separately. Then, finally when you fix all the functions, check isShuffled function using the entire program. This is the benefit of using functions. You can break your code into pieces, and easily fix issues in each function regardless of the entire program. Program to test getNumDigits function

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

Beginning ASP.NET 2.0 And Databases

Authors: John Kauffman, Bradley Millington

1st Edition

0471781347, 978-0471781349

More Books

Students also viewed these Databases questions

Question

2. Identify issues/causes for the apparent conflict.

Answered: 1 week ago