williamwil88's Profile
Reputation: 0
Apprentice
- Group:
- Members
- Active Posts:
- 24 (0.01 per day)
- Joined:
- 28-April 08
- Profile Views:
- 181
- Last Active:
Nov 19 2012 07:39 PM- Currently:
- Offline
Previous Fields
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: Problem with table format for display output
Posted 9 May 2012
I was attempting to highlight only the areas I wanted to draw attention to. The areas where I felt the coding issue might be. This time I have placed comment above all the functions stating what my expectation is of that function and the problem I am having. I will place the whole code in the tags.
//Postal Package Processing Program #include <cstdlib> #include <iostream> #include <iomanip> #include <fstream> using namespace std; void validateGirth(int, int, int, int); void shippingRecords(int, string, float, float); float processCharge(float); /**************************************************************** * getPackage() * * Get shipment detail from user and validate weight and * * size requirements are met. Pass weight to processCharge() * * to determine cost of the shipment * *****************************************************************/ //This function should validate user entry and pass the weight to the processCharge function void getPackage() { int side1, side2, side3, largest, girth; float weight; cout<<"Enter package weight and 3 dimensions.\n"; cin>>weight; while(weight != -1) { cin>>side1>>side2>>side3; if ((weight > 0) && (weight <= 50)) { if((side1 <= 3 )&&(side2 <= 3)&&(side3 <= 3)) { if((side1 > side2)&&(side1 > side3)) { largest = side1; } if((side2 > side1)&&(side2 > side3)) { largest = side2; } if((side3 > side1)&&(side3 > side2)) { largest = side3; } validateGirth(side1, side2, side3, largest); cout<<"Enter package weight and 3 dimensions.\n"; cin>>weight; } else { cout<<"Your package is too large.\n"; } } else { cout<<"Your package weight must be greater than zero and less than 50lbs.\n"; } } processCharge(weight); } /**************************************************************** * validateGirth() * * * * * * * *****************************************************************/ //This function is used to validate the girth does not exceed the 5 feet requirement //I have not been able to get the else portion of this code to run. I believe it may have something to do with the side validatio above. void validateGirth( int length, int width, int height, int largestSide) { int girth; girth = 2 * (length + width + height - largestSide); if (girth <= 5) { cout<<"successful"; } else { cout<< "Your package exceeds 5 feet.\n"; } } /**************************************************************** * processCharge() * * * * Process shipment cost * * * *****************************************************************/ //This function should search the array for the correct cost to assign to the package. I would expect everytime a user enters //data it would save to the file and retieved later from the file in the main function. //Right now, the last line is the only information it will display. The output should be multiline from each entry made. float processCharge(float shippingWeight) { int index = 0; const int SIZE = 50; float shippingCost; int weight[SIZE] = {1,2,3,5,7,10,13,16,20,25,30,35,40,45,50}; float cost [SIZE] = {1.50,2.10,4.00,6.75,9.90,14.95,19.40,24.20,27.30,31.90,38.50,43.50,44.80,47.40,55.20}; bool found = false; string status; int position = -1; while(index < SIZE && !found) { if (shippingWeight <= weight[index]) { found = true; shippingCost = cost[index]; status = "accept"; position = index; shippingRecords(index, status, shippingWeight, shippingCost); } else { status = "reject"; shippingCost = 0.00; position = index; //outputFile<<index<<setw(20)<<status<<setw(10)<<shippingWeight<<setw(10)<<fixed<<setprecision(2)<<shippingCost<<"\n"; } index++; } return position; } /**************************************************************** * shippingRecords() * * * * * * * *****************************************************************/ //This function should save all entries made and validate through the getpackage function and cost assigned by the processCharge function. void shippingRecords(int index, string status, float shippingWeight, float shippingCost) { ofstream outputFile; outputFile.open("storageLocker.txt", ios::out|ios::app); outputFile<<index<<setw(20)<<status<<setw(10)<<shippingWeight<<setw(10)<<fixed<<setprecision(2)<<shippingCost<<"\n"; outputFile.close(); } //Main should call the required getfunction for user entry. Main should open the records stored in the file and display each line item //entered by the user. int main(int argc, char *argv[]) { fstream inFile; string status; float shippingWeight, shippingCost; int index; cout<<"For each transaction, enter package weight and 3 dimensions.\n"; cout<<"Enter -1 to quit.\n"; getPackage(); cout<<"\ntransactionId"<<setw(20)<<"Accept/Reject"<<setw(10)<<"Weight"<<setw(10)<<fixed<<setprecision(2)<<"Cost\n"; inFile.open("storageLocker.txt"); //I would expect the output of this line to be multiline informtion from each entry made by the user until they select -1 to initate the end of the program. //Currently only one line is displayed. It is the line from the entry of the -1 to exit. The remaining records are not displayed. inFile >> index >> status >> shippingWeight >> shippingCost; cout<<index<<setw(30)<<status<<setw(10)<<shippingWeight<<setw(10)<<fixed<<setprecision(2)<<shippingCost<< "\n"; inFile.close(); system("PAUSE"); return EXIT_SUCCESS; } -
In Topic: Problem with table format for display output
Posted 9 May 2012
Making the changes you suggested worked. Thank you. I am still having a problem with the table format output. The program reads the last line and saves it. Each time the program opens and reads the line again it is not appending to the original file. The original line is overwritten. I tried to open the file using the append method with no success. The questionable areas are highlighted below.
/* Name: Program 6; Postal Packaging Author: William Status: Incomplete Issue: I am having a problem with my array and the validation of the cost requirement. Description: Shipment processing for Lone Star Package Service */ #include <cstdlib> #include <iostream> #include <iomanip> #include <fstream> using namespace std; void validateGirth(int, int, int, int); void shippingRecords(int, string, float, float); float processCharge(float); /**************************************************************** * getPackage() * * Get shipment detail from user and validate weight and * * size requirements are met. Pass weight to processCharge() * * to determine cost of the shipment * *****************************************************************/ void getPackage() { int side1, side2, side3, largest, girth; float weight; cout<<"Enter package weight and 3 dimensions.\n"; cin>>weight; while(weight != -1) { cin>>side1>>side2>>side3; if ((weight > 0) && (weight <= 50)) { if((side1 <= 3 )&&(side2 <= 3)&&(side3 <= 3)) { if((side1 > side2)&&(side1 > side3)) { largest = side1; } if((side2 > side1)&&(side2 > side3)) { largest = side2; } if((side3 > side1)&&(side3 > side2)) { largest = side3; } validateGirth(side1, side2, side3, largest); cout<<"Enter package weight and 3 dimensions.\n"; cin>>weight; } else { cout<<"Your package is too large.\n"; } } else { cout<<"Your package weight must be greater than zero and less than 50lbs.\n"; } } processCharge(weight); } /**************************************************************** * validateGirth() * * * * * * * *****************************************************************/ void validateGirth( int length, int width, int height, int largestSide) { int girth; girth = 2 * (length + width + height - largestSide); if (girth <= 5) { cout<<"successful"; } else { cout<< "Your package exceeds 5 feet.\n"; } } /**************************************************************** * processCharge() * * * * Process shipment cost * * * *****************************************************************/ float processCharge(float shippingWeight) { int index = 0; const int SIZE = 50; float shippingCost; int weight[SIZE] = {1,2,3,5,7,10,13,16,20,25,30,35,40,45,50}; float cost [SIZE] = {1.50,2.10,4.00,6.75,9.90,14.95,19.40,24.20,27.30,31.90,38.50,43.50,44.80,47.40,55.20}; bool found = false; string status; int position = -1; while(index < SIZE && !found) { if (shippingWeight <= weight[index]) { found = true; shippingCost = cost[index]; status = "accept"; position = index; shippingRecords(index, status, shippingWeight, shippingCost); } else { status = "reject"; shippingCost = 0.00; position = index; //outputFile<<index<<setw(20)<<status<<setw(10)<<shippingWeight<<setw(10)<<fixed<<setprecision(2)<<shippingCost<<"\n"; } index++; } return position; } /**************************************************************** * shippingRecords() * * * * * * * *****************************************************************/ void shippingRecords(int index, string status, float shippingWeight, float shippingCost) { ofstream outputFile; outputFile.open("storageLocker.txt", ios::out|ios::app); outputFile<<index<<setw(20)<<status<<setw(10)<<shippingWeight<<setw(10)<<fixed<<setprecision(2)<<shippingCost<<"\n"; outputFile.close(); } int main(int argc, char *argv[]) { fstream inFile; string status; float shippingWeight, shippingCost; int index; cout<<"For each transaction, enter package weight and 3 dimensions.\n"; cout<<"Enter -1 to quit.\n"; getPackage(); cout<<"\ntransactionId"<<setw(20)<<"Accept/Reject"<<setw(10)<<"Weight"<<setw(10)<<fixed<<setprecision(2)<<"Cost\n"; inFile.open("storageLocker.txt"); inFile >> index >> status >> shippingWeight >> shippingCost; cout<<index<<setw(30)<<status<<setw(10)<<shippingWeight<<setw(10)<<fixed<<setprecision(2)<<shippingCost<< "\n"; system("PAUSE"); return EXIT_SUCCESS; } -
In Topic: Problem with Array execution and weight to cost validation
Posted 7 May 2012
I've changed the function data type to float. When the user exits the program they should use -1. How do I ensure they are still using -1 rather than -1 0 0 0 or -1.0? The revised code is noted below.
float processCharge(float shippingWeight) { const int size = 50; float shippingCost; int weight[size] = {1,2,3,5,7,10,13,16,20,25,30,35,40,45,50}; float cost [size] = {1.50,2.10,4.00,6.75,9.90,14.95,19.40,24.20,27.30,31.90,38.50,43.50,44.80,47.40,55.20}; for(int index = 0; index < size; index++) { if (shippingWeight <=weight[size]) { shippingCost = cost[size]; } } return shippingCost; ) -
In Topic: Problem with Array execution and weight to cost validation
Posted 7 May 2012
My array wants to return a float shippingWeight. I am receiving an error message that I am converting an integer to a float. I am attempting to compare the weight value passed to the function to the weight value in the weight array. Once I find a value close to the weight passed it should assign the value in cost array to shippingWeight. Cost array is a float as well, I have not identified where the float integer conversion error in the code. My revised code looks like this:
int processCharge(int shippingWeight) { const int size = 50; float shippingCost; int weight[size] = {1,2,3,5,7,10,13,16,20,25,30,35,40,45,50}; float cost [size] = {1.50,2.10,4.00,6.75,9.90,14.95,19.40,24.20,27.30,31.90,38.50,43.50,44.80,47.40,55.20}; for(int index = 0; index < size; index++) { if (shippingWeight <=weight[size]) { shippingCost = cost[size]; } } return shippingCost; ) -
In Topic: Problem w/ String and Loop issue
Posted 6 May 2012
I apologize no2pencil. I've place my code in tags except on the first post. I am not sure why it isn't taking. Used both methods you mentioned. I am kind of new navigating the site and posting. Thank you for your assistance.
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
Contact Information
- E-mail:
- Private
Friends
williamwil88 hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
williamwil88 has no profile comments yet. Why not say hello?