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

Part C. String Manipulation: Reverse. 1. Write a function called reverseStr that

ID: 3916930 • Letter: P

Question

Part C. String Manipulation: Reverse. 1. Write a function called reverseStr that accepts as a parameter a char array (or char pointer) and returns a void type. The function reverses the contents of the array (or string) being passed. Example: the string "Hello" will be reversed to olleH". You have to be careful about the 10' symbol to keep it at the end of the array and watch out for odd and even length of strings 2. Test your function and display the string (array) before and after it is reversed IMPORTANT: The function does NOT print the string in reverse; it actually reverses it in the memory Part D. String Tokenization 1. Write a function called parseSentence that takes as input parameter a null (i.e ' ") terminated string line, where line would contain an English sentence 2. Assume that the delimiters are space, comma, semicolon and period 3. The function extracts each word from the sentence (without any punctuation or spacing) and then prints one word per line 4. The function returns a void type For example char str "hello world, how are you today."; parseSentence (str); would print the following List ofWords: hello world how are you today Part E. String Sorting 1. Write a function called sortWords that takes as input parameter a null (i.e.'0') terminated string line, where line would contain an English sentence 2. Assume that the delimiters are space, comma, semicolon and period 3. The function extracts each word from the sentence (without any punctuation or spacing) and then prints them after sorting 4. The function returns a void type

Explanation / Answer

Part C String Manipulation :

void reverseStr(char *a){

int length = strlen(a);

char *start = a;

char *end = a + strlen(a) - 1;

while(end > start){

char t = *start;

*start = *end;

*end = t;

end--;

start++;

}

//printf("Reversed String:: %s", a );

}

int main(){

char *a = "hello";

printf("before reverse :: %s", a);

reverse(a);

printf("After reverse :: %s", a);

return 0;

}

Part D: String Tokenization

import java.io.*;

import java.util.StringTokenizer;

public class Tokenizer{

public static void main(String[] args){

String inputString;

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

//System.out.println("Enter the input string");

inputString = br.readLine();

//we are replacing all semi colon,period and coma to space o we have only one delimeter

inputString = inputString.replaceAll(","," ");

inputString = inputString.replaceAll("."," ");

inputString = inputString.replaceAll(";"," ");

//Using String tokenizer we are using default constructor because we have to ignore the space

StringTokenizer st = new StringTokenizer(inputString, " ");

while(st.hasMoreToken()){

System.out.println(st.nextToken());

}

}

}

PART E: STRING SORTING

import java.util.*;

public class SortWord{

public static void main(String[] args){

String inputString;

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

//System.out.println("Enter the input string");

inputString = br.readLine();

sortWording(inputString);

}

public void sortWording(String inputString){

//we are replacing all semi colon,period and coma to space o we have only one delimeter

inputString = inputString.replaceAll(","," ");

inputString = inputString.replaceAll("."," ");

inputString = inputString.replaceAll(";"," ");

//now we are spliting using space

String[] splitString = inputString.split(" ");

for(int i=0; i < splitString.length; i++){

for(int j = i+1; j < splitString.length; j++){

if(splitString[i].compareTo(splitString[j])){

char temp = splitString[i];

splitString[i] = splitString[j];

splitString[j] = temp;

}

}

}

System.out.println("Sorted Order of the Words are below::::");

for(int i=0; i < splitString.length; i++){

System.out.println(splitString[i]);

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote