Question

Create qz5.c to include all of the following function prototypes: void check1(char *, char, int *);...

Create qz5.c to include all of the following function prototypes:

void check1(char *, char, int *);
void check2(char *, char, int *);
void display(char, int);

Then, implement main() to perform the tasks below:

  1. Define a 10-element char array with initial values of any lower case letters of your selection. Values can duplicate.
  2. Define a pointer that points to the above array.
  3. Print the array completely with double spaces before each character. See screenshot below for a sample.
  4. Call check1() with three arguments:
    • First argument is the pointer defined in item 2 above.
    • Second argument is any lower case letter which is used to compared with every element of the input array.
    • Third argument is passed by address (or reference), which tells the total number of elements of the array that are smaller than the letter specified by the second argument. FYI. Letter 'a' is smaller than 'b', and 'b' is smaller than 'c', etc.

check1() must use the pointer given in its first parameter and no direct access of the array to set a value to its third parameter, which can then be accessed by main().

  1. Call display() to print two lines of message using the last two arguments of check1(). For example, if 'w' is the 2nd argument of check1(), then there are 8 elements in the given array smaller than 'w' and 2 elements is equal to or greater than 'w'.
  2. Repeat task 4 and 5, except check2() is called in task 4 with three same arguments of check1(). Here check2() also uses only the pointer that points to the array to perform exactly the same function as check1() but the way this pointer is used must be different from that of check1(). In the screenshot below, 'b' is passed as the 3rd argument and results zero elements less than 'b' and all ten are either equal to or greater than 'b'.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//******************************************************START OF PROGRAM*****************************************

#include <stdio.h>

void check1(char *, char, int *);
void check2(char *, char, int *);
void display(char, int);

void main(){
char str[10] = {"HomeworkLibster"}, *ptr, letter;
int n = 0; //used to keep track of how many elements grater than or less than input letter is in array
printf("\nEnter the letter to be compared");
scanf("%c", &letter);

ptr = str; // ptr is a pointer pointing to the array str

check1(ptr, letter, &n);
display(letter, n);

check2(ptr, letter, &n);
display(letter, n);
}

void check1(char *ptr, char letter, int *n){
*n = 0; //since n is a pointer, we have to use value at operator '*' to access its value
for(int i = 0; i < 9; i++)
if(ptr[i] < letter)
(*n)++;
}

void check2(char *ptr, char letter, int *n){
*n = 0; //since n is a pointer, we have to use value at operator '*' to access its value
for(int i = 0; i < 9; i++)
if(*(ptr + i) < letter) //uses i as a displacement for accessing values from ptr
(*n)++;
}

void display(char letter, int n){
printf("\nThere are %d elements in the given array lesser than '%c' and %d elements equal to or greater than '%c'", n, letter, 10 - n, letter);
}

//*****************************************************END OF PROGRAM*****************************************************

The above is the implementation of the functions check1() and check2()

check2() uses its character pointer (ptr) in a different way than check1(), because it uses the value at operator '*' and the displacent 'i' to calculate the address of each of its elements and then display its value - *(ptr + i)

Add a comment
Know the answer?
Add Answer to:
Create qz5.c to include all of the following function prototypes: void check1(char *, char, int *);...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • implement the following function: void BuildString(int argc, char* argv[]); 1. Arguments passed through the function. Concatenate...

    implement the following function: void BuildString(int argc, char* argv[]); 1. Arguments passed through the function. Concatenate the strings arguments using strcat, display the concatenated string. 2.. If only one argument passed, display the string. 3. If no argument passed, display the message, no argument passed. In main do the following: 1. Call the function BuildString, passing the proper arguments (argc and argv).

  • (C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element...

    (C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to the element 1 of the new array. Element 1 of the argument array should be copied to element 2 of the new array, and so forth....

  • C++ The Function's Specification You will be writing a function with this specification: void quicksort void*...

    C++ The Function's Specification You will be writing a function with this specification: void quicksort void* base size t n, size t bytes, int compar (const void* const void*) Precondition base is a pointer to the first component of an array with at least n elements The component type of the array may be any type at all, and the parameter bytes must be the number of bytes in each component of the array. The fourth parameter compar, must be...

  • must be done in C You will implement a function that matches one of the prototypes...

    must be done in C You will implement a function that matches one of the prototypes below. int maxArray(int size, int* arr); int maxArray(int size, int arr]); The first parameter is the number of elements in the array. The second parameter is an address to the beginning of an int array. In the body of the function, use a looping structure to identify and return the maximum (largest number) of the array. NOTE: The maximum of the same number, say...

  • The main(int argc, char *argv[]) function will perform the following: • Evaluate whether value in argc...

    The main(int argc, char *argv[]) function will perform the following: • Evaluate whether value in argc is greater or equal to 3. • If it is not, then print the following message: Incorrect number of arguments - please call with assignment min max where assignment is the name of your executable and min/max define the range of numbers for your array. • If argc is ≥ 3 convert the values for min and max into integers and store them in...

  • in c++ please Assignment Instructions: MAIN FUNCTION: Ask the user how many students were surveyed.   Call...

    in c++ please Assignment Instructions: MAIN FUNCTION: Ask the user how many students were surveyed.   Call a function called makeArray to define an array of integers with the number of elements equal to the number of students surveyed. Call a function called getStudentData to allow the user to enter the number of hours each student spent watching Netflix into the array. Call a function called getAverage to calculate and display the average of the hours entered. Call a function called...

  • Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int...

    Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int *a2) Write a program addition.c that reads in an array (a1) of numbers, and creates a new array (a2) of numbers such that the first and last numbers of a1 are added and stored as the first number, the second and second-to-last numbers are added and stored as the second number, and so on. You need to check for even and odd length of...

  • Here's an assignment that'll give you some practice with pointers. All you have to do is...

    Here's an assignment that'll give you some practice with pointers. All you have to do is write a program that allows the user to populate an array of doubles (5 values) by calling the function InitArray. After the user has entered all the values, then call the function DispRevArray to display the array in reverse. Main will create and allocate space for an array of type double for 5 elements. Then you will create and allocate a pointer that will...

  • #include<stdio.h> #include<stdio.h> int main(){ int i; //initialize array char array[10] = {“Smith”, “Owen”, “Kowalczyk”, “Glass”, “Bierling”,...

    #include<stdio.h> #include<stdio.h> int main(){ int i; //initialize array char array[10] = {“Smith”, “Owen”, “Kowalczyk”, “Glass”, “Bierling”, “Hanenburg”, “Rhoderick”, “Pearce”, “Raymond”, “Kamphuis”}; for(int i=0; i<8;i++){ for(int j=0; j<9; j++){ if(strcmp(array[j],array[j+1])>0){ char temp[20]; strcpy(temp,array[j]); strcpy(array[j],array[j+1]); strcpy(array[j+1],temp); } } } printf(“---------File Names---------\n”); for(inti=0; i<9; i++){ printf(“\t%s\n”,array[i]); } printf(-------5 Largest Files according to sorting----\n”); for(int i=0;i>=5;i--) { printf(“\t%s\n”,array[i]); } return0; } Consider the "sort" program (using with void* parameters in the bubblesort function) from the week 10 "sort void" lecture. Modify it as follows...

  • C++ Array Expander and Element Shifter Thank you so much to anybody that can help! Here...

    C++ Array Expander and Element Shifter Thank you so much to anybody that can help! Here are our two homework prompts: PART A: Array Expander Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is twice the size of the argument array. The function should copy the contents of the argument array to the new array and initialize the unused elements of the second array with 0....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT