Question

In: Computer Science

3. Write a function named "countNonAlpha" that accepts a string. It will return the number of...

3. Write a function named "countNonAlpha" that accepts a string. It will return the number of non-alphabet characters (excluding blanks) in the string.
For example, if the string is "Hello, World!", it will return 2 for ',' and '!" in the string.

4. Write a function named "deleteZeros" that takes two arguments:
a. an array of integer values;
b. an integer for the number of elements in the array;
The function will return the number of zeros that it has deleted from the array
The function should shift the contents of each element in the array whenever a zero
element is deleted
For example, if the array is defined as
int numList[] = {10, 0, 20, 30, 40, 0, 50};
The function will return 2 and shift to make the array to contain
10 20 30 40 50

5. Write a function named "reverseCase" that takes only one argument of a C-string (an array of characters that terminates with a NULL ('\0') character).
The function will change all lower cases to upper case and vice versa in that given
C-string. If the character is not an alphabet, it will be unchanged.
The function will return the number of letters that it has changed.
For example, if the array is defined as
char greeting[] = " Hello, World! ";
It will return 10 and change the array to contain
hEELO, wORLD!

Solutions

Expert Solution

#include<stdio.h>
int countNonAlpha(char *str){
   int count=0;
   for(int i=0;str[i]!='\0';i++){
char ch=str[i];
if( !((ch >= 97 && ch <= 122) || (ch >= 65 && ch <= 90)))
if(ch!=' ')
count++;
   }
   return count;
}
int main(){
   char *str="Hello, World!";
   printf("%d",countNonAlpha(str));
}

As per policy we can answer 1 question per post. Please post the remianing questions as separate post.Thanks


Related Solutions

Write a function named "characters" that takes a string as a parameter and returns the number...
Write a function named "characters" that takes a string as a parameter and returns the number of characters in the input string
C++ Please Define a function named "isAscending" that accepts a string as an input parameter and...
C++ Please Define a function named "isAscending" that accepts a string as an input parameter and returns "true" if all the characters included in the string are ordered in ascending order of their ASCII codes or the input string is a null string, and returns "false" otherwise. For example, if the string "ABXab" is passed to the function, it returns "true" because the ASCII code of 'B' is greater than 'A', 'X' is greater than 'B', 'a' is greater than...
Language: Python 3 Compose a function process which accepts a string filename. process should return a...
Language: Python 3 Compose a function process which accepts a string filename. process should return a list of records contained in the file. #define your function here # Create a blank list called `entries` and an empty string called `current_style`. # Open the file `filename`, read the data using readlines(), and close it. # Loop through each line of the file and do the following: # Strip the whitespace off of the ends of the line using the `strip` method....
Write a python function to fulfill the requirements. The function accepts a string, a current state,...
Write a python function to fulfill the requirements. The function accepts a string, a current state, edges’ information, and an accepting state. The output of the function is a boolean value verifying if the string can pass the finite state machine or not.             ### Finite State Machine Simulator in Python ### Provide s1 and s2 that are both accepted, but s1 != s2. s1 = "bdf" s2 = "bdgbdf" edges = {(1,'a') : 2,                (1,'b') : 3,       ...
Write a function named mirror_tree that accepts a pointer to the root of a binary tree...
Write a function named mirror_tree that accepts a pointer to the root of a binary tree of integers. Your function should rearrange the nodes into a mirror tree of the original tree. The mirror tree has the left and right subtrees reversed for each node. Constraints: You must implement your function recursively and without using loops. Do not construct any new BST objects in solving this problem (though you may create as many NODE* pointer variables as you like). Do...
Write a function, named isMultipleOfFive that accepts integer argument. When the function is called, it should...
Write a function, named isMultipleOfFive that accepts integer argument. When the function is called, it should display if the argument "is a multiple of 5" or "is not a multiple of 5".
In Java, write a recursive function that accepts a string as its argument and prints the...
In Java, write a recursive function that accepts a string as its argument and prints the string in reverse order. Demonstrate the function in a driver program.
Write a function called remove_punct() that accepts a string as a parameter, removes the punctuation (',',...
Write a function called remove_punct() that accepts a string as a parameter, removes the punctuation (',', '!', '.') characters from the string, and returns the number of punctuation characters removed. For example, if the string contains ['C', 'p', 't', 'S', ',', '1', '2', '1', '.', 'i', 's', 'f', 'u', 'n', '!', '\0'], then the function should remove the punctuation characters. The function must remove the characters by shifting all characters to the right of each punctuation character, left by one...
In c++ Write a function that: accepts a string and an integer as it's only arguments...
In c++ Write a function that: accepts a string and an integer as it's only arguments uses the argument to open a file for writing writes the integer to the file if it fails to open the file, returns -1 if it succeeds in opening the file, returns 0 does not interact with the user in any way does not use global variables
(java) Part 1 Write a method named compare that accepts two String arrays as parameters and...
(java) Part 1 Write a method named compare that accepts two String arrays as parameters and returns a boolean. The method should return true if both arrays contain the same values (case sensitive), otherwise returns false. Note - the two arrays must be the same length and the values must be in the same order to return true. Part  2 Write a method named generateArray that accepts an int size as its parameter and returns an int[] array where each element...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT