filter out in C++

letter: upper or lower case a through z
vowel: the letters a, e, i, o or u
consonant: letters that are not vowels
word: a sequence of sequential letters and/or numbers separated by punct or space
number: zero through 9
space: whitespace characters such as space, tab, or newline
punct: punctuation marks such as quote, comma, period, etc.
upper: uppercase letter, vowel, consonant or word
lower: lowercase letter, vowel, consonant or word
The user is going to provide the name of a file and one or more of the items in the list above.

I am having trouble to telling the program that I want it to do that only a specific action and not do all of the actions something like if and else. This is what I have so far.
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
using namespace std;
int check_vowel(char);
int check_constant(char);
int check_number(char);
int check_punctuation(char);
void usage(char *progname, string msg)
{
    cerr << "Error: " << msg << endl;
    cerr << "Usage is: " << progname << " [filename]" << endl;
    cerr << " specifying filename reads from that file; no filename reads standard input" << endl;
}
int main(int argc, char *argv[])
{
    istream *br;
    ifstream infile;
    
    if( argc == 1 )
        br = &cin;
    else if( argc == 2 ) {
        infile.open(argv[1]);
        if( infile.is_open() )
            br = &infile;
        else {
            usage(argv[0], "Cannot open " + string(argv[1]));
            return 1;
        }
    }
    else {
        usage(argv[0], "More than one file name was given");
        return 1;
    }
    
    string oneLine;
    
    getline(*br, oneLine);
    if( br->good() )
        cout << oneLine << endl;
    else
        cout << "!!! I COULD NOT READ !!!\n";
    
    
    char line[1000];
    
    while( cin.good() ) {
        cin.get(line, 1000, '\n');
        
        cout << line << ":" << strlen(line) << endl;
    }
    

    char v[100], l[100];
    int i, j = 0;
    
    gets(v);
    
    for(i = 0; v[i] != '\0'; i++) {
        if(check_vowel(v[i]) == 0) {       //not a vowel
            l[j] = v[i];
            j++;
        }
    }
    
    l[j] = '\0';
    
    strcpy(v, l);    //We are changing initial string
    
    cout << ("String after deleting vowels: ") << v;
    
    char c[100], t[100];
    int a, b = 0;
    
    gets(c);
    
    for(a = 0; c[a] != '\0'; a++) {
        if(check_vowel(c[a]) == 0) {       //not a vowel
            l[b] = c[a];
            b++;
        }
    }
    
    t[b] = '\0';
    
    strcpy(c, t);    //We are changing initial string
    
    cout << ("String after deleting constants: ") << c;
    
    
    char n[100], r[100];
    int d, f = 0;
    
    gets(n);
    
    for(d = 0; n[d] != '\0'; d++) {
        if(check_number(n[d]) == 0) {       //not a number
            r[f] = n[d];
            f++;
        }
    }
    
    r[f] = '\0';
    
    strcpy(n, r);    //We are changing initial string
    
    cout << ("String after deleting numbers: ") << n << endl;
    
    char p[100], u[100];
    int g, h = 0;
    
    gets(p);
    
    for(g = 0; p[g] != '\0'; g++) {
        if(check_punctuation(p[g]) == 0) {       //not a punctuation
            u[h] = p[g];
            h++;
        }
    }
    
    u[h] = '\0';
    
    strcpy(p, u);    //We are changing initial string
    
    cout << ("String after deleting punctuation: ") << p << endl;

    
    return 0;
}
int check_vowel(char c)
{
    switch(c) {
        case 'a':
        case 'A':
        case 'e':
        case 'E':
        case 'i':
        case 'I':
        case 'o':
        case 'O':
        case 'u':
        case 'U':
            return 1;
        default:
            return 0;
    }
}
    int check_constant(char c)
    {
        switch(c) {
            case 'q':
            case 'w':
            case 'r':
            case 't':
            case 'y':
            case 'i':
            case 'p':
            case 's':
            case 'd':
            case 'f':
            case 'g':
            case 'h':
            case 'j':
            case 'k':
            case 'l':
            case 'z':
            case 'x':
            case 'c':
            case 'v':
            case 'b':
            case 'n':
            case 'm':
            case 'Q':
            case 'W':
            case 'R':
            case 'T':
            case 'Y':
            case 'U':
            case 'P':
            case 'S':
            case 'D':
            case 'F':
            case 'G':
            case 'H':
            case 'J':
            case 'K':
            case 'L':
            case 'Z':
            case 'X':
            case 'C':
            case 'V':
            case 'B':
            case 'N':
            case 'M':
                return 1;
            default:
                return 0;
        }

}
int check_number(char c)
{
    switch(c) {
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
        case '0':
            return 1;
        default:
            return 0;
    }
}
int check_punctuation(char c)
{
    switch(c) {
        case '.':
        case '?':
        case '!':
        case '"':
        case ',':
        case ';':
        case ':':
            return 1;
        default:
            return 0;
    }
}
Last edited on
Topic archived. No new replies allowed.