In: Computer Science
Project 6-1: Email Creator
C++ code
Create a program that reads a file and creates a series of emails.
Console
Email Creator
================================================================
From: [email protected]
Subject: Deals!
Hi James,
We've got some great deals for you. Check our website!
================================================================
From: [email protected]
Subject: Deals!
Hi Josephine,
We've got some great deals for you. Check our website!
================================================================
From: [email protected]
Subject: Deals!
Hi Art,
We've got some great deals for you. Check our website!
Specifications
james\tbutler\[email protected]
josephine\tdarakjy\[email protected]
art\tvenere\[email protected]
To: {email}
From: [email protected]
Subject: Deals!
Hi {first_name},
We've got some great deals for you. Check our website!
-------------------
Text files
(email_template.txt)
To: {email}
From: [email protected]
Subject: Deals!
Hi {first_name},
We've got some great deals for you. Check our website!
email_list.txt
james butler [email protected]
josephine darakjy
[email protected]
art venere [email protected]
#include<iostream>
#include<fstream>
#include<cctype>
#include<string>
using namespace std;
string toLower(const string &str);
int main(){
ifstream in;
in.open("email_template.txt");
if(in.fail()){
cout<<"Unable to open email_template.txt"<<endl;
return -1;
}
string line, fname, uname, email;
string temp_copy, temp="";
int pos;
while(!in.eof()){
getline(in, line);
temp += line+"\n";
}
in.close();
in.open("email_list.txt");
if(in.fail()){
cout<<"Unable to open email_list.txt"<<endl;
return -1;
}
cout<<"Email Creator"<<endl<<endl;
while(!in.eof()){
in>>fname>>uname>>email;
fname = toLower(fname);
fname[0] = toupper(fname[0]);
email = toLower(email);
temp_copy = temp;
while((pos=temp_copy.find("{email}"))!=string::npos){
temp_copy.replace(pos, 7, email);
}
while((pos=temp_copy.find("{first_name}"))!=string::npos){
temp_copy.replace(pos, 12, fname);
}
cout<<"========================================================"<<endl;
cout<<temp_copy;
}
in.close();
return 0;
}
string toLower(const string &str){
string result = "";
for(int i=0; i<str.size(); i++){
result += tolower(str[i]);
}
return result;
}
Let me know if yo have any clarifications. Thank you...