Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the program using nested loops with the while statement. You\'re working f

ID: 3723776 • Letter: W

Question

Write the program using nested loops with the while statement.

You're working for a company that's building an email list from files of mail messages. Your boss would like you to write a program that reads a file called mail.dat, and that outputs every string containing the sign to file addresses.dat. For the purpose of this project, a string is defined as it is by the C++ stream reader-a contiguous sequence of non-whitespace characters. Given the data From sharon@marzipan.edu Date: Wed, 13 Aug 2003 17:12:33 EDT Subject: Re: hi To: john@meringue.com John, Daves email is dave smitheicing.org ttyl, sharon the program would output the following information on file addresses.dat: sharon@marzipan.edu john@meringue.com dave smith@icing.org Use meaningful variable names, proper indentation, and appropriate comments. Thoroughly test the program using vour own data sets

Explanation / Answer

#include <fstream>
#include <sstream>
#include <string>
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
ifstream infile("mail.dat"); //name of input file
ofstream outfile("addressess.dat"); // name of output file
string line;   

while (getline(infile, line)) // Reading mail.txt file line by line
{
// Checks whether line contains an email id. i.e. "@"
if(line.find("@") != string::npos )
{
//This if block takes care of the lines which do not contain space but only "@" .
if(line.find(" ") == string::npos)
{
//cout << line <<endl;
outfile << line<<endl;
}
// This else block take care if line contains " " and "@"
else
{
string temp_str;
// if(line.at(0) == ' ')
temp_str = line.substr(line.find(" ")+1);

while(temp_str.find(" ") != string::npos )
{
  
if(temp_str.find(" ") > temp_str.find("@") )
outfile << temp_str.substr(0,temp_str.find(" "))<< endl;

temp_str = temp_str.substr(temp_str.find(" ")+1);

}
//cout<< temp_str <<endl;

  
outfile << temp_str << endl; //dumping email address into the output file.

}// end of inner if
} // end of outer if
} // end of while

return 0;
}