Assume a text file “Test.txt” is already created. Using this file, write a
function to create three files “LOWER.TXT”, which contains all the
lowercase vowels and “UPPER.TXT” which contains all the uppercase vowels
and “DIGIT.TXT” which contains all digits.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
bool in(char* c, int size, char s){
for(int i = 0; i < size; i++)
if(c[i] == s) return true;
return false;
}
void file(){
fstream test("Test.txt", ios::in),
lower("LOWER.txt", ios::out | ios::trunc),
upper("UPPER.txt", ios::out | ios::trunc),
digit("DIGIT.txt", ios::out | ios::trunc);
string s;
char uppercase[5] = {'A', 'E', 'I', 'O', 'U'},
lowercase[5] = {'a', 'e', 'i', 'o', 'u'},
digits[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
if(test){
while(getline(test, s)){
for(int i = 0; i < s.length(); i++){
if(in(lowercase, 5, s[i])) lower<<s[i]<<endl;
if(in(uppercase, 5, s[i])) upper<<s[i]<<endl;
if(in(digits, 10, s[i])) digit<<s[i]<<endl;
}
}
test.close();
lower.close();
upper.close();
digit.close();
return;
}
else cout<<"Error opening test.txt";
}
int main(){
file();
return 0;
}
Comments
Leave a comment