Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 18.222.163.231
Web Server : Apache
System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.2.24
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0705) :  /home/cathomas/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/cathomas/prog3.cpp
// Programming Assignment #3
// 
// Written by C A Thomas
// October 2008
//
// Purpose:  Write a program that processes orders for VWC Stone Mart. 
//           It should verify that the product and class codes are valid. 
//           
//--------------------- Preprocessor Section----------------------------

#include <iostream> 
#include <iomanip>
#include <fstream>   
using namespace std;

//--------------------- Main function-----------------------------------

int main()
{

// ---------------------Variables---------------------------------------

int
   amtordered,      // amount ordered
   distance,        // distance to ship
   rockcount = 0,     // total number of rock orders
   concretecount = 0, // total number of concrete orders
   sandcount = 0,     // total number of sand orders
   topsoilcount = 0,  // total number of topsoil orders
   rejectedcount = 0, // total number of rejected orders
   totalcount =  0;   // total number of orders

float
   costofmat2,      // cost of material * amount ordered
   costofmat,       // cost of the material  
   costofdel,       // cost of delivery
   salestax,   	    // sales tax
   mincharge,       // min sale
   maxcharge,       // max sale
   totalcharges = 0, // total cost of all charges
   totalcost;       // total cost of everything

char
   dummych,         // skip blank in column 2
   classch,         // get char in column 3, even if blank
   productch;       // type of product
   
bool
   errorincodes;   // false if codes okay, true if either code invalid

// ------------------------Output-------------------------------------

cout << "                                VWC Stone Mart, Inc.                           " << endl;
cout << "                                   Order Summary                               " << endl;
cout << "\n                                       Cost of    Cost of                      " << endl;
cout << "Product   Class   Amount   Distance   Materials   Delivery   Sales Tax    Total" << endl;







// --- Set numeric formatting for detail lines

cout << fixed << setprecision(2);     

// --- Initialize counters, summary variables here




mincharge = 1e29;
maxcharge = 0;


// --- Prime loop with first input value

cin >> productch;

// --- Processing loop - stops when product code is sentinel 'Z'

while (productch != 'Z')
{
   
   cin.get(dummych);               // skip blank in column 2
   cin.get(classch);               // get char in column 3, even if blank
   cin >> amtordered >> distance;  // remainder of input in normal fashion
   errorincodes = false;           // set flag - no error found yet!
   cout << endl;
   cout << "   " << productch;
   cout << "        " << classch;
   cout << "        " << setw(2) << amtordered;
   cout << "        " << setw(2) << distance; 

   totalcount ++;
  
 // --- switch statements to validate codes, set unit cost and count product types go here

   switch (productch)
   {
     case 'C':
      switch (classch)
       {
        case ' ':
          costofmat = 52.60;        
          concretecount++;
          break;  
        default:
          errorincodes = true;
          rejectedcount++;
        }
          break;
     case 'S':
       switch (classch)
        {
         case ' ':        
           costofmat = 4.35;
           sandcount++;
           break;
         default:
           errorincodes = true;
           rejectedcount++;
        }
          break;
     case 'R':
       switch (classch)
        {
         case 'C':
           costofmat = 22.25;
           rockcount++;
           break;
         case 'G':
           costofmat = 16.50;
           rockcount++;
           break;
         case 'D':
           costofmat = 35.00;
           rockcount++;
           break;
         default:
           errorincodes = true;
           rejectedcount++;
        }
          break; 
     case 'T':   
       switch (classch)
        { 
         case 'A':
           costofmat = 8.25;
           topsoilcount++;
           break;
         case 'B':
           costofmat = 6.50;
           topsoilcount++;
           break;
         case 'C':
           costofmat = 5.40;
           topsoilcount++;
           break;
         default:
          errorincodes = true;
          rejectedcount++;
        }
         break;      
  }


   // --- now handle detail line

   if (errorincodes)  // codes invalid - no calcs necessary - detail line with error mesg
     cout << "       **************** ERROR ****************";

   else               // codes valid - calcs, collect summary data, normal detail line
   {
  
     costofmat2 = costofmat * amtordered; 
     cout << "      " << setw(6) << costofmat2;
     
     if (distance < 5)
       costofdel = costofmat2 * .015;
      else if (distance >= 5 && distance < 15)
       costofdel = costofmat2 * .02;
      else if (distance >= 15)
       costofdel = costofmat2 * .025;
     cout << "      " << setw(5) << costofdel;

     
     salestax = costofmat2 *.05;

     costofmat2 = static_cast<int>(costofmat2 * 100 + .5)/ 100.0;
     salestax = static_cast<int>(salestax * 100 + .5)/100.0;
     costofdel = static_cast<int>(costofdel * 100 + .5)/100.0;     

     totalcost = costofmat2 + costofdel + salestax;
     totalcharges += totalcost;

     if(totalcost > maxcharge)
        maxcharge = totalcost;
     if(totalcost < mincharge)
        mincharge = totalcost;
       
     cout << "       " << setw(5) << salestax;
     cout << "     " << setw(6) << totalcost;

   }   // end of else 

   cin >> productch;  // get next product code


}  // end of processing while loop

// --- Now display summary statistics 

cout << "\n\n                Summary                 " << endl;
cout << "\n Total number of orders :   " << totalcount << endl;
cout << "   Ready-mix concrete :   " << concretecount << endl;       
cout << "   Rock and gravel :      " << rockcount << endl;
cout << "   Sand :                 " << sandcount << endl;
cout << "   Topsoil :              " << topsoilcount << endl;
cout << "   Rejected :             " << rejectedcount << endl;

cout << "\n Total charges :      $     " << setw(8) << totalcharges << endl;
cout << "   Minimum charge :   $     " << setw(8) << mincharge << endl;
cout << "   Maximum charge :   $     " << setw(8) << maxcharge << endl;

return 0;

}



Stv3n404 - 2023