Question:
How to create a C++ program? File I/O, Library Functions?
c++
2010-04-21 20:36:39 UTC
I need to write a c++ program that opens an input file, filters the contents, and writes the resulting data to an output file. The filter options are:
1) Convert all alphabetic characters to uppercase 2) Convert all alphabetic characters to lowercase 3) Replace all numeric (digit) characters with spaces
The program should prompt for an input file name, then present a menu to select the type of filter to be applied, then prompt for an output file name. It should also support multiple runs, asking “Do you want to process another file?”.
Filenames of up to 40 characters, with any 3 character extension should be supported. Invalid menu selections should produce an error message and a redisplay of the menu. An error message should be displayed if the filename entered cannot be opened. Any characters not affected by the chosen filter should be copied in their original form from the input to the output file.
Three answers:
Cubbi
2010-04-22 07:25:37 UTC
Do you think it won't be obvious that someone else wrote it for you?



#include

#include

#include

#include

#include

#include

using namespace std;

int spacedigits(int c)

{

return isdigit(c) ? ' ' : c;

}

int main()

{

map filters;

filters["1"] = toupper;

filters["2"] = tolower;

filters["3"] = spacedigits;



cout << "Enter input file name: ";

string s;

getline(cin, s);

ifstream fi(s.c_str());



string choice;

while(filters.find(choice) == filters.end())

{

cout << "Choose filter (1,2, or 3): ";

getline(cin, choice);

}



cout << "Enter output file name: ";

getline(cin, s);

ofstream fo(s.c_str());



transform( istreambuf_iterator(fi), istreambuf_iterator(), ostreambuf_iterator(fo), filters[choice] );

}



note: doesn't ask if you want to process another; you should be able to do that much!
anonymous
2016-06-02 04:07:22 UTC
It is very easy. their are many ways - you can use a c programming tool like quency , torbo c++ or c free or - you can directly write the code in a note pad and save it as *.c or *.h file (but in that case you need a separate compiler)
tbshmkr
2010-04-21 20:54:22 UTC
Post your code.

=

We will help you make it work right.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...