Question

I was asked to write a program that when divisible by 2- reverses the order of...

I was asked to write a program that when divisible by 2- reverses the order of the letters in a sentence

when divisible by 3- changes all lowercase letter into uppercase letters in a sentence

when divisible by 5 skips the vowels in a sentence

this is what I have so far. my reverseMode works fine.

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

void reverseMode(char* str);
void upperMode(char* str);
void goodbyeVowels(char* str);

char str[50], rstr[50]; //initializing my character arrray

int len, i,n;


int main()
{

  
cout << "Please Enter a Sentence: ";// displays message to user
cin.getline(str,50); //stores characters into str
reverseMode(str); //enables function
upperMode(str);
goodbyeVowels(str);
cout << str;
return 0;
  
}

void reverseMode(char* str)
{
  
for (i=0; i<strlen(str)/2; i++){
char temp= str[i];
str[i]=str[strlen(str)-i-1];
str[strlen(str)-i-1] = temp;
}
}

void upperMode(char* str)
{
for (i=0; i <strlen(str)/3; i++){
str[i] = toupper(str[i]);

}
}

void goodbyeVowels (char* str)
{
  
len=strlen(str);
for (i=0; i<len/5; i++)
{
if( str[i] =='a' || str[i] =='e' || str[i] =='i' ||
str[i] =='o' || str[i] =='u' || str[i] =='A' ||
str[i] =='E' || str[i] =='I' || str[i] =='O' ||
str[i] =='U')
{
for (n=i; n<len; n++)
{
str[n]=str[n+1];
  
len--;
}
}
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

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

void reverseMode(char* str);
void upperMode(char* str);
void goodbyeVowels(char* str);

char str[50], rstr[50]; //initializing my character arrray

int len, i,n;


int main()
{
cout << "Please Enter a Sentence: ";// displays message to user
cin.getline(str,50); //stores characters into str
reverseMode(str); //enables function
upperMode(str);
goodbyeVowels(str);
cout << str;
return 0;

}

void reverseMode(char* str)
{
int len=strlen(str);
if(len%2==0)
{
for (i=0; i<len/2; i++){
char temp= str[i];
str[i]=str[strlen(str)-i-1];
str[strlen(str)-i-1] = temp;
}
}
}

void upperMode(char* str)
{
int len=strlen(str);
if(len%3==0)
{
for (i=0; i <len; i++){
str[i] = toupper(str[i]);
}
}
}

void goodbyeVowels (char* str)
{

len=strlen(str);
if(len%5==0)
{
int currentIndex=0;
for (i=0; i<len; i++)
{
if( str[i] =='a' || str[i] =='e' || str[i] =='i' ||
str[i] =='o' || str[i] =='u' || str[i] =='A' ||
str[i] =='E' || str[i] =='I' || str[i] =='O' ||
str[i] =='U')
{
for (n=i; n<len; n++)
str[n]=str[n+1];
len--;
}
}
}
}
//output:

Add a comment
Know the answer?
Add Answer to:
I was asked to write a program that when divisible by 2- reverses the order of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Can you all fix this coding below, if so "ASAP" would be great? Write a program...

    Can you all fix this coding below, if so "ASAP" would be great? Write a program that prompts the user to input a string and outputs the string in uppercase letters using dynamic arrays. int main() {​ char *str; ​ ​ int strLen;​ int len;​ char ch;​ ​ int i;​ ​ cout << "Enter the size of the string: ";​ cin >> strLen;​ cout << endl;​ ​ cin.get(ch);​ ​ str = new char[strLen + 1];​ ​ cout << "Enter a...

  • I'm having trouble getting my program to output this statement Enter a sentence: Test! There are...

    I'm having trouble getting my program to output this statement Enter a sentence: Test! There are 5 total characters. There are 1 vowel. There are 1 UPPERCASE letters. There are 3 lowercase letters. There are 1 other characters. Here's my code: #include<string.h> #include<stdio.h> #include<stdbool.h> int main() { char str[100]; int i; int vowels=0; int UC; int LC; int Others; int c; printf("Enter a sentence: \n"); gets(s); LC=countLC(&s); UC=countUC(&s); Others=countOthers(&s); printf("There are %d total characters.\n", ; for(i=0; i<strlen(str); i++){ if(isVowel(str[i])) vowels++;...

  • #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str);...

    #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() {    char string[100];    char inputChoice, choice[2];    int vowelTotal, consonantTotal;    //Input a string    cout << "Enter a string: " << endl;    cin.getline(string, 100);       do    {        //Displays the Menu        cout << "   (A) Count the number of vowels in the string"<<endl;        cout << "   (B) Count...

  • #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str);...

    #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() {    char string[100];    char inputChoice, choice[2];    int vowelTotal, consonantTotal;    //Input a string    cout << "Enter a string: " << endl;    cin.getline(string, 100);       do    {        //Displays the Menu        cout << "   (A) Count the number of vowels in the string"<<endl;        cout << "   (B) Count...

  • // Write a program that determines how many of each type of vowel are in an...

    // Write a program that determines how many of each type of vowel are in an entered string of 50 characters or less. // The program should prompt the user for a string. // The program should then sequence through the string character by character (till it gets to the NULL character) and count how many of each type of vowel are in the string. // Vowels: a, e, i, o, u. // Output the entered string, how many of...

  • Write a program that reads a sentence input from the user. The program should count the...

    Write a program that reads a sentence input from the user. The program should count the number of vowels(a,e,i,o,u) in a sentence. Use the following function to read the sentence. Should use switch statement with toupper. int read_line(char str[],int n) {    int ch, i=0;    while((ch =getchar()) != '\n')        if(1<n)            str[i++]==ch;    str[i] != '\0';    return i; } output should look like: Enter a sentence: and thats the way it is! Your sentence...

  • Write a program that prompts the user to input a string. The program then uses the...

    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. #include <iostream> #include <string> using namespace std; void removeVowels(string& str); bool isVowel(char ch);...

  • C++ Programming I have finished the code but there's one error which shows that "strcpy" might...

    C++ Programming I have finished the code but there's one error which shows that "strcpy" might be unsafe. Consider using strcpy_s instead. I've tried that but it's not working probably because I didn't implement it correctly. I am posting my code below. It'd be really helpful if you could fix all the strcpy errors and post it below. Thank you. Text.cpp: #include <iostream> #include <iomanip> #include <cassert> #include <cstring> #include "Text.h" Text::Text ( const char *charSeq ) {    bufferSize...

  • Why the result is 0. The correct result should be 2 but it is 0. Why?...

    Why the result is 0. The correct result should be 2 but it is 0. Why? File Edit using std:istring int numVowels(string str) Exited with status int str len str. length); int i int count for (i=0; î <str-len; i++) /s Convert the character to 1 /s If the character is atready in Lower case, tolower) will return temp tolower(strli]): />If the character is any of these five letters ,a", 'e', 'i', 'o', 'u count++ /- Return the count value...

  • I need to add a for or a while loop to the following code. please help...

    I need to add a for or a while loop to the following code. please help needs to be in c++. #include <iostream> #include <string.h> using namespace std; int main() {    char input[100]; cout << "Please enter a character string: "; cin >> input; char *head = &input[0], *tail = &input[strlen(input) - 1]; char temp = *head; *head = *tail; *tail = temp; tail--; head++; cout << "CString = " << input << "\n"; }

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT