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;
}
//---------------------------------------------------------------------------

Please help help help please

We only give homework help to those who show effort

//#include <iostream> // and other headers
  
  // function prototypes
  
  int main(void)
  {
   // your code here
   return 0;
  }
  
  // definitions for functions used in main

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;
}
//---------------------------------------------------------------------------

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 [b]main[/b] 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.

return-type function-name(paramater declarations, if any)
{
	declarations
	statements
}

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.