Need direction on how start this program

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2004
Posts: 4
Reputation: beezybeem is an unknown quantity at this point 
Solved Threads: 0
beezybeem beezybeem is offline Offline
Newbie Poster

Need direction on how start this program

 
1
  #1
Sep 13th, 2004
1st time trying to do C++. I need direction of how to write this program. Thank you.


Specification:
Follow the coding style guide lines of codingStyle.doc

A small postal system ships packages within your state. Acceptance of parcels is subject to the following constraints:
1. Parcels weight <= 50 pounds
2. The largest-dimension (length or width or height) <= 36 inches
3. The maxSize = (largest-dimension + girth) <= 72 inches. Girth is calculated as follows:
girth = 2 * ( length + width + height - largest-dimension)


If the parcel is accepted then the shipping charge is found by searching a lookup table consisting of 2 parallel arrays One array containing a weight values and a second array containing price values. If the weight falls between two weight values use the next higher weight in the table.

Build the lookup table by reading the values from the file parcel.rte into 2 parallel arrays. There will be an array of type int for the weight and an array of type float for the associated shipping cost.


Your program should process the transaction file, parcel.box, containing one record for each box mailed during the week. Each record contains a transaction number, followed by the weight and then 3 dimensions. The dimensions can be in any order. Your program should read a record for a parcel. Check for all the constraints. If it passes the constraint test then find the shipping cost from the lookup table. Use the function wt_index( ) to find the index of the matching parcel weight in the weight array. Then use this index to extract the shipping price from the cost array.

For each parcel record processed print a report line to the console. The line will contain the data from the transaction. If the parcel is accepted the last field will be the shipping cost. If rejected the last field will be the string "rejected"

Use this report format.

Transaction Weight Length Width Height Price
100 1 20 5 5 1.20
101 34 19 24 20 reject

You will need to use stream manipulators to make your report appear neat and readable.

At the end print a summary of the total number of parcels processed and the total which were rejected.

I have provided a the executable parcel.exe to use as an example of how your program should run.

Input: the input data are in two files:
'parcel.rte' lookup table
'parcel.box' parcel transactions



Building the lookup table:
The file 'parcel.rte' contains 25 pairs of values arranged as weight and shipping_cost. Read these values into 2 parallel arrays. The weight_array is type int and the shipping cost is type float. Your program will use this lookup table to determine the shipping cost of a parcel.

Transaction file:
I have provided some test data in the file 'parcel.box'. Each line is a transaction record. You must treat the file as “black box� in that you do not know how many records are in the file.
Use a while(there are still records) loop to drive the process until EOF.
DO NOT STORE THE TRANSACTION FILE IN PARALLEL ARRAYS!! ('parcel.box')

I have provided the following function stubs for you to implement.
Your program logic should use these functions. You may add additional functions as needed by your design..

Required functions:
DO NOT CHANGE THE CALLING INTERFACE OF THESE FUNCTIONS

//---------------------------------------------------------------------------
int
girth(int length, int width, int height)
{
girth == 2 * ( length + width + height - largest_dimension)
note:girth() should use the function largest() to find the largest_dimension

return the girth
}
//---------------------------------------------------------------------------
// use this helper function to calculate girth
int
largest(int length, int width, int height)
{
return the largest of 3 values
}
//---------------------------------------------------------------------------
// use this function to help look up the shipping cost in the lookup table
// it is a standard linear search. Since the values are sorted you may
// also use binary search.

int
wt_index(int weightArray[], int arraySize, int boxWeight)
{
if the box_wt is an odd number increment to the next higner even weight
find box_wt in the array lookupWeight[]

return its index;
}
//---------------------------------------------------------------------------
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 4
Reputation: beezybeem is an unknown quantity at this point 
Solved Threads: 0
beezybeem beezybeem is offline Offline
Newbie Poster

Please help help help please

 
0
  #2
Sep 14th, 2004
Please help help help please
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,377
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 242
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Need direction on how start this program

 
0
  #3
Sep 14th, 2004
We only give homework help to those who show effort


  1. //#include <iostream> // and other headers
  2.  
  3. // function prototypes
  4.  
  5. int main(void)
  6. {
  7. // your code here
  8. return 0;
  9. }
  10.  
  11. // definitions for functions used in main
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 4
Reputation: beezybeem is an unknown quantity at this point 
Solved Threads: 0
beezybeem beezybeem is offline Offline
Newbie Poster

Re: Need direction on how start this program

 
0
  #4
Sep 17th, 2004
Thanks for the reply. I have come up with this.... where am I going wrong and what do you think am missing out.

/*
ReadText.cpp
==============================================================================
=NAME:
=ORIGINAL CODE DATE:
=HISTORY OF MAINTENANCE:
=
=
=
==============================================================================
*/
// INCLUDES
#include <conio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cstdlib>
//#include "windows.h"

using namespace std;

// MACROS
#define skip1 cout << endl
#define skip2 cout << endl << endl
#define skip3 cout << endl << endl << endl

// SYMBOLIC CONSTANTS

// struct declarations and typedef declarations

// PROTOTYPES non library functions used by functions in this file (file scope)

// GLOBAL EXTERNALS (HAVE A GOOD RATIONALE FOR USING GLOBAL EXTERNAL VARIABLE)

// uncomment the following statement to invoke a file version of cout
// ofstream fout("coutfile.txt", ios::out);
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int
main()
{
// PROTOTYPES non library functions called by this function (block scope)

void
displayInt(int weightArray[], int arraySize, int boxWeight) ;

int
lsearch (int weightArray[], int arraySize, int boxWeight, int girth);

int
lsearch (int weightArray[], int arraySize, int boxWeight, int girth);



// LOCAL DECLARATIONS

int temp;
int table[0] = {0} ;
int kk;
int girth;


cout << "\nBegin main()\n\n";

//---------------------------------------------------------------------------
int
girth(int length, int width, int height)
{
girth == 2 * ( length + width + height - largest_dimension)
note:girth() should use the function largest() to find the largest_dimension

return the girth
}
//---------------------------------------------------------------------------
// use this helper function to calculate girth
int
largest(int length, int width, int height)
{
return the largest of 3 values
}
//---------------------------------------------------------------------------
// use this function to help look up the shipping cost in the lookup table
// it is a standard linear search. Since the values are sorted you may
// also use binary search.

int
wt_index(int weightArray[], int arraySize, int boxWeight)
{
if the box_wt is an odd number increment to the next higner even weight
find box_wt in the array lookupWeight[]

return its index;
}
//---------------------------------------------------------------------------
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 185
Reputation: Stack Overflow is an unknown quantity at this point 
Solved Threads: 4
Stack Overflow's Avatar
Stack Overflow Stack Overflow is offline Offline
C Programmer

Re: Need direction on how start this program

 
0
  #5
Sep 17th, 2004
Mostly, the C syntax is beneficial to understand before writing programs.

A C program, whatever its size, consists of functions and variables. A function contains statements that specify the computing operations done, and variables store values used during the computation.

This is all good and great you may say. C functions are like the subroutines and function of Fortran or the procedures and functions of Pascal. Normally you are at liberty to give functions whatever names you like, but "main" is special — your program begins executing at the beginning of main. This means that every program must have a main somewhere.

main() will usually call other functionsto help perform its job, some that you wrote, and others from libraries that are provided to you.

Here is a simple program written in C:

#include <stdio.h>		// include information about standard library

int main() 			// define a function named main that receives no argument values
{				// statements of main are enclosed in braces
	printf("Hello world\n");// main calls library function printf to print this sequence of characgers: \n reperesents the new line character
}

In C, a function is equivalent to a subroutine or function in Fortran, or a procedure or function in Pascal. A function provides a convenient way to encapsulate some computation, which can then be used without worrying about its implementation.

  1. return-type function-name(paramater declarations, if any)
  2. {
  3. declarations
  4. statements
  5. }

That's also good, but remember functions much be called outside of main(), not inside:

#include <stdio.h>

// declaration
int power(int, int);

// main
int main() {
	int i;

	for (i = 0; i < 10; ++i)
		printf("%d %d %d\n", i, power(2,i), power(-3,i));
	return 0;
}

// actual function
int power(int base, int n) {
	int i, p;

	p = 1;
	for (i = 1; i <= n; ++i)
		p = p * base;
	return p;
}

I hope this does help better compile your code. Another thing I saw was you had a local declaration of:

int table[0] = {0};

An array cannot be initialzed with 0 indices. It may result in an error, so try to use non-zero integers when setting the index of an array.


Hope this helps,
- Stack Overflow
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [code][/code] tags. Your question may have been asked before, try the search facility.

IRC
Channel: irc.daniweb.com
Room: #c, #shell
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC