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 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...
(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...
Python: Write a function named calc_odd_sum that accepts a positive integer as the argument and returns...
Python: Write a function named calc_odd_sum that accepts a positive integer as the argument and returns the sum of all the odd numbers that are less than or equal to the input number. The function should return 0 if the number is not positive. For example, if 15 is passed as argument to the function, the function should return the result of 1+3+5+7+9+11+13+15. If -10 is passes, it shall return 0. You shall run the program test the result at...
Write a complete static method named addUp that accepts, in order, an integer number and an...
Write a complete static method named addUp that accepts, in order, an integer number and an integer thisMany as parameters and that prints a complete line of output reporting all the numbers that result from adding number to itself thisMany number of times (starting at 1 and ending at thisMany). For example, the following calls: addUp(3, 5); addUp(7, 3); should produce this output: Adding up 3 for 5 times gives: 3, 6, 9, 12, 15 Adding up 7 for 3...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT