Question

In: Computer Science

PLEASE PROVIDE COMMENTS ON STEPS Write a C++ program that modifies a string (null terminated) as...

PLEASE PROVIDE COMMENTS ON STEPS

Write a C++ program that modifies a string (null terminated) as follows:

Consonants are positioned at the beginning of the string and vowels are moved to the end of the string.

Example :

Original string : washer

New string : wshrae

Note:

The library string functions cannot be used. You must use pointers and the switch statement to execute this program. Assume that the vowels are a, e, i, o, and u. The modification has to be done in the original char array without creating a new array.

Solutions

Expert Solution

Solution for the given question are as follows -

Code :

#include<iostream>
#include<string.h>
using namespace std;
int main ()
{
// local variable declaration
string str, str1, str2;
// get input from user
cout << "Enter a string : ";
getline (cin, str);
// loop over string
for (int i = 0; str[i]!='\0'; ++i)
{
// check char is vowel or not
switch(str[i]) {
case 'a' :
str1 += str[i];
break;
case 'e' :
str1 += str[i];
break;
case 'i' :
str1 += str[i];
break;
case 'o' :
str1 += str[i];
break;
case 'u' :
str1 += str[i];
break;
default :
str2+= str[i];
break;
}
}
// concate the strings
str = str2 + str1;
// print output
cout << "Final Result : " << str;
return 0;
}

Code screen shot :

Output :


Related Solutions

Write an 8088/8086 assembly program that counts the length of a null terminated string that starts...
Write an 8088/8086 assembly program that counts the length of a null terminated string that starts at location STR.Assume string length will not exceed 255 character.Print the result on the screen?
Please write a complete C coding program (NOT C++) that has the following: (including comments) -...
Please write a complete C coding program (NOT C++) that has the following: (including comments) - declares two local integers x and y - defines a global structure containing two pointers (xptr, yptr) and an integer (z) - declares a variable (mst) by the type of previous structure - requests the values of x and y from the user using only one scanf statement - sets the first pointer in the struct to point to x - sets the second...
C++ program assignment asks to implement the following functions. Each function deals with null terminated C-strings....
C++ program assignment asks to implement the following functions. Each function deals with null terminated C-strings. Assume that any char array passed into the functions will contain valid, null-terminated data. The functions must have the signatures listed below. 1. This function returns the last index where the target char can be found in the string. it returns -1 if the target char does not appear in the string. For example, if s is “Giants” and target is ‘a’ the function...
Write a C++ Program Write a program that prompts the user to input a string. The...
Write a C++ Program Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning...
use linux or c program. please provide the answer in details. Write a program that will...
use linux or c program. please provide the answer in details. Write a program that will simulate non - preemptive process scheduling algorithm: First Come – First Serve Your program should input the information necessary for the calculation of average turnaround time including: Time required for a job execution; Arrival time; The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time. Step 1: generate the input data (totally...
Please provide Python code that does the following: 3) Write a program that takes a string...
Please provide Python code that does the following: 3) Write a program that takes a string as input, checks to see if it is comprised entirely of letters, and if all those letters are lower case. The output should be one of three possible messages: Your string is comprised entirely of lower case letters. Your string is comprised entirely of letters but some or all are upper case. Your string is not comprised entirely of letters. Your program may NOT:...
Write a C program that will read a character string and then encrypt the string based...
Write a C program that will read a character string and then encrypt the string based on one of the 3 different encryption methods. The type of encryption is to be selected by the user. Encryption method 1: Swapping by position. Characters in the array are swapped with the opposite characters based on their position in the string. Example: Input string – apple. Encrypted string – elppa Method: The first character ‘a’ and the last character ‘e’ – swap their...
Q) You have been asked to develop a program which processes C++ null-terminated strings to extract...
Q) You have been asked to develop a program which processes C++ null-terminated strings to extract character and numerical data separately. Assume that the users runs the application (examTest.exe) from the command line as follows: examTest.exe X-Axis:10,Y-Axis:17,Z-Axis:-6 Your application should step through the input arguments and extract the values of the XAxis, Y-Axis and Z-Axis commands. The user must always enter the arguments in the specified order, however your application should check they are correct. At the end of your...
Hello, Please write this program in java and include a lot of comments and please try...
Hello, Please write this program in java and include a lot of comments and please try to make it as simple/descriptive as possible since I am also learning how to code. The instructions the professor gave was: Create your own class Your own class can be anything you want Must have 3 instance variables 1 constructor variable → set the instance variables 1 method that does something useful in relation to the class Create a driver class that creates an...
C PROGRAM STRING AND FILE PROCESSING LEAVE COMMENTS! I WILL LEAVE POSITIVE REVIEW! THANK YOU :)...
C PROGRAM STRING AND FILE PROCESSING LEAVE COMMENTS! I WILL LEAVE POSITIVE REVIEW! THANK YOU :) I need a program that 1) Count all words in a file. A word is any sequence of characters delimited by white space or the end of a sentence, whether or not it is an actual English word. 2)Count all syllables in each word. To make this simple, use the following rules: •Each group of adjacent vowels (a, e, i, o, u, y) counts...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT