I am using the prev and next lines to do the manipulations defined by the functions.
The input file is exactly in the same format as I posted before. So I end up getting an output file with:
// blank line here ///
Humpty Dumpty
sat on a
wall
Code:
#include <iostream>
#include <string>
#include <cctype>
#include <fstream>
using namespace std;
string make_upcase(string &s) ;
int count_words(string s) ;
bool are_anagrams(string s, string s2) ;
int main()
{
cout <<"Enter the output filename: " ;
cin >> output_filename ;
OUTFILE.open(output_filename.c_str()) ;
string line, prev_line, next_line ;
while (INFILE)
{
while( getline(INFILE, line) )
{
if(isdigit(line[0]))
{
continue ;
prev_line = line ;
}
next_line = line ;
OUTFILE << prev_line << endl << next_line ;
}// End of while( getline(INFILE, line) ) loop
} // End of while(INDATA) loop
system("Pause");
return 0;
}// End main
string make_upcase(string &s)
//----------------------------------------------------------------------------
//Creates a new string that is an upper case version of the original string.
//Pre-Condition: Original string is lowercase.
//Post-Condition: New String is all Caps.
//----------------------------------------------------------------------------
{
string uppercase_string ;
if(! s.empty()) //Does the following if the string is not empty
{
string letter ;
for(int i = 0; i < s.length(); i++)
{
letter = toupper(s[i]) ; //coverts single character to uppercase
//using <cctype> header
uppercase_string.insert(i,letter) ;
}
cout <<uppercase_string <<"\n";
}
return uppercase_string ;
}
//***NOT FINISHED YET
int count_words(string s) //determines how many words are in the string.
{
return s.length() ;
}
bool are_anagrams(string s, string s2)
//----------------------------------------------------------------------------
//Determines whether the strings are anagrams of one another.
//Pre-Condition: Two strings are passed to the function, original string and
// uppercase string.
//Post-Condition: If the two strings are anagrams of eachother, the function
// returns true, else it returns false.
//----------------------------------------------------------------------------
{
if(s.length() != s2.length())
{
return false ;
}
if(!s.empty())
{
for(int i = 0; i < s.length(); i++)
{
for(int j = 0; j <s2.length(); j++)
{
if(s[i] == s2[j])
{
return true ;
}
else
{
return false ;
}
} //end of int j for loop
} //end of int i for loop
} //end if
} //end of function definition