Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C programming Numbers Process 2 (assigned to Programmer B) Process two for “play

ID: 3691806 • Letter: C

Question

C programming

Numbers Process 2 (assigned to Programmer B)

Process two for “playing with numbers” is to take the collection of numbers entered by the user and to generate the average value of all the numbers that are divisible by 3. For example, if the user had entered in these 5 numeric values,

5           3           9           11         25

The values in red are each divisible by the number 3 and an average value of these numbers would be calculated (which the result in this example would be 6).

Constraint: The collection of numbers used in the calculation of this process must be contained inside the array structure used in the “Capturing of Random Numeric Inputs Process”. No global variables are to be used (but constant macros are allowed in the design). In addition, the calculated result of this process can not be displayed within this process (e.g. it must be displayed by another process). Failure to follow this constraint for this assignment will have an extremely negative impact to your grade for this assessment.

Numbers Process 4 (assigned to Programmer B)

Process four for “playing with numbers” is to take the collection of numbers entered by the user and to resort the order of the numbers in intervals of three. For example, if the user had entered in these 7 numeric values:

1           2           3           4           5           6         7

The process will then need to resort those values as such: 3            2           1           6           5          4

As you can see in the example, if a collection has any additional values that do not fit within a grouping of three, those values are to be discarded. So in this example, no action occurs for value 7 since the last interval that was divisible by three was the 6th occurrence of an inputted value.

Constraint: The collection of numbers used in the calculation of this process must be contained inside the array structure used in the “Capturing of Random Numeric Inputs Process”. The results the reordering must also be contained within an additional array structure. No global variables are to be used (but constant macros are allowed in the design). The calculated result of this process can not be displayed within this process and this additional array must be used to return the result back to another process (e.g. it must be displayed by another process). Failure to follow this constraint for this assignment will have an extremely negative impact to your grade for this assessment.

Explanation / Answer

#include <stdio.h>

void playWithLetters(char* input);
void playWithNumbers();

int main() {

   char input[] = "The quick brown fox jumps over the lazy dog.";
   int choice = -1;
   while (choice < 0 || choice > 2) {
       printf(
               "Playing with Numbers or Letters ==-- Would you like to play with numbers or letters? Enter 1 for numbers and 2 for letters (0 to exit)");
       scanf("%d", &choice);
       if (choice < 0 || choice > 2) {
           printf("Invalid selection! Please Try Again. ");
       } else if (choice == 0) {
           return 0;
       } else if (choice == 1) {
           playWithNumbers();
       } else {
           playWithLetters(input);
       }
       choice = -1;
   }
   return 0;
}

/**
* This function will be called for Letters only.
*/
void playWithLetters(char* input) {
   int choice = -1;
   char inputChar;
   while (choice < 0 || choice > 2) {
       printf(
               "What would you like to do? Find more than one occurrence of a character Find character occurrence that has a vowel before it. Enter 1 or 2. (0 to return to main selection) ");
       scanf("%d", &choice);
       if (choice < 0 || choice > 2) {
           printf("Invalid selection! Please Try Again. ");
       } else if (choice == 0) {
           return;
       } else {
           while (!((inputChar >= 'a' && inputChar <= 'z')
                   || (inputChar >= 'A' && inputChar <= 'Z'))) {
               printf(
                       "Please enter an alphabetic character to work with. Enter any upper or lower case character: ");
               scanf("%c", &inputChar);
           }
           int count = 0;
           int i = 0;
           if (choice == 1) {
               /**
               * Here we are traversing complete sentence to check the occurrences of input character.
               */
               for (i = 0; input[i] != ''; i++) {
                   if (input[i] == inputChar) {
                       count++;
                   }
               }
           } else {
               /**
               * Here we are checking if before character is vowel or not if it is we are incrementing count.
               */
               for (i = 1; input[i] != ''; i++) {
                   if (input[i - 1] == 'a' || input[i - 1] == 'e'
                           || input[i - 1] == 'i' || input[i - 1] == 'o'
                           || input[i - 1] == 'u' || input[i - 1] == 'A'
                           || input[i - 1] == 'E' || input[i - 1] == 'I'
                           || input[i - 1] == 'O' || input[i - 1] == 'U') {
                       if (inputChar == input[i]) {
                           count++;
                       }
                   }
               }
           }
           printf("Total occurrences %d", count);
       }
   }
}

/**
* This function will be called for Numbers.
*/
void playWithNumbers() {
   int choice = -1;
   int tempArr[10000];
   int numCount = 0;
   int finished = 0;
   int i = 0;
   while (finished == 0) {
       finished = 1;
       printf(
               "Please enter the quantity of numbers you wish to enter. Enter a number between 1 and 10:");
       scanf("%d", &numCount);
       int temp = 0;
       for (i = 0; i < numCount; i++) {
           printf("Please enter number %d : ", (i + 1));
           scanf("%d", &temp);
           if (temp < 0 || temp > 10) {
               break;
           }
           tempArr[i] = temp;
       }
       if (finished == 0) {
           continue;
       }
   }
   while (choice < 0 || choice > 2) {
       printf(" == Playing with Numbers ==-- What would you like to do? ");
       printf("Add 2nd and 3rd numbers of collection entered ");
       printf("Average of Numbers divisible by 3 of collection entered ");
       printf(
               "Multiplication of every 1st and 2nd numbers of collection entered ");
       printf(
               "Resort the collection entered by sets of three Enter 1, 2, 3, or 4 (0 to return to main selection): ");
       scanf("%d", &choice);
       if (choice < 0 || choice > 4) {
           printf("Invalid selection! Please Try Again. ");
       } else if (choice == 0) {
           return;
       } else {
           if (choice == 1) {
               printf("%d ", (tempArr[1] * tempArr[2]));
           } else if (choice == 2) {
               int sum = 0;
               int count = 0;
               for (i = 0; i < numCount; i++) {
                   if (tempArr[i] % 3 == 0) {
                       sum += tempArr[i];
                       count++;
                   }
               }
               printf("%d ", (count != 0 ? (sum / count) : 0));
           } else if (choice == 3) {
               printf("%d ", (tempArr[0] * tempArr[1]));
           } else if (choice == 4) {

           }
           choice = 0;
       }
   }
}

I didn't get the 4th option in numbers.