In this project, you will sort envelopes as they arrive at the post office. Your
ID: 662203 • Letter: I
Question
In this project, you will sort envelopes as they arrive at the post office. Your program should sort the envelopes by Zip code and assign them to one of the four mail carrier. Zip codes are assigned to mail carrier using the following informaton:
Mail Carrier Zip Code
Greg ----------------------------------60515
Natalie -------------------------------60516
Lynne --------------------------------60517
Ed -------------------------------------60512
The data for this program are saved in the file named Lettes.dat below. This file contains the name of the person, to whom the letter is addressed, and the addressees street address, city, state, and Zip code information.
You will create all necessary constructors for the Letter class by using default function arguments, if appropriate. In addition, you should implement the name, street, city, and state dynamically instead of an array of characters, and the zip as integer. Make sure that you write a destructor for this class, as you are now using dynamically allocated memory. You should also overload the comparison operators(>,<,==,!=,>=, and <=)so that you can sort the mail by carrier. In addtion, you will need to overload the assignment operator(=). Your specification file(i.e., letter.h)should have a copy constructor, the set methods and get methods for name, street, city, state, and zip.
Read the data from the file Letter.dat and print the information by mail carrier. Use the following prototype for the print fuction:
Void print(Letter*, int);
You should have the following files:letter.h,letter.cpp,and letter_drvr.cpp.
Letters,dat File
Mary Beacom
1111 First Street
Downers Grove
IL
60515
Delaney Benson
2222 Second Street
Downers Grove
IL
60516
Natalie Johnson
3333 Third Street
Downers Grove
IL
60517
Karen Egan
4444 Fourth Street
Woodridge
IL
60512
Jeanne Brocious
5555 Fifth Street
Woodridge
IL
60512
Cathy Jezek
6666 Sixth Street
Downers Grove
IL
60515
Mike Stancati
7777 Seventh Street
Downers Grove
IL
60515
Helga Ertas
8888 Eight Street
Downers Grove
IL
60516
Tejas Vakil
9999 Ninth Street
Downers Grove
IL
60517
Joyce Koerfer
1212 First Street
Downers Grove
IL
60515
MaryAnn Zlotow
3232 Second Street
Downers Grove
IL
60517
Lynne Swiatek
8765 Fifth Street
Woodridge
IL
60512
Explanation / Answer
#include <iostream>
using namespace std;
class Letter{
private :
string first,last,streetn,staten;
public:
Letter(string fname, string lname, string street, string state){
first = fname;
last = lname;
streetn = street;
staten = state;
}
string Details(){
return first + " " + last + " " + streetn + " " + staten ;
}
};
int main()
{
string street, city, state;
int zipc;
cout << "Enter the Zip Code " << endl;
cin >> zipc ;
if(zipc == 60515) {
cout << " Route assigned to Greg" << endl;
Letter Myenvelope( "Mary", "Beacom", "1111 First Street", "IL");
Letter Myenvelope1( "Cathy", "Jezek"), "6666 Sixth Street", "IL");
Letter Myenvelope2( "Mike", "Stancati"), "7777 Seventh Street", "IL");
Letter Myenvelope3( "Joyce", "Koerfer"), "1212 First Street", "IL");
cout << Myenvelope.Details() << endl;
cout << Myenvelope1.Details() << endl;
cout << Myenvelope2.Details() << endl;
cout << Myenvelope3.Details() << endl;
}
else if (zipc == 60516) {
cout << "Route assigned to Natalie" << endl;
Letter Myenvelope4( "Helga", "Ertas", "8888 Eighth Street", "IL");
Letter Myenvelope5( "Delaney", "Benson", "2222 Second Street", "IL");
cout << Myenvelope4.Details() << endl;
cout << Myenvelope5.Details() << endl;
}
}
else if (zipc == 60517) {
cout << "Route assigned to Lynn" << endl;
Letter Myenvelope6( "Natalie", "Johnson", "3333 Third Street", "IL");
Letter Myenvelope7( "Tejas", "Vakil", "9999 Ninth Street", "IL");
Letter Myenvelope8( "MaryAnn Zlotow", "3232 Second Street", "IL");
cout << Myenvelope6.Details() << endl;
cout << Myenvelope7.Details() << endl;
cout << Myenvelope8.Details() << endl;
}
else if(zipc == 60512) {
cout << " Route assigned to Ed" << endl;
Letter Myenvelope6( "Lynne", "Swiatek", "8765 Fifth Street", "IL");
Letter Myenvelope7( "Karen", "Egan", "4444 Forth Street", "IL");
Letter Myenvelope8( "Jeanne", "Brocious", "5555 Fifth Street", "IL");
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.