Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Hello, hope all is well. CAN YOU PLEASE SEE THE SAMPLE OUTPUT AND THE PROGRAM BELOW. PLEASE HELP TO MAKE SURE THIS IS THE

C++

Hello, hope all is well.

CAN YOU PLEASE SEE THE SAMPLE OUTPUT AND THE PROGRAM BELOW. PLEASE HELP TO MAKE SURE THIS IS THE MOST EFFICIENT WAY....PLEASE ADVISE AND LET ME KNOW OF ANY CHANGES TO MAKE THIS PROGRAM MORE EFFICIENT BY USING LESS MEMORY....

// Sample OUTPUT

MENU

1. Calling extractSmallestEvenDigitInfoYourName()

2. Quit

Enter an integer for option + ENTER: 6

Wrong Option!

MENU

1. Calling extractSmallestEvenDigitInfoYourName()

2. Quit

Enter an integer for option + ENTER: 1

How many integers? 3

Enter integer #1: 1004

Enter integer #2: -2111

Enter integer #3: 80645

The original array:

1004

-2111

80645

Calling extractDigitExistenceInfoYourName()

After the function completed and returned the info

The smallest even digit is 0; and 0 is seen 3 time(s) in the following values:

1004 8

0645

MENU

1. Calling extractSmallestEvenDigitInfoYourName()

2. Quit

Enter an integer for option + ENTER: 1

How many integers? 4

Enter integer #1: 1004

Enter integer #2: -2111

Enter integer #3: 602400

Enter integer #4: 80645

The original array:

14

-2111

24

8452

Calling extractDigitExistenceInfoYourName()

After the function completed and returned the info

The smallest even digit is 2; and 2 is seen 3 time(s) in the following values:

-2111

24

8452

MENU

1. Calling extractSmallestEvenDigitInfoYourName()

2. Quit

Enter an integer for option + ENTER: 1

How many integers? 5

Enter integer #1: 1

Enter integer #2: -3

Enter integer #3: 5

Enter integer #4: -7

Enter integer #5: 9

The original array:

1

-3

5

-7

9

Calling extractDigitExistenceInfoYourName()

After the function completed and returned the info

There are no even digits.

#include #include using namespace std; bool extractEvenDigitCount(int val, int &minEvenVal, int &count) { int currDigit; bool newSmallEvenIntFound = false; /*If new small even integer is found, then it will be true */ do { currDigit = val%10; /*Extract the digit from the number */ val = val/10; if(currDigit < 0) currDigit = -currDigit; /* Invert the sign if found -ve digit */ if(currDigit % 2) continue; /* If not even digit continue with next digit */ /* If current digit is even and its value is less than current smallEvenValue, then overwrite the smallEvenValue with the current digit. Or for the first number in array smallEvenValue will be -1, so overwrite the current digit as the first small even digit. */ if((currDigit % 2 == 0) && ((currDigit < minEvenVal) || (minEvenVal == -1))) { minEvenVal = currDigit; count=1; /* Start count from 1 */ newSmallEvenIntFound = true; /*Make new small even digit found flag true, so that the counters for the previous small digit can be made zero by calling resetCounter */ } else if(currDigit == minEvenVal) count++; /*If current digit matches with the small even digit then increment the counter */ }while(val); /*Continue until val becomes zero */ return newSmallEvenIntFound; }

void resetCounters(int count[], int range) {/* Reset the count for the previous counters, when another small even integer is found */ for(int i = 0; i < range; i++) count[i] = 0; }

void extractSmallestEvenDigitInfoYourName(int arr[], int size) { int *count = new int [size]; resetCounters(count, size); int minEvenVal = -1; for(int i = 0; i < size ; i++) { /*If a new small digit is found, then reset previous small digit counters to zero */ if(true == extractEvenDigitCount(arr[i], minEvenVal, count[i])) resetCounters(count, i); } int totalCount = 0; for(int i=0;i

int main() { int choice, size, *arr; while(1) { cout<<"MENU"<>choice; if(choice == 2) exit(0); if(choice != 1) { cout<<"Wrong option!"<>size; arr = new int [size]; for(int i = 0; i< size; i++) { cout<<"Enter integer #"<>arr[i]; } cout<<"The original array :"<

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 C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions

Question

=+18.7. Reconsider Problem 12.12.

Answered: 1 week ago