. Main Selection Process (assigned to Programmer A): The program, upon initial e
ID: 3689813 • Letter: #
Question
.
Main Selection Process (assigned to Programmer A):
The program, upon initial execution, will display the following title information and then will prompt the user to select which portion of the program they wish to work with:
--== 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):
The selection value entered by the user must be a numeric value of one, two, or zero. If any other value is entered, the user must be notified of the error and the same question prompt should be displayed (this should continue until the users enter one of the correct selections):
Invalid selection! Please Try Again.
Would you like to play with numbers or letters? Enter 1 for numbers and 2 for letters (0 to exit):
If a numeric 0 is entered, the program should end. If a numeric 1 is entered, the program will then move to the number manipulation portion of the program. If a numeric 2 is entered, the program will then move to the character manipulation portion of the program. The program will be designed to continuously run until a user finally enters the zero value to exit the program.
Numbers Selection Process (assigned to Programmer B):
If the user selects to “play with numbers” (option 1), the program will then execute the following subsequent selection criteria:
--== Playing with Numbers ==-- What would you like to do?
Add 2nd and 3rd numbers of collection entered
Average of Numbers divisible by 3 of collection entered
Multiplication of every 1st and 2nd numbers of collection entered
Resort the collection entered by sets of three Enter 1, 2, 3, or 4 (0 to return to main selection):
The selection value entered by the user must be a numeric value of one, two, three, four, or zero. If any other value is entered, the user must be notified of the error and the same question prompt should be displayed (this should continue until the users enter one of the correct selections):
Invalid selection! Please Try Again. What would you like to do?
Add 2nd and 3rd numbers of collection entered
Average of Numbers divisible by 3 of collection entered
Multiplication of 1st and 2nd numbers of collection entered
Resort the collection entered by sets of three Enter 1, 2, 3, or 4 (0 to return to main selection):
If a numeric 0 is entered, the program should return back to the main selection process. If any of the other valid selections are entered, the program will then execute a standard process of collecting numeric inputs and then it will execute the specific process selected. Each one of these process are defined further down in this assignment. For each of those processes, a calculated result will be generated and returned to this section of the program.
Depending on what process was called, two different methods of displaying the results are necessary for this portion of the program.
If a single calculated result is returned, the following prompt should be displayed with the results (where red represents the numeric answer):
Your calculated result is: #####
If a multiple results are returned, the following prompts should be written for each occurrence of a result (and should display the proper cell number):
Cell 0 contains number ##### Cell 1 contains number ##### Cell 2 contains number ##### Cell 3 contains number #####
After displaying the results to the user, the program should then re-issue the “Main Selection Process” prompt listed above in the first section.
Letters Selection Process (assigned to Programmer A):
If the user selects to “play with letters” (option 2), the program will then execute the following subsequent selection criteria:
--== Playing with Letters ==-- 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):
The selection value entered by the user must be a numeric value of one, two, or zero. If any other value is entered, the user must be notified of the error and the same question prompt should be displayed (this should continue until the users enter one of the correct selections):
Invalid selection! Please Try Again. 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):
If a numeric 0 is entered, the program should return back to the main selection process. If any of the other valid selections are entered, the program will then execute a standard process of collecting a character input and then should execute the specific process selected. Each one of these process are defined further down in this assignment. For each of those processes, a calculated result will be generated and returned to this section of the program.
The “play with letters” section of the program has a predefined string used within the manipulation process. This portion of the program needs to define and initialize this string prior to the manipulation processes. The string should be initialized with the following sentence:
"The quick brown fox jumps over the lazy dog."
This string does not need to display to the user, but will be used in each of the selected processes and then the results will be displayed to the user.
When the single calculated result is returned, the following prompt should be displayed with the results (where red represents the numeric answer):
Your calculated result is: #####
After displaying the results to the user, the program should then re-issue the “Main Selection Process” prompt listed above in the first section.
Capturing of Random Numeric Inputs Process (assigned to Programmer B):
For each of the “playing with numbers” selections, a user must enter in a collection of numbers that will then be worked upon by each of the possible processing selections. The user is allowed to enter from 1 to 10 numeric values and should be prompted to do so:
Please enter the quantity of numbers you wish to enter. Enter a number between 1 and 10:
If a numeric that is less than 1 or greater than 10 is entered, the user must be notified of the error and the same question prompt should be displayed (this should continue until the users enter one of the correct selections):
Invalid selection! Please Try Again.
Please enter the quantity of numbers you wish to enter. Enter a number between 1 and 10:
After the user selects the number of values to entered, the program should then begin collection each individual input value till the number requested is reached. On each prompt for a numeric input, the order of the number input should be displayed (red numbers represent user input values):
Please enter number 1: 5
Please enter number 2: 2
Please enter number 3: -59
Please enter number 4: 1547
Please enter number 5: 5487
Constraint: The numbers entered by a user must be stored in an array structure. Any collection of values entered by a user must be passed from one process to another via this (or another) array structure. Failure to use arrays for this assignment will have an extremely negative impact to your grade for this assessment.
After the user enters in all of the numeric selections, the process should then continue to execute the processing selection made by the user.
Capturing of Character Input Process (assigned to Programmer A):
For each the “playing with letters” selections, a user must enter a single alphabetic character that will then be then used by each of the possible processing selections. The user is allowed to enter any upper or lower case character, but no other values are allowed. The user should be prompted for this character entry as:
Please enter an alphabetic character to work with. Enter any upper or lower case character:
If a character is entered that is not a lower or uppercase letter (e.g. #, 4, %, !), the user must be notified of the error and the same question prompt should be displayed (this should continue until the users enter one of the correct selections):
Invalid selection! Please Try Again.
Please enter an alphabetic character to work with. Enter any upper or lower case character:
After the user enters the character selection, the process should then continue to execute the processing selection made by the user.
Numbers Process 1 (assigned to Programmer A)
Process one for “playing with numbers” is to take the collection of numbers entered by the user and to add every 2nd and 3rd input value. For example, if the user had entered in these 6 numeric values,
10 20 20 7 20 12
The values in red would be the ones that would be in the summation (which the result in this example would be 72).
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 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 3 (assigned to Programmer A)
Process three for “playing with numbers” is to take the collection of numbers entered by the user and to multiply every first input of a series of two by every second input of a series of two. For example, if the user had entered in these 7 numeric values:
3 5 2 14 6 55 34
The values in red (first one entered in the series of two) should be multiplied by the values in blue (second one entered in the series of two). So the calculated results for each of these in order are 15, 28, & 330. If a collection has an odd number of values, the last value should be ignored in the process. So in this example, no action occurs for value 34.
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 calculations 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.
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.
Letters Process 1 (assigned to Programmer B)
Process one for “playing with letters” is to take an inputted character value and to search through a collection of letters to find the number of occurrences greater that one. For example, if the user had entered in character value of “u” (lowercase):
"The quick brown fox jumps over the lazy dog."
Two lowercase values are present in the defined string (identified in red). This process is searching for the number of occurrences that is greater that one, so for this example, the calculated result would be the number 1 (e.g. there is one more occurrence of the letter than just a single occurrence).
Constraint: The character value used in the calculation of this process as well as the pre-defined string array used must be the ones contained inside the “Capturing of Character Input 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.
Letters Process 2 (assigned to Programmer A)
Process two for “playing with letters” is to take an inputted character value and to search through a collection of letters to find the number of occurrences that have an English lowercase vowel letter (a, e, i, o, or u) immediately occur before the inputted character. For example, if the user had entered in character value of “w” (lowercase):
"The quick brown fox jumps over the lazy dog."
The word “brown” has the letter “w” present (in red) and also has a vowel letter occurring immediately before it (in blue). So the calculated result would be 1 (e.g. for one occurrence of this condition happening).
Constraint: The character value used in the calculation of this process as well as the pre-defined string array used must be the ones contained inside the “Capturing of Character Input 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.
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.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.