Question

In: Computer Science

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 of the string.

Example :

Original string : washer

New string : wshrae

Solutions

Expert Solution

#include <iostream>
#include <string>
using namespace std;

int main()
{
    string s;
    cout<<"Original string: ";
   cin>>s;
   int len = s.length();
   char* ptr = new char[s.length()];
   
   for(int i = 0;i<=len;i++){
       ptr[i] = s[i];
   }
   
   int count = 0;
   char ch;
   // Loop through all the elements of string s
   for(char* p = ptr; p<(ptr+len-count);p++){
      ch = *p;
      // Checking for a vowel
      switch(ch){
         case 'a':
         case 'e':
         case 'i':
         case 'o':
         case 'u':
          // Moving all the characters from index i+1 to one index left
          // This makes last position empty for vowel ch
         for(char* q = p+1;q<(ptr+len);q++){
            *(q-1) = *q;
         }     
         // Replacing last character with ch
         *(ptr+len-1) = ch;
         // Incrementing count
         count++;
         break;
      }
      //cout<<(*(ptr))<<end;
   }
   
   cout<<"New string: "<<ptr<<endl;
    return 0;
}


Related Solutions

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...
You will need to write a library of functions that uses pointers. Your functions must follow...
You will need to write a library of functions that uses pointers. Your functions must follow the headers below. int intDivide(int numerator, int denominator, int *quo_ptr, int *rem_ptr); Create a function to do integer division that gives the division result and remainder via output parameters, quo_optr and rem_ptr.   Additionally, the function must return an int representing the success/failure of the function. The function should return 0 if it succeeds and -1 if there is a divide by zero error. (Note...
For the answer please show you work : please include steps/functions used on TI 84+ calculator...
For the answer please show you work : please include steps/functions used on TI 84+ calculator (mandatory). a. State the hypotheses and identify the claim. b. Find the critical value. c. Compute the test value. d. Make the decision./Summarize the results In a magazine survey, 60% of respondents said that they used reusable shopping bags, 32% asked for plastic, and 8% requested paper. A random sample of 300 shoppers revealed that 28 asked for paper, 120 requested plastic, and the...
The hypothalamus is important in what body functions? Note: Please write or type in a way...
The hypothalamus is important in what body functions? Note: Please write or type in a way that is legible and understandable. Thank you for taking the time to answer my question.
1) (note: Please also provide the excel formulas used to solve it )  You work for a...
1) (note: Please also provide the excel formulas used to solve it )  You work for a soft-drink company in the quality control division. You are interested in the standard deviation of one of your production lines as a measure of consistency. The product is intended to have a mean of 12 ounces, and your team would like the standard deviation to be as low as possible. You gather a random sample of 18 containers. Estimate the population standard deviation at...
Look up the man pages for the following string functions from the C standard library, and...
Look up the man pages for the following string functions from the C standard library, and write implementations of each: strstr() Please explain the work please, thank you
Please write code in c++. Use iostream (and any string library if you need it). Create...
Please write code in c++. Use iostream (and any string library if you need it). Create s structure plane : First line contains n(0 < n < 1001). Then n lines inputed in given format:   First - ID[int type]   Second - FromLocation[char*]   Third - ToLocation[char*]   Fourth - DepartureTime[char*] Output: Sorted list of planes should be in UPPER CASE. Example of input:(it's just one of an examples, you need to write code generally) 10 40 Shuch Satp 05:47 89 Kyzy Taldy  07:00...
(For this part, you MUST present sufficient solution steps, and MUST apply specific Excel functions =NPV(…),...
(For this part, you MUST present sufficient solution steps, and MUST apply specific Excel functions =NPV(…), =IRR(…), =AVERAGE(…), =YIELD(…) whenever applicable). Please show excel formulas. Given the following information for Bajor Co.: Debt: Bajor’s long-term debt capital consists of bonds with 6.250 percent coupon rate (semiannual coupon payments), 9 years time to maturity, and current price of 106.61 percent of its par value (i.e., price = 106.61 relative to full amount redemption par of 100). Preferred stock: Bajor has not...
(For this part, you MUST present sufficient solution steps, and MUST apply specific Excel functions =PV(…),...
(For this part, you MUST present sufficient solution steps, and MUST apply specific Excel functions =PV(…), =FV(…), =PMT(…), =NPER(…), =RATE(…), =PRICE(…) or =YIELD(…) whenever applicable. Please show me the EXCEL functions that was used to help me better understand was equals what. Using Excel finance formulas You apply for a 20-year, fixed-rate (APR 6.48%) monthly-payment-required mortgage loan for a house selling for $150,000 today. Your bank requires 22% initial down payment of house value (to be paid in cash immediately),...
(For this part, you MUST present sufficient solution steps, and MUST apply specific Excel functions =NPV(…),...
(For this part, you MUST present sufficient solution steps, and MUST apply specific Excel functions =NPV(…), =IRR(…), =AVERAGE(…), =YIELD(…) Case Two (22 pts) Given the following information for Bajor Co.: Debt: Bajor’s long-term debt capital consists of bonds with 6.250 percent coupon rate (semiannual coupon payments), 9 years time-to-maturity, and current price of 106.61 percent of its par value (i.e., price = 106.61 relative to full amount redemption par of 100). Preferred stock: Bajor has not issued any preferred stocks....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT