Hello,
My main problem currently is what to do exactly for this program. I have no idea on where to go or what to add or change. I am trying to read information from a file, and then change the format of the information. For example, I need to change the name format to have the middle name have just the first letter and a period. Such as "Chris Jones Johnson" to become "Johnson, Chris J." I also need to format time given as "10:10 PM" to military time. I also need to encrypt a message from the file. Here is the code I have so far. Please tell me what I need to delete or add or change.
Thank you in advance,
Roy
Code:#include <iostream> #include <cstdlib> #include <fstream> #include <string> #include <sstream> #include <vector> #include <iomanip> using namespace std; string mtime(string time, ofstream &date); int main() { ifstream blog; ofstream outblog; char file[30]; char o, e, i; int key, b; string originalChar, echar, tempchar ; istringstream Name, Date, Code; //Used to sort data from the file string fname, lname, mname, time, name[3]; cout << "Please enter the name of a blog file:" << endl; cin >> file; cout << "Please enter an encryption key between 1 and 100" << endl; //Used to encrypt the file cin >> key; if (key < 1 || key > 100) { cout << "The key entered was not between 1 and 100" << endl; //Makes sure the user inputs within the range return 0; exit(0); } blog.open("file"); if (blog.fail()) { //Makes sure the file was opened sucessfully perror("blog"); exit(0); } getline(blog, name[3]); Name.str(name[3]); while (Name >> name[3]) { //Supposed to read data into the given variables. Name >> fname >> mname >> lname; mname.substr(0, 2); mname.insert(1, "."); } getline(blog, time); Date.str(time); while (Date >> time) { Date >> time; b = time.find(":"); time.erase(b, 1); time.insert(b, " "); } getline(blog, originalChar); Code.str(originalChar); Code >> originalChar; for (i = 0; i < originalChar.length(); i++) { tempchar = originalChar; if (originalChar.at(i) + key > 126) { //Encrypts the message from the blog file. originalChar.at(i) = 32 + ((o + key ) - 127); } else { originalChar.at(i) = (o + key); } } echar = originalChar; cout << echar << endl; mtime; } string mtime(string time, ofstream &date) { //Switches around the time format to military time while (date << time) { int b, hours, minutes; string Day; b = mtime.find(":"); mtime.erase(b, 1); mtime.insert(" "); mtime >> hours >> minutes >> "hours"; if (time.find("PM")) { hours = hours + 12; } istringstream ntime; date << setw(2) << hours << minutes << Day; cout << date; } }]



LinkBack URL
About LinkBacks


