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 PROVIDE COMMENTS ON STEPS IMPORTANT NOTE: The library string functions cant be used. You must...
PLEASE PROVIDE COMMENTS ON STEPS IMPORTANT NOTE: The library string functions cant be used. You must use pointers and the switch statement to execute this program. Assume that the vowels are a, e, i, o, u. The modification has to be done in the original char array without creating a new array. 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...
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:...
Complete the program used on the instructions given in the comments: C++ lang #include <string> #include...
Complete the program used on the instructions given in the comments: C++ lang #include <string> #include <vector> #include <iostream> #include <fstream> using namespace std; vector<float>GetTheVector(); void main() { vector<int> V; V = GetTheVector(); //reads some lost numbers from the file “data.txt" and places it in //the Vector V Vector<int>W = getAverageOfEveryTwo(V); int printTheNumberOfValues(W) //This should print the number of divisible values by 7 //but not divisible by 3. PrintIntoFile(W); //This prints the values of vector W into an output file...
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...
The program should be written in C++ with comments Write a program that takes graduation rates...
The program should be written in C++ with comments Write a program that takes graduation rates (per 1000 of the population) for North, South, East, West and Central United States. Input the number from each of the regions in a function returning an int with the graduation rate to the main program. Also figure out which region has the highest graduation rate in another function and display the result from inside that particular function. So your function prototypes should be...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT