Untitled
unknown
plain_text
a year ago
2.8 kB
7
Indexable
#include <iostream>
#include <fstream>
#include <string>
#include <filesystem>
#include <vector>
using namespace std;
void checkInbox();
int displayMenu();
void WriteToOutbox();
int main() {
//TODO: Display a menu of options and prompt the user to choose from those available (including quitting)
switch(displayMenu()) {
case -1:
cout << "Error selection out of bound" << endl;
break;
case 2:
WriteToOutbox();
default:
cout << "default" << endl;
}
//Make sure to handle invalid input!
return 0;
}
void checkInbox() {
//TODO: create a vector of strings to store the filenames
for (const auto& entry : std::filesystem::directory_iterator("inbox")) {
if (entry.is_regular_file()) { // Ensure it's a file, not a directory
string filename = entry.path();
//TODO: add each filename to a vector of strings
}
}
//TODO: Present the user with a numbered list of their inbox emails
// include the filename and the subject
//TODO: Ask the user for the number of the email to open, or 0 to return to the main menu
// if they open an email, display its full contents, then ask if they want to open another
}
int displayMenu() {
int num = 0;
cout << "Email Management System" << endl;
cout << "1. Check Inbox" << endl;
cout << "2. Write Email" << endl;
cout << "3. Filter Spam" << endl;
cout << "4. Filter Spam + Ham" << endl;
cout << "5. Exit" << endl;
cout << "Enter your choice: ";
cin >> num;
cin.ignore();
if (num < 1 || num > 5) {
return -1;
} else {
return num;
}
}
void WriteToOutbox() {
string recipient = "";
cout << "Enter recipient email" << endl;
cin >> recipient;
cin.ignore();
string subjectLine = "";
cout << "Enter the subject line" << endl;
cin >> subjectLine;
cin.ignore();
int emptyCounter = 0;
string body = "";
string line = "";
cout << "Please enter email body. Enter 2 empty lines to finish:\n";
while(true) {
getline(cin,line);
if(line.empty()) {
emptyCounter++;
} else {
emptyCounter = 0;
}
if (emptyCounter == 2) {
break;
}
body += line + '\n';
}
string filename = "";
cout << "Enter the filename" << endl;
cin >> filename;
cin.ignore();
ofstream EmailFile(filename);
EmailFile << recipient << endl << subjectLine << endl << body << endl;
EmailFile.close();
}Editor is loading...
Leave a Comment