Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Spammer's Delight Problem OLA205 Exercise Due: by Midnight March 2, 2022 NOTE: Please remember that exercises are due by the stated time and cannot

The Spammer's Delight Problem

OLA205 Exercise Due: byMidnightMarch 2, 2022 NOTE: Please remember thatexercisesare due by the stated time and cannot be late.

PERSPECTIVE:We need practice in using files and strings and we don't have much time. This short assignment should provide that practice.

PROBLEM BACKGROUND:Assume you're working on a contract where a company is building a mailing list (or, rather, an e-mailing list) by analyzing e-mail messages. Your task is to write a C++ program that reads an e-mail (stored in the current working directory) calledmail.datand outputs to a file calledaddresses.dat, one per line, every e-mail address contained inside the file. (You can see now why this assignment is titled"The Spammer's Delight Problem".) For this assignment, if a whitespace delimited string of characters has an embedded commercial at sign (@) inside it (that is, anywhere in the string), we shall consider it an e-mail address. (Yes, this is somewhat simplistic---it allows, for example, an@at the beginning or end of the string.) However,any trailing commas must be trimmed from addresses. Thus the string "abc@mtsu.edu," must appear in the output file as "abc@mtsu.edu" with the trailing comma removed. Only commas at the end of a string are considered trailing; do not remove non-trailing commas. Do not worry about any other punctuation characters; the only editing your program must do is to removetrailing commas. [This is essentiallyProgramming Problem 5found in the (former) Dale/Weems textbook on page 303 of Chapter 6.]

IMPLEMENTATION NOTES:Use as your source file name "spammer.cpp". This program is short enough to be coded entirely in themain()routine---do so;do notdefine any additional user-defined functions. Use comments to clarify your variable declarations (i.e., usevariable dictionary formatin your declarations). Use only C++ constructs found in Chapters 1 through 6 and 10 of the textbook; the idea is to keep the program simple and straightforward. Don't forget to head your source file with the standard title line and global comments we use for all programming assignments. Be sure to have code toclose()both files that youopened. As stated in the Dale/Weems problem statement, aninput stringis defined (by the C++ stream reader) as a sequence of characters with no intervening whitespace characters. (This makes the program SO much easier!)

INPUT/OUTPUT:You should create your own input data file(s) to initially test your program. For grading, link the file$PUB/mail.datinto your work area and use it. The command ln s $PUB/mail.dat mail.dat will do that. (Be sure tolink,notcopy, the file into your work area.) For your output file, use the filenameaddresses.dat. Do not write anything to stdout or stderr (i.e., do not usecoutorcerrin your final product). The first 10 lines of youraddresses.datfile should look like:

mikkiflower@gm@il.com

mikkiflower@gm@il.com

info@academart.edu

alvarolanchart@apanimationschool.com

dst@asu.edu

"hanish,frank"@wsi-gris.uni-tuebingen.de

ansen@cs.utah.edu

REQUIRED:You are to electronically submit the source program, a source program listing and run log, and the output file obtained from running your program against the sample input (see above). Once you have a working program, the following UNIX commands will do what is required:

$ script ola205.log

$ rm -f mail.dat addresses.dat

$ ln -s $PUB/mail.dat mail.dat

$ pr -n -t -e4 spammer.cpp

$ c++ spammer.cpp -o ola205

$ ola205

$ cat addresses.dat

$ exit (Be sure to exit the script session before trying to do the handin!)

$ handin "ola205" spammer.cpp addresses.dat ola205.log

NOTE:You should work alone on this assignment; neither offer nor accept any additional help, except on a one-to-one basis with the instructor.

HINTS:Some of the string methods found in Table 10-9 of the textbook may be useful in coding the solution to this problem.

GRADING: In addition to examining your source code and the execution results obtained by running your program against the data set above, the grader may run your program against some additional (and unknown to you) data sets. Your program must work properly for any valid input to be considered correct.

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

Here is my code

// ola205 BY student name, CSCI 2170-003, Due: 3/1/2022 // PROGRAM ID: spammer.cpp / The Spammer's Delight Problem // AUTHOR: //Remarks:

#include #include using namespace std;

int main() { string str; int n;

ifstream in("mail.dat"); // opens input file ofstream out("addresses.dat"); // writes to output file

while(in>>str) // read the strings in file until end of file { n = str.length(); // length of word or string for(int i=0; i { if(str[i] == '@') // search for @ in a string in the input file { if(str[n-1] == ',') // if a trailing comma is found then this will ommit it { n=n-1; // trim the string by 1 character } for(int j =0; j { out } out<" "; print="" a="" next="" line="" in="" output=""> } } } return 0; }

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

here is the addresses.dat file

ikkiflower@gm@il.com mikkiflower@gm@il.com info@academart.edu alvarolanchart@apanimationschool.com dst@asu.edu "hanish,frank"@wsi-gris.uni-tuebingen.de ansen@cs.utah.edu mthomas@aracademy.edu sberkan@artcenter.edu lcoper@artcenter.edu cbar@artcenter.edu rclayon@artcenter.edu azerad@artcenter.edu aicafadm@aii.edu thome@saic.edu Deiseberg@saic.edu sfare@saic.edu ne11@fac.aii.edu jeses@aii.edu grifitc@aii.edu aippres@aii.edu chapelm@aii.edu nmclarence@aii.edu sye@aii.edu dheap@aii.edu wwake@aii.edu hestman@aii.edu dma81@fac.aii.edu crohd@aii.edu shughes@aii.edu aiadm@aii.edu oliver.biber@medien.uni-weimar.de sclarof@cs.bu.edu bilmark@cs.utexas.edu pflower@uarts.edu zeml@cs.toronto.edu mrj3@ber.ac.uk sales@cs.washington.edu curles@cs.washington.edu weghor@u.washington.edu counselling@uwo.ca smith@uwsp.edu

schoolse@uvsc.edu al@mcap.ca inf@vanarts.com art@vcu.edu jhseip@vcu.edu jgabard@vt.edu nfo@sc.waseda.ac.jp gary.scid@washburn.edu heroes@earthlink.net ksingh@mail.arch.wsu.edu rish@wellesley.edu por@wellesley.edu gorham@wvu.edu geor@wilamette.edu karuhr@wilamette.edu sv2007@siggraph.org Mikki_Flower@siggraph.org

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

I am kind of confused on what my output is suppose to be. The output that came out was exaclty the addresse.dat file

Can you pls help me with this?

btw i change the gm@il becasue of the guildlines

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Strategic Management Competitiveness and Globalization, Concepts and Cases

Authors: Michael A.Hitt, R.Duane Ireland, Robert E.Hoskisson

11th edition

978-1285425177, 1285425170, 978-1305200333, 978-1285425184

More Books

Students also viewed these General Management questions

Question

Explain the six common forms of union security clause. LO.1

Answered: 1 week ago