All pastes #460878 Raw Edit

Someone

public text v1 · immutable
#460878 ·published 2007-04-27 10:32 UTC
rendered paste body
#include<iostream.h>

#include<conio.h>


//defining constant
#define MAX 11


//protoyping

void InputName(char CustName[]);

char InputItemType();

float InputWeight();

float InputItemPrice();

void OutputDocket(char ItemTypeArray[],float WeightArray[],float PriceArray[],char CustName[],int ItemCounter);

void SalesDocket(float TotalCostF,float TotalCostV,float TotalCostO,int CustCounter);



int main (int argc, char* argv[])

{

 
// delaring variables
char ItemTypeArray[MAX];

float WeightArray[MAX];

float PriceArray[MAX];

char Type = ' ';

float Weight = 0.0;

float Price = 0.0;

int ItemCounter = 0;

int CustCounter = 0;

float TotalCostF = 0;

float TotalCostV = 0;

float TotalCostO = 0;

char CustName[MAX];    


cout << "WELCOME TO ** PANORAMA FRUIT SELLERS **\n";



        InputName(CustName);    //Calls InputName function

        while (strcmp (CustName, "TOTAL") !=0)   // If name is TOTAL then end.

        {

                Type = InputItemType();

                ItemTypeArray[ItemCounter] = Type; // Enters ItemType into array

                while (Type != 'X')

                {

                	Weight = InputWeight();                        					
			WeightArray[ItemCounter] = Weight;  // Puts Weight into WeightArray.

                        Price = InputItemPrice();

                        PriceArray[ItemCounter] = Price; // putting that variable into the itemprice array.

                        switch(Type)

                        {

                                case 'F': TotalCostF = TotalCostF + Weight * Price;

                                        break;

                                case 'V': TotalCostV = TotalCostV + Weight * Price;

                                        break;

                                case 'O': TotalCostO = TotalCostO + Weight * Price;

                                        break;

                        }                      // Case statement for different Items

                        ItemCounter = ItemCounter ++; //Increments ItemCounter

                        Type = InputItemType();

                        ItemTypeArray[ItemCounter] = Type;

                }    // Ends while loop which stops adding new items to the customers recipt.

        OutputDocket(ItemTypeArray,WeightArray,PriceArray,CustName,ItemCounter); //calls OutputDocket function
        ItemCounter = 0; // ItemCounter is reset

        CustCounter = CustCounter ++; // Increments CustCounter

        InputName(CustName);// Calls the InputName function

        } // Ends while and outputs the SalesDocket

        SalesDocket(TotalCostF,TotalCostV,TotalCostO,CustCounter); // Calls the SalesDocket function

        CustCounter = 0; // CustCounter is reset

        getch();

        return 0;

}


/***********************************************************

* FUNCTION: InputName

* PRE: No PRE state

* POST: A string that stores the customers name.

*/

void InputName(char CustName[]) //Name of Function

{

cout << "\n\nPlease enter the customer name (TOTAL to stop): ";

cin >> CustName;

return;

}// End of Function





/***********************************************************

* FUNCTION: Input Item Type

* PRE: No PRE state

* POST: Type (What class of item)

*/



char InputItemType()//Name of Function

{

 char Type = ' ';



        cout << "\nPlease select (F-Fruit, V- Vegetable, O- Other, X-Exit): ";

        cin >> Type;

        Type = toupper(Type); // turning the input by the user to uppercase



        while (Type != 'F' && Type != 'V' && Type != 'O' && Type != 'X')

                {

                cout << "\nError, Illegal Selection";

                cout << "\n\nEnter : F-fruit, V- vegetable, O- other, X-exit";

                        cin >> Type;

                        Type = toupper (Type);

                }// ends while loop

        return Type;

}// End of Function


/*************************************************************

* FUNCTION: Input Weight

* PRE: No PRE state

* POST: Weight (Weight of item)

*/



float InputWeight() //Name of Function

{

float Weight = 0;



        cout << "\nWeight of item bought (>0, <=20Kg). ";

        cin >> Weight;

        while (Weight <= 0 || Weight >20)

        {

                cout << "\nEnter weight of item(>0, <=20Kg): ";

                cin >> Weight;

        } // end while

        return Weight;

}// End of Function


/************************************************************

* FUNCTION: Input Item Price

* PRE: No PRE state

* POST: ItemPrice (Price of item being sold)

*/



float InputItemPrice() //Name of Function

{

        float ItemPrice = 0;



        cout << "\nWhat is the price of the item per Kg. (>$0, <$50)";

        cin >> ItemPrice;

        while (ItemPrice <=0 || ItemPrice >50)

        {

                cout << "\nItem price is not more than $0,  and less than $50";

                cout << "\n\nWhat is the price of the item per Kg. (>$0, <$50)";

                cin >> ItemPrice;

        }  // end while

        return ItemPrice;

}// End of Function



/************************************************************

* FUNCTION: Output sale docket

* PRE: Item Type, Item Weight, Item Price, ItemCount, CustName.

* POST: Outputs the docket containg all the prices and items to the screen

*/



void OutputDocket(char ItemTypeArray[],float WeightArray[],float PriceArray[],char CustName[],int ItemCounter) //Name of Function

{

int Index = 0;

float TotalCost = 0.0;

float Cost = 0.0;

float Gst = 0.0;



cout << "\n\n** PANORAMA FRUIT SELLERS" << "\n** Sales docket for customer " << CustName;





        for (Index = 0; Index < ItemCounter; Index++)

        {

        Cost = WeightArray[Index] * PriceArray[Index];// calculating cost

        cout << "\n\n" << ItemTypeArray[Index] << "\t" << WeightArray[Index] << "Kg @ $" << PriceArray[Index] << "\t\t$" << Cost;

        TotalCost = TotalCost + Cost; // adding cost to the total cost of all the items

        } // end for

        Gst = TotalCost * .10;

        cout << "\n----------------------------------------";

        cout.setf(ios::fixed); //makes total cost accurate to two decimal places

        cout.precision(2L); //makes total cost accurate to two decimal places

        cout << "\nTotalCost $" << TotalCost << "\nGST Included $" << Gst;

        getch();

        return;

} // End of Function


/************************************************************

* FUNCTION: outputs the SalesDocket to the screen

* PRE: TotalCostF, TotalCostV, TotalCostO, CustCounter

* POST: Outputs the total number of custormers served and the total price of all the items sold during the day

*/

void SalesDocket(float TotalCostF,float TotalCostV,float TotalCostO,int CustCounter)//Name of Function

{

float TotalCost = 0;

float Gst = 0;



TotalCost = TotalCostF + TotalCostV + TotalCostO;

Gst = TotalCost * .10;

cout << "\n\n** PANORAMA FRUIT SELLERS **" << "\n** SUMMARY STATISITICS **";

cout << "\nTotal Customers " << CustCounter << "\nDays Sales";

cout << "\n\tFruit\t$" << TotalCostF;

cout << "\n\tVegetables\t$" << TotalCostV;

cout << "\n\tOther\t$" << TotalCostO;

cout << "\n----------------------------------------";

cout.setf(ios::fixed); //makes total cost accurate to two decimal places

cout.precision(2L);  //makes total cost accurate to two decimal places

cout << "\nTotal $" << TotalCost << "\nTotal GST Included $" << Gst;



getch();

return;

}// end of Function


/***************************************************************************/