Write a program which gives the user the option to separate, Vowels or Consonant from a given text from a file. We will display the separated data on screen and also store it in output file. This is for C++
.
Name of the input file to be used is: SeparateConVow.dat
.
The input file has this sentence:
THIS IS THE FINAL PROJECT FOR OUR CLASS
.
The code should separate the vowels and consonants in that sentence. ^
.
Sample:
Run 1:
Enter name of input file: i.dat
Enter name of output file: o.dat
Would you like to separate Vowels or Consonant, Please press 1 for Vowel, 2 for consonant :
1
Vowels in the string are :
I I E I A O E O O U A
/******** The output of the program ******/
/******** Contents in the output file ******/
/******** The code ******/
#include <bits/stdc++.h>
using namespace std;
//store the string from the file
class Vowels
{
private:
string sentence;
public:
Vowels();
Vowels(string);
string vowels() const;
string constance() const;
void toFile(string) const;
~Vowels();
};
// implementing the class
// contructors
Vowels::Vowels()
{
}
Vowels::Vowels(string sentence)
{
Vowels::sentence=sentence;
}
// method to find vowels
string Vowels::vowels() const
{
// split the string
string mystr=Vowels::sentence;
char mystArr[mystr.length()+1];
strcpy(mystArr,mystr.c_str());
string vowels=""; //store vowels
// find vowels in the string
for(int i = 0; mystArr[i]!='\0'; ++i)
{ mystArr[i]=toupper(mystArr[i]);
if(mystArr[i]=='A' ||mystArr[i]=='E' || mystArr[i]=='I' ||
mystArr[i]=='O' || mystArr[i]=='U')
{
vowels.push_back(mystArr[i]);
vowels+=" ";
}
}
return vowels;
}
// method to find contants
string Vowels::constance() const
{
// split the string
string mystr=Vowels::sentence;
char mystArr[mystr.length()+1];
strcpy(mystArr,mystr.c_str());
string constant=""; //store constant
// find vowels in the string
for(int i = 0; mystArr[i]!='\0'; ++i)
{ mystArr[i]=toupper(mystArr[i]);
if(mystArr[i]=='A' ||mystArr[i]=='E' || mystArr[i]=='I' ||
mystArr[i]=='O' || mystArr[i]=='U')
continue;
constant.push_back(mystArr[i]);
constant+=" ";
}
return constant;
}
// method to write to file
void Vowels::toFile(string name) const
{
ofstream myfile;
myfile.open(name);
myfile <<"Vowels are :"<<endl;
myfile<<Vowels::vowels()<<endl;
myfile <<"Constance are :"<<endl;
myfile<<Vowels::constance()<<endl;
myfile.close();
}
Vowels::~Vowels()
{
}
// function to read str from file
string readFile(string name)
{
/// filestream variable file
fstream file;
string word, sentence, filename;
// filename of the file
filename = name;
// opening file
file.open(filename.c_str());
// extracting words from the file
while (file >> word) {
sentence+=word;
}
file.close();
return sentence;
}
// the main
int main()
{
// initialize variables
string filename="SeparateConVow.dat";
string outfile="SeparateConVowOut.dat";
// prompt user for input
cout<<"Enter name of input file : ";
cin>>filename;
cout<<"Enter name of output file : ";
cin>>outfile;
Vowels v = Vowels(readFile(filename));
// display the vowels
cout<<"Vowels in the string are : "<<endl;
cout<<v.vowels()<<endl;
//display the contance
cout<<"Constance in the string are : "<<endl;
cout<<v.constance()<<endl;
// write to file
v.toFile(outfile);
return 0;
}
Please Give A Thumbs Up if you are satisfied with Answer
Comment Down For any queries
Write a program which gives the user the option to separate, Vowels or Consonant from a...
in C++ please. (Vowel or consonant?) Assume letters A/a, E/e, I/i,0/o, and U/u as the vowels Write a program that prompts the user to enter a letter and check whether the letter is a vowel or consonant. Here is a sample run: 4.10 Enter a letter: B B is a consonant -Enter Enter a letter grade: a is a vowel Enter Enter a letter grade: # is an invalid input Enter (Vowel or consonant?) Assume letters A/a, E/e, I/i,0/o, and...
Vowel or Consonant?Write a program for Programming Exercise 4.10 on p.151 in the textbook. Testing: Run the program for two vowels, two consonants, and two invalid characters. Assume letters A/a , E/e , I/i , O/o , U/u as the vowels. Write a program that prompts the user to enter a letter and check whether the letter is a vowel or constant.
use C++ please 1. Vowels and Consonants Write a program that asks the user to input three different integers. Write a function called numberStyle for this program that will accept each integer (one at a time) and return the following . If the integer is even, return 1 . If the integer is odd, return -1 . If the integer is zero, return O In main, after calling the function output the appropriate message describing the integers ing the function...
‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels in the string B) Count the number of consonants in the string C) Convert the string to uppercase D) Convert the string to lowercase E) Display the current string X) Exit the program The program should start with a user prompt to enter a string, and let them type it in. Then the menu would be displayed. User may enter option in small case...
Write a python program that does the following: takes as input from the user an English sentence calls the function vc_counter() that: takes a string argument counts the number of vowels and consonants in the string returns a dictionary of the counts, using the keys total_vowels and total_consonants Uses the return from vc_counter() to print the total vowels and consonants with appropriate descriptions. Example: Enter an English sentence: The quick brown fox's jump landed past the lazy dog! Total #...
(Count vowels and consonants, file input, nested-loops, switch statement) Assume that letters A, E, I, O and U are the vowels. Write a program that reads strings from a text file, one line at a time, using a while-loop. You do the following operations within each loop: Read one line from the input file and store it in a string; Count the number of vowels and consonants (using either while-loop or for-loop) in the file string. The while-loop...
Pig Latin Translator in Java The goal here is to read in the characters stored in a text file and create a second text file that contains the original text but with every word converted to “Pig-Latin.” The rules used by Pig Latin are as follows: • If a word begins with a vowel, just as "yay" to the end. For example, "out" is translated into "outyay". • If it begins with a consonant, then we take all consonants before...
Java: Assume letters A E O U I as the vowels. Write a program that prompts the user to enter a string and displays the number of vowels and consonants in the string. The same vowels or consonants are counted only once. Use sets in the code.
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...
String variables/Selection & loop Write a complete Java program which prompts the user for a sentence on one line where each word is separated by one space, reads the line into one String variable using nextline(), converts the string into Ubbi dubbi and displays the translated sentence. Ubbi dubbi works by adding ub before each vowel sound in a syllable. For example, hello becomes hubellubo. The word speak has the vowel sound ea, so in Ubbi dubbi it becomes spubeak....