#include #include #include #include using namespace std; void add5(int& i); void getGrade(int pct, char& gr); void open(ofstream& fout); void MrOrMs(string& name, char gender); void longWords(ifstream& fin, string& str); int main() { int x = 99; add5(x); cout << x << endl; char grade; getGrade(75,grade); cout << grade << endl; getGrade(105,grade); cout << grade << endl; ofstream fout; cout << "The file is " << (fout.is_open() ? "" : "not ") << "open\n"; open(fout); cout << "The file is " << (fout.is_open() ? "" : "not ") << "open\n"; string name = "Joe Bentley"; MrOrMs(name,'M'); cout << name << endl; ifstream fin("nov12.txt"); if (!fin) { cerr << "Can't open nov12.txt\n"; exit(1); } string longstring; longWords(fin,longstring); cout << endl << longstring << endl; } // Write a file that reads words from a file and adds the words to a string if the word is more than 5 characters void longWords(ifstream& fin, string& str) { string buffer; while (fin >> buffer) { if (buffer.size()>5) str += buffer + '\n'; } } void MrOrMs(string& name, char gender) { if (gender == 'M') name = "Mr. " + name; else name = "Ms. " + name; } // Write a function that opens a file for output, given an ofstream object void open(ofstream& fout) { string name; cout << "what's the file name? "; cin >> name; fout.open(name); } // Write a function that "populates" a grade variable, given a percent void getGrade(int pct, char& gr) { switch (pct/10) { case 10: // "fall through" case 9: gr = 'A'; break; case 8: gr = 'B'; break; case 7: gr = 'C'; break; case 6: gr = 'D'; break; default: gr = 'F'; } } // Write a function that adds 5 to a given int void add5(int& i) { i += 5; }