Question

In: Computer Science

Project 6-1: Email Creator C++ code Create a program that reads a file and creates a...

Project 6-1: Email Creator

C++ code

Create a program that reads a file and creates a series of emails.

Console

Email Creator

================================================================

To:      [email protected]

From:    [email protected]

Subject: Deals!

Hi James,

We've got some great deals for you. Check our website!

================================================================

To:      [email protected]

From:    [email protected]

Subject: Deals!

Hi Josephine,

We've got some great deals for you. Check our website!

================================================================

To:      [email protected]

From:    [email protected]

Subject: Deals!

Hi Art,

We've got some great deals for you. Check our website!

Specifications

  • Your instructor should supply you with a file named email_list.txt that contains a list of email addresses in this format:

james\tbutler\[email protected]

josephine\tdarakjy\[email protected]

art\tvenere\[email protected]

  • Your instructor should supply you with a file named email_template.txt that provides a template for a mass email in a file like this:

To:      {email}
From:    [email protected]
Subject: Deals!

Hi {first_name},

We've got some great deals for you. Check our website!

  • When the program starts, it should read the email addresses and first names from the file, merge them into the mass email template, and display the results on the console.
  • All email addresses should be converted to lowercase.
  • All first names should be converted to title case.
  • If you add names to the list of email addresses, the program should create more emails.
  • If you modify the template, the program should change the content of the email that’s created.

-------------------

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]

Solutions

Expert Solution

#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...


Related Solutions

This is C++ Create a program that reads an HTML file and converts it to plain...
This is C++ Create a program that reads an HTML file and converts it to plain text. Console: HTML Converter Grocery List * Eggs * Milk * Butter Specifications: The HTML file named groceries.html contains these HTML tags: <h1>Grocery List</h1> <ul> <li>Eggs</li> <li>Milk</li> <li>Butter</li> </ul> When the program starts, it should read the contents of the file, remove the HTML tags, remove any spaces to the left of the tags, add asterisks (*) before the list items, and display the...
c++ Create a program that creates a sorted list from a data file. The program will...
c++ Create a program that creates a sorted list from a data file. The program will prompt the user for the name of the data file. Create a class object called group that contains a First Name, Last Name, and Age. Your main() function should declare an array of up to 20 group objects, and load each line from the input file into an object in the array. The group class should have the following private data elements: first name...
C++ Program -------------------- Project 5-1: Monthly Sales Create a program that reads the sales for 12...
C++ Program -------------------- Project 5-1: Monthly Sales Create a program that reads the sales for 12 months from a file and calculates the total yearly sales as well as the average monthly sales. Console Monthly Sales COMMAND MENU m - View monthly sales y - View yearly summary x - Exit program Command: m MONTHLY SALES Jan        14317.41 Feb         3903.32 Mar         1073.01 Apr         3463.28 May         2429.52 Jun         4324.70 Jul         9762.31 Aug        25578.39 Sep         2437.95 Oct         6735.63 Nov          288.11 Dec         2497.49...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
How to do in C++ HTML Converter Create a program that reads an HTML file and...
How to do in C++ HTML Converter Create a program that reads an HTML file and converts it to plain text. Console HTML Converter Grocery List * Eggs * Milk * Butter Specifications Your instructor should provide an HTML file named groceries.html that contains these HTML tags: <h1>Grocery List</h1> <ul>     <li>Eggs</li>     <li>Milk</li>     <li>Butter</li> </ul> When the program starts, it should read the contents of the file, remove the HTML tags, remove any spaces to the left of the tags, add...
Create a C Program that reads a file and replaces every other letter with an asterisk....
Create a C Program that reads a file and replaces every other letter with an asterisk. The first integer 'num' is the number of lines. Include an "Error" Message and exit the program if:    The wrong name for the input/output file is given    The input/output file can not be opened input.txt 7 Never Have We Ever Played A Game output.txt 7 N*v*r *a*e W* *v*r *l*y*d * G*m*
Write a program in c++ that reads x[4]. Then create the array y[6||6], such that the...
Write a program in c++ that reads x[4]. Then create the array y[6||6], such that the first quarter of y consists of the value of the first element of x. The second quarter of y consists of the value of the second element of x. The third quarter of y consists of the value of the third element of x. The fourth quarter of y consists of the value of the fourth element of x?
C++ Write a program that prompts for a file name and then reads the file to...
C++ Write a program that prompts for a file name and then reads the file to check for balanced curly braces, {; parentheses, (); and square brackets, []. Use a stack to store the most recent unmatched left symbol. The program should ignore any character that is not a parenthesis, curly brace, or square bracket. Note that proper nesting is required. For instance, [a(b]c) is invalid. Display the line number the error occurred on. These are a few of the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT