VISUAL STUDIO (C++) FedEx has hired you to write a little utility program to hel
ID: 3707697 • Letter: V
Question
VISUAL STUDIO (C++)
FedEx has hired you to write a little utility program to help out shipping locations without digital (Internet) connection to outside world. For example, North Pole office do not have connection to the central FedEx system or the Internet. Yes, Fedex wants to open up an office in North Pole :D Welcome to FedEx in the middle of nowhere. - This tool will help you keep track of packages. 1-Create New Mail 2- Search Mail (by State> 3- Search Mail Cby Cost) 4-Grand Report -Exit What do you want to do? 1 Destination State (two letter, no space NY Cost of this delivery?18.99 1- Create New Mai1 2- Search Mail (by State 3- Search Mail (by Cost 4- Grand Report 0-Exit What do you want to do? 1 Destination State (tuo letter. no space CA Cost of this delivery?5.99 Now, for these offices FedEx needs a little utility program to help their staff keep track of packages Here are the features of the program 1- Create New Mail 2- Search Mail Cby State> 3- Search Mail (by Cost> 4- Grand Report 0-Exit What do you want to do? 2 Enter state you want to see (tuo letter, no space Here are the packages to CA Package to CA for 55.99 [40]1- Create New Mail: Allows us to enter a package to the system. We need two pieces of information from the user: a) the state where the package is going (2 letter abbreviation) and b) the cost of the delivery CA 1- Create New Mail 2- Search Mail Cby State> 3- Search Mail (by Cost 4- Grand Report 0- Exit What do you want to do? 3 Enter nininum package price: 6.08 Here are the packages that are larger in value than 6: Package to NY for $10.99 [30] 2- Search Mail (by State): Takes a state name (two letter abbreviation) from user and goes through all the packages entered into the system and displays those that are going to that state 1-Create New Mail 2- Search Mail 3- Search Mail (by Cost 4- Grand Report 0- Exit What do you want to do? 4 Here are all the packages for today: Package to NY for $18.99 Package to CA for $5.99 Total cost for all packages today so far is $16.98 [30] 3- Search Mail (by Cost): Takes a dollar amount from user. Then displays all packages in the system with cost larger than the amount entered [30] 4- Grand Report: Displays all packages entered into the system. 1- Create New Mail 2- Search Mail 3- Search Mail by Cost) 4- Grand Report 0- Exit What do you want to do? 0 Press any key to continue .. . [10j 0-Exit: Exits the program (duh!!) [30] Comments and Indentations [30] Implement File I/O so we don't lose package information (saving and reading) [50] Each feature should be implemented in its own function. You are required to use prototypes for the functions . . . You can assume there are at most 1000 packages per day (for specifying the size of your arrays) Mail and Package is the same thing! - don't get confused Refer to screenshot displayed aboveExplanation / Answer
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
struct Mail{
string state;
double cost;
};
void createMail(Mail data[], String state, double cost,int &count){
data[count].state = state;
data[count].cost = cost;
count++;
}
void searchByState(Mail data[], String state,int count){
int found = 0;
for (int i = 0; i<count; i++){
if (data[i].state == state){
if (found == 0){
cout << "Here are the packages to " << state << endl;
found = 1;
}
cout << "Package to " << data[i].state << " for $" << data[i].cost << endl;
}
}
if (found == 0)
cout << "No records found ";
}
void searchByCost(Mail data[], double cost,int count){
int found = 0;
for (int i = 0; i<count; i++){
if (data[i].cost > cost){
if (found == 0){
cout << "Here are the packages to " << state << endl;
found = 1;
}
cout << "Package to " << data[i].state << " for $" << data[i].cost << endl;
}
}
if (found == 0)
cout << "No records found ";
}
void grandReport(Mail data[], int count){
for (int i = 0; i<count; i++){
cout << "Package to " << data[i].state << " for $" << data[i].cost << endl;
}
}
int main(){
Mail data[1000];
String state;
double cost;
int ch;
cout << "============================================= ";
cout << "Welcome to FedEx in the moddle pf nowhere.:-> ";
cout << "This tool will help you keep track of packages ";
cout << "============================================= ";
int count = 0;
ifstream fin("mail.txt");
if (fin){
while (fin >> data[count].state >> data[count].cost){
count++;
}
fin.close();
}
else {
cout << "Error opening file ";
}
while (true){
cout << "1.Create New Mail ";
cout << "2.Search Mail (By State) ";
cout << "3.Search Mail (By Cost) ";
cout << "4.Grand Report ";
cout << "0.Exit ";
cout << "What do you want to do:";
cin >> ch;
if (ch == 0){
break;
}
if (ch == 1){
cout << "Destination state (two letter, no space):";
cin >> state;
cout << "Cost of the delivery? ";
cin >> cost;
createMail(data,state,cost,count);
}
if (ch == 2){
cout << "Enter state you want to see (two letters, no space):";
string state;
cin >> state;
searchByState(data,state,count);
}
if (ch == 3){
cout << "Enter minimum package price:";
double cost;
cin >> cost;
searchByCost(data,cost,count);
}
if (ch == 4){
grandReport(data);
}
}
ofstream fout("mail.txt");
for (int i = 0; i<count; i++){
fout << data[i].state << " " << data[i].cost << endl;
}
fout.close();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.