computerjunkie
This Site is Intended to Help those of you in Walker's CSIS 150 Class... NOTE: DON'T COPY AND PASTE
//file main.cc
//author Justin Kingsley
(kingslju@mmstate.edu)
//assignment 10
//Pig Latin
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//*prototype
bool isVowel(char ch);
string rotate(string pStr);
string pigLatinString(string pStr);
string StringOrNot(string input);
int main(int argc, char ** argv)
{
ifstream ins;
ofstream outs;
string str,
input, //Place holder for the location of input file
output; //Place holder for the location of output file
if (argc != 3)
{
cerr << argv[0] << ": Usage: " << argv[0] << " <infile> <outfile>\n";
exit(1);
}
ins.open(argv[1]);
if (ins.fail()) //Tests to see if input file is Readable
{
cerr << argv[0] << ": Input file " << argv[1] << " --> Error" << endl;
return 1;
}
ins.close();
outs.open(argv[2]);
if (outs.fail()) //Testing to see if output failed to write
{
cerr << argv[0] << "Output File " << argv[2] << " --> Error" << endl;
return 1;
}
outs << StringOrNot(argv[1]) << endl; //calls StringOrNot function
outs.close();
cout << endl
<< "All is done... You can check your results at "
<< argv[2] << endl;
return 0;
}
//author Justin Kingsley
(kingslju@mmstate.edu) //assignment 10
//Pig Latin
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//*prototype
bool isVowel(char ch);
string rotate(string pStr);
string pigLatinString(string pStr);
string StringOrNot(string input);
int main(int argc, char ** argv)
{
ifstream ins;
ofstream outs;
string str,
input, //Place holder for the location of input file
output; //Place holder for the location of output file
if (argc != 3)
{
cerr << argv[0] << ": Usage: " << argv[0] << " <infile> <outfile>\n";
exit(1);
}
ins.open(argv[1]);
if (ins.fail()) //Tests to see if input file is Readable
{
cerr << argv[0] << ": Input file " << argv[1] << " --> Error" << endl;
return 1;
}
ins.close();
outs.open(argv[2]);
if (outs.fail()) //Testing to see if output failed to write
{
cerr << argv[0] << "Output File " << argv[2] << " --> Error" << endl;
return 1;
}
outs << StringOrNot(argv[1]) << endl; //calls StringOrNot function
outs.close();
cout << endl
<< "All is done... You can check your results at "
<< argv[2] << endl;
return 0;
}
PigLatin problem
//file StringOrNot.cc
//author Justin Kingsley (kingslju@mmstate.edu) //don't just copy my code... it won't work with your program
//assignment 9
//Pig Latin
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//*prototype
bool isVowel(char ch);
string rotate(string pStr);
string pigLatinString(string pStr);
string StringOrNot()
{
ifstream ins;
string con, //holds the information that comes form the input file
str, //place holder for the string about to be translated into pigLatin
cur, //currently translated string
input; //Place holder for the location of input file
char ch; //Place holder for current character
int call = 0; //tells the program if it needs to call the function pigLatinString if set to 1
cout << "Please Enter in the Location of the INPUT FILE:" << endl;
cin >> input;
ins.open(input.c_str());
if (ins.fail()) //Tests to see if input file is Readable
{
cerr << "Input file failed" << endl;
return "Input file failed";
}
ins.get(ch);
while (ins)
{
con = con + ch; //con collects confirmation string
switch(ch)
{
case '.' : case '!' : case ',' : case '?' : case ';' : case ':' : case '\n' : case ' ' : case '-' :
{
if(call == 1)
{
cur = cur + pigLatinString(str); // Runs PigLatin and add the returned string to cur
cur = cur + ch; // Adds char ch to cur
call = 0; // tells system str is empty
str = ""; // Clears str
ch = ins.get(); // gets next char value
}
else
{
cur = cur + ch; // Adds ch to cur
ins.get(ch); // gets next char value
}
break;
}
default:
{
str = str + ch; // Adds ch to end of str(soon to be processed by PigLatin
call = 1; // Tell system that str contains something
ins.get(ch); // gets next char value
}
}
}
ins.close();
cur = cur + "\n**********************\n** Is PigLatin for: ** \n**********************\n\n" + con;
return cur;
}
//author Justin Kingsley (kingslju@mmstate.edu) //don't just copy my code... it won't work with your program
//assignment 9
//Pig Latin
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//*prototype
bool isVowel(char ch);
string rotate(string pStr);
string pigLatinString(string pStr);
string StringOrNot()
{
ifstream ins;
string con, //holds the information that comes form the input file
str, //place holder for the string about to be translated into pigLatin
cur, //currently translated string
input; //Place holder for the location of input file
char ch; //Place holder for current character
int call = 0; //tells the program if it needs to call the function pigLatinString if set to 1
cout << "Please Enter in the Location of the INPUT FILE:" << endl;
cin >> input;
ins.open(input.c_str());
if (ins.fail()) //Tests to see if input file is Readable
{
cerr << "Input file failed" << endl;
return "Input file failed";
}
ins.get(ch);
while (ins)
{
con = con + ch; //con collects confirmation string
switch(ch)
{
case '.' : case '!' : case ',' : case '?' : case ';' : case ':' : case '\n' : case ' ' : case '-' :
{
if(call == 1)
{
cur = cur + pigLatinString(str); // Runs PigLatin and add the returned string to cur
cur = cur + ch; // Adds char ch to cur
call = 0; // tells system str is empty
str = ""; // Clears str
ch = ins.get(); // gets next char value
}
else
{
cur = cur + ch; // Adds ch to cur
ins.get(ch); // gets next char value
}
break;
}
default:
{
str = str + ch; // Adds ch to end of str(soon to be processed by PigLatin
call = 1; // Tell system that str contains something
ins.get(ch); // gets next char value
}
}
}
ins.close();
cur = cur + "\n**********************\n** Is PigLatin for: ** \n**********************\n\n" + con;
return cur;
}
No Questionss - Questions?
Profile
Calendar
Bookmarks
c++