
//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;
}
Quick Links
Latest Comment
Re: Current health dilemma(s) - my not-so-newly-fo... weight is maintained my us not having alot of money. i...
| Terms of Service
| Privacy Policy
c++