Question

Write a program which gives the user the option to separate, Vowels or Consonant from a...

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

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

/******** 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

Add a comment
Know the answer?
Add Answer to:
Write a program which gives the user the option to separate, Vowels or Consonant from a...
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
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