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

In visual studio, I have to create a Mail class with two properties: State and C

ID: 3570330 • Letter: I

Question

In visual studio, I have to create a Mail class with two properties: State and Cost. I have to use Mail as an array throughout. Must be done on visual studio. Only use loops, class, if statements, arrays and functions. See the code below. I need it amended to fit the directions above.

#include <iostream>
#include <string>

using namespace std;

void AddNewPackage(string state[], double cost[], int &count);
void SearchByState(string state[], double cost[], int &count);
void SearchByCost(string state[], double cost[], int &count);
void Report(string state[], double cost[], int &count);

int main(){

   // we keep data in arrays
   string state[1000]; // which state mail goes to
   double cost[1000];   // how much is the cost of the mail
   int count = 0;       // how many records in the array currently

   cout << "================================================" << endl;
   cout << "Welcome to FedEx in the middle of nowhere. :-)" << endl;
   cout << "This tool will help you keep track of packages." << endl;
   cout << "================================================" << endl;

   while (true) // loop forever (or until we break somehwere inside the loop)
   {
       cout << endl;
       cout << "1- Create New Mail" << endl;
       cout << "2- Search Mail (by State)" << endl;
       cout << "3- Search Mail (by Cost)" << endl;
       cout << "4- Grand Report" << endl;
       cout << "0- Exit" << endl;
       cout << "What do you want to do? ";
       int choice;
       cin >> choice;

       if (choice == 1)
       {
           AddNewPackage(state, cost, count);
       }
       else if (choice == 2)
       {
           SearchByState(state, cost, count);
          
       }
       else if (choice == 3)
       {
           SearchByCost(state, cost, count);

       }
       else if (choice == 4)
       {
           Report(state, cost, count);
       }
       else if (choice == 0)
       {
           // user wants to quit! let's break :-)
           break;
       }
       else
       {
           cout << "Invalid choice, try again." << endl;
       }
   }

   system("PAUSE");
   return 0;
}

// adds a new package to the system
// notice the & character to make count send by reference
void AddNewPackage(string state[], double cost[], int &count)
{
   string destState;
   cout << "Destination State (two letter, no space): ";
   cin >> destState;

   double packageCost;
   cout << "Cost of this delivery?";
   cin >> packageCost;

   // put information into arrays at next available slot
   state[count] = destState;
   cost[count] = packageCost;

   count++; // increment the counter to the next available slot
}

// displays all packages for a certain state
void SearchByState(string state[], double cost[], int &count)
{
   string searchState;
   cout << "Enter state you want to see (two letter, no space): ";
   cin >> searchState;

   cout << "Here are the packages to " << searchState << ":" << endl;

   for (int i = 0; i < count; i++)
   {
       if (state[i] == searchState)
       {
           cout << "Package to " << state[i] << " for $" << cost[i] << endl;
       }
   }
}

// displays all packages that cost more than the specified amount
void SearchByCost(string state[], double cost[], int &count)
{
   double searchCost;
   cout << "Enter minimum package price: ";
   cin >> searchCost;

   cout << "Here are the packages that are larger in value than " << searchCost << ":" << endl;

   for (int i = 0; i < count; i++)
   {
       if (cost[i] > searchCost)
       {
           cout << "Package to " << state[i] << " for $" << cost[i] << endl;
       }
   }
}

// displays all records
void Report(string state[], double cost[], int &count)
{
   cout << "Here are all the packages for today: " << endl;
   double total = 0;
   for (int i = 0; i < count; i++)
   {
       cout << "Package to " << state[i] << " for $" << cost[i] << endl;
       total += cost[i];
   }
   cout << "Total cost for all packages today so far is $" << total << "." << endl;
}

Explanation / Answer

#include <iostream>
#include <string>

using namespace std;

class Mail{
private :
string state;
double cost;

public :
void setState(string s){
state = s;
}
void setCost(double d){
cost = d;
}

string getState(){
return state;
}

double getCost(){
return cost;
}
};

/*void AddNewPackage(string state[], double cost[], int &count);
void SearchByState(string state[], double cost[], int &count);
void SearchByCost(string state[], double cost[], int &count);
void Report(string state[], double cost[], int &count);*/

void AddNewPackage(Mail arr[], int &count);
void SearchByState(Mail arr[], int &count);
void SearchByCost(Mail arr[], int &count);
void Report(Mail arr[], int &count);

int main(){

// we keep data in arrays
//string state[1000]; // which state mail goes to
//double cost[1000]; // how much is the cost of the mail
Mail arr[1000];
int count = 0; // how many records in the array currently

cout << "================================================" << endl;
cout << "Welcome to FedEx in the middle of nowhere. :-)" << endl;
cout << "This tool will help you keep track of packages." << endl;
cout << "================================================" << endl;

while (true) // loop forever (or until we break somehwere inside the loop)
{
cout << endl;
cout << "1- Create New Mail" << endl;
cout << "2- Search Mail (by State)" << endl;
cout << "3- Search Mail (by Cost)" << endl;
cout << "4- Grand Report" << endl;
cout << "0- Exit" << endl;
cout << "What do you want to do? ";
int choice;
cin >> choice;

if (choice == 1)
{
AddNewPackage(arr, count);
}
else if (choice == 2)
{
SearchByState(arr, count);

}
else if (choice == 3)
{
SearchByCost(arr, count);

}
else if (choice == 4)
{
Report(arr, count);
}
else if (choice == 0)
{
// user wants to quit! let's break :-)
break;
}
else
{
cout << "Invalid choice, try again." << endl;
}
}

// system("PAUSE");
return 0;
}

// adds a new package to the system
// notice the & character to make count send by reference
void AddNewPackage(Mail arr[], int &count)
{
string destState;
cout << "Destination State (two letter, no space): ";
cin >> destState;

double packageCost;
cout << "Cost of this delivery?";
cin >> packageCost;

// put information into arrays at next available slot
arr[count].setState(destState);
arr[count].setCost(packageCost);

count++; // increment the counter to the next available slot
}

// displays all packages for a certain state
void SearchByState(Mail arr[], int &count)
{
string searchState;
cout << "Enter state you want to see (two letter, no space): ";
cin >> searchState;

cout << "Here are the packages to " << searchState << ":" << endl;

for (int i = 0; i < count; i++)
{
if (arr[i].getState() == searchState)
{
cout << "Package to " << arr[i].getState() << " for $" << arr[i].getCost() << endl;
}
}
}

// displays all packages that cost more than the specified amount
void SearchByCost(Mail arr[], int &count)
{
double searchCost;
cout << "Enter minimum package price: ";
cin >> searchCost;

cout << "Here are the packages that are larger in value than " << searchCost << ":" << endl;

for (int i = 0; i < count; i++)
{
if (arr[i].getCost() > searchCost)
{
cout << "Package to " << arr[i].getState() << " for $" << arr[i].getCost() << endl;
}
}
}

// displays all records
void Report(Mail arr[], int &count)
{
cout << "Here are all the packages for today: " << endl;
double total = 0;
for (int i = 0; i < count; i++)
{
cout << "Package to " << arr[i].getState() << " for $" << arr[i].getCost() << endl;
total += arr[i].getCost();
}
cout << "Total cost for all packages today so far is $" << total << "." << endl;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote