#include #include #include struct MailingAddress { char *name; char *address; char *city_state_zip; }; struct Package { MailingAddress address; // (where its being sent) int length; // (in inches) int width; //(in inches) int depth; //(in inches) int weight; //(in oz) double rate; double shipping_price; }; //Reads the number of packages from the user int readNumPackages(); //Reads package information from the user and stores it in the package records. //Calculates the rate based on the weight and the volume. Returns the records via a pointer Package* readPkgInfo(int no_of_packages); //Calculates the price for each package based on the weight and rate void calculatePrice(Package* package,int no_of_packages); //Display the postal information for each package void displayInfo(Package* package, int no_of_packages); int main(void) { int no_of_packages = 0; Package* package; //Get the number of packages from the user no_of_packages = readNumPackages(); //Get package information from the user and calculate the rate package = readPkgInfo(no_of_packages); //Calculate the price of the package calculatePrice(package, no_of_packages); //Display the package information displayInfo(package, no_of_packages); return 0; }//end of function main int readNumPackages() { int no_of_packages = 0; char buffer[255]; //Prompt the user for number of packages cout << "Please enter the number of packages: "; cin.getline(buffer,sizeof(buffer)); no_of_packages = atoi(buffer); return (no_of_packages); }//end of function readNumPackages Package* readPkgInfo(int no_of_packages) { Package* package; int i = 0; char buffer[255]; int volume = 0; //Dynamically allocate the number of packages needed package = new Package[no_of_packages]; for(i = 0; i < no_of_packages; i++) { cout << endl << "Please enter the address information for Package " << i+1 << endl; cout << "Name: "; cin.getline(buffer,sizeof(buffer)); package[i].address.name = new char[strlen(buffer) + 1]; strcpy(package[i].address.name,buffer); cout << endl << "Street Address: "; cin.getline(buffer,sizeof(buffer)); package[i].address.address = new char[strlen(buffer) + 1]; strcpy(package[i].address.address,buffer); cout << endl << "City, State, Zip code: "; cin.getline(buffer,sizeof(buffer)); package[i].address.city_state_zip = new char[strlen(buffer) + 1]; strcpy(package[i].address.city_state_zip,buffer); cout << endl << "Please enter the measurements for package " << i+1 << endl; cout << "Length in inches: "; cin.getline(buffer,sizeof(buffer)); package[i].length = atoi(buffer); cout << endl << "Width in inches: "; cin.getline(buffer,sizeof(buffer)); package[i].width = atoi(buffer); cout << endl << "Depth in inches: "; cin.getline(buffer,sizeof(buffer)); package[i].depth = atoi(buffer); cout << endl << "Weight in ounces: "; cin.getline(buffer,sizeof(buffer)); package[i].weight = atoi(buffer); volume = ((package[i].length)*(package[i].width)*(package[i].depth)); if(((package[i].weight)/volume) > 1) { package[i].rate = ((.37) + (.37*.33)); } else { package[i].rate = .37; } cout << endl << endl; } return (package); }//end of function readPkgInfo void calculatePrice(Package* package, int no_of_packages) { int i = 0; for(i = 0; i < no_of_packages; i++) { package[i].shipping_price = ((package[i].weight)*(package[i].rate)); } return; }//end of function calculatePrice void displayInfo(Package* package, int no_of_packages) { int i = 0; cout << endl << endl << endl; cout << "The postal information for your packages is:" << endl; for(i = 0; i < no_of_packages; i++) { cout << "Package " << i+1 << ": " << endl; cout << "\tShipping Address: " << endl; cout << "\t\t" << package[i].address.name << endl; cout << "\t\t" << package[i].address.address << endl; cout << "\t\t" << package[i].address.city_state_zip << endl << endl; cout << "\tPackage Size: " << endl; cout << "\t\tLength: " << package[i].length << endl; cout << "\t\tWidth: " << package[i].width << endl; cout << "\t\tDepth: " << package[i].depth << endl; cout << "\t\tWeight: " << package[i].weight << endl << endl; cout << "\tShipping Rate: $" << package[i].rate << endl; cout << "\tShipping Price: $" << package[i].shipping_price << endl << endl; } return; }//end of function displayInfo