-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule5LabWeek2RemoveTheVowels.cpp
More file actions
83 lines (64 loc) · 2.88 KB
/
Copy pathModule5LabWeek2RemoveTheVowels.cpp
File metadata and controls
83 lines (64 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//************************************************************************
// Author: Rolando Carreon
// Date: apr 11 2025
// Language: C++
// Assignment: Module 5 Lab Week 2 Remove the Vowels
// Description: In this lab, i will create a program that prompts the user
// to input a string, the program will then use two function
// to remove all the vowels from the strinf and output the
// result without voewels.
//************************************************************************
#include<iostream>
#include<string>
using namespace std;
// function prototypes
void removeVowels(string &inputString, string &outputString);
void inputOutput(string &inputString, string &outputString);
int main()
{
// declare local variables
string inputString; // user defined string to type
string outputString; // string to hold the output without vowels
// welcome message
cout << "Welcome to the Vowel Removal Program!" << endl;
// prompts user for inputString, passes to removeVowels() function to remove
// vowels and passes the outputString result to the inputOutput() function
// and then displays the result
inputOutput(inputString, outputString);
return 0;
}
// function definitions
// function that takes a character as input and returns true if the character is a vowel (a, e, i, o, u, both lowercase, and uppercase) otherwise, it returns false.
void removeVowels(string &inputString, string &outputString)
{
// loop through each character in the input string
// sets index to 0 and checks if the character is a vowel, increments index til done
for (int i = 0; i < inputString.length(); i++)
{
// check if the character is a vowel
if (inputString[i] != 'a' && inputString[i] != 'A' &&
inputString[i] != 'e' && inputString[i] != 'E' &&
inputString[i] != 'i' && inputString[i] != 'I' &&
inputString[i] != 'o' && inputString[i] != 'O' &&
inputString[i] != 'u' && inputString[i] != 'U')
{
// if not a vowel add it to the output only string
outputString += inputString[i];
}
}
}
// function takes a string as input and returns a new string with all the vowels removed
void inputOutput(string &inputString, string &outputString)
{
// prompt user for string input
cout << "Enter a string: ";
// use ggetline to allow spaces in the input
getline(cin, inputString); // getline user input for inputString varibale
// only displays the first word before the space so getline is used instead
// cin >> inputString;
// cout << endl;
// call the removeVowels function to remove vowels from the input string
removeVowels(inputString, outputString);
// display the string with vowels removed
cout << "String without vowels: " << outputString << "\n" << endl;
}