Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C PROGRAMMING Create a program that takes 2 arguments from the terminal. The fir

ID: 3765782 • Letter: C

Question

C PROGRAMMING

Create a program that takes 2 arguments from the terminal. The first argument is an infile (which will be a .txt wordlist) and the second argument is an outfile. Prompt the user with 4 options on how to manipulate the wordlist. After the program completes the outfile should contain the modified wordlist. //sample output ./wlmanipulation infile.txt outfile.txt Choose an option below to modify your wordlist

1. Change the first letter to a capital letter.

2. Make each word lowercase

3. Make each word uppercase

4. Duplicate each word 10 times and display the word with it's duplicate # after it.

Wordlist complete. Check "outfile.txt" for results.

Explanation / Answer

#include <iostream>
#include <fstream>

using namespace std;
string make_lower(string str);
string make_upper(string str);
string make_first_capital(string str);
int main ( int argc, char *argv[] )
{
string infile="in.txt";
string outfile = "out.txt";
string temp;
ifstream in(argv[1]);
fstream out(argv[2]);
int ch,i;
if(argc!=3)
{
cout<<"enter valid orguments that contain input and output filenames ";
return -1;
}
cout<<"1. Change the first letter to a capital letter. 2. Make each word lowercase 3. Make each word uppercase 4. Duplicate each word 10 times and display the word with it's duplicate # after it";
cout<<"enter your choice ";
cin>>ch;
switch(ch)
{
case 1:
   while(in>>temp)
       {
temp = make_first_capital(temp);
       out<<temp<<endl;
       }
   break;
   case 2:
       while(in>>temp)
       {
       temp = make_lower(temp);
       out<<temp<<endl;
       }
   break;
   case 3:
       while(in>>temp)
       {
       temp = make_upper(temp);
       out<<temp<<endl;
       }
   break;
   case 4:
       while(in>>temp)
       {
       for(i=1;i<11;i++)
       {
       cout<<temp<<i<<endl;
       out<<temp<<i<<endl;      
       }
       }
break;
   default:cout<<"enter valid input"<<endl;
   exit(0);    
   }
}

string make_first_capital(string str)
{
   if(str[0]>='a' && str[0]<='z')
       str[0]+='A'-'a';
   return str;
}
string make_upper(string str)
{
int i=0;
   for(i=0;i<str.length();i++)
       if(str[i]>='a' && str[i]<='z')
           str[i]+='A'-'a';
   return str;
}
string make_lower(string str)
{
int i=0;
   for(i=0;i<str.length();i++)
       if(str[i]>='A' && str[i]<='Z')
           str[i]+='a'-'A';
   return str;
}