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
  • 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);...

  • 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"; }

  • C++ problem where should I do overflow part? in this code do not write a new...

    C++ problem where should I do overflow part? in this code do not write a new code for me please /////////////////// // this program read two number from the user // and display the sum of the number #include <iostream> #include <string> using namespace std; const int MAX_DIGITS = 10; //10 digits void input_number(char num[MAX_DIGITS]); void output_number(char num[MAX_DIGITS]); void add(char num1[MAX_DIGITS], char num2[MAX_DIGITS], char result[MAX_DIGITS], int &base); int main() { // declare the array = {'0'} char num1[MAX_DIGITS] ={'0'}; char...

  • This is for a C++ program: I'm almost done with this program, I just need to...

    This is for a C++ program: I'm almost done with this program, I just need to implement a bool function that will ask the user if they want to repeat the read_course function. I can't seem to get it right, the instructions suggest a do.. while loop in the main function. here is my code #include <iostream> #include <cstring> #include <cctype> using namespace std; const int SIZE = 100; void read_name(char first[], char last[]); void read_course(int & crn, char des[],...

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
ADVERTISEMENT