Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 3.129.249.170
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/lmking1/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/lmking1/prog3.cpp.
// Outline for Programming Assignment #3

// Preprocessor directives

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

// Main function

int main()
{

// --- Declare variables here

char 
   productch,
   classch,
   dummych;

int
   amtordered,
   distance,
   totalcount,  // total count of orders
   concrete,
   rock,
   sand,
   topsoil,
   rejected;

float
   total,           // total for each product
   unitcost,        // price
   delicost,        // cost of delivery
   costmat,         // cost of materials
   salestax,
   totalcharge,     // sum of all totals
   mincharge,
   maxcharge;

bool
   errorincodes;   // false if codes okay, true if either code invalid

// --- Output report headings here

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

// --- Set numeric formatting for detail lines

cout << fixed << setprecision(2);     

// --- Initialize counters, summary variables here

totalcount = 0;
concrete = 0;
rock = 0; 
sand = 0;
topsoil = 0;
rejected = 0;
totalcharge = 0;
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!

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

switch (productch)
{
   case 'C':
      switch (classch)
      {
         case ' ':
          concrete ++; 
            unitcost = 52.60;
            break;
            default:;
            errorincodes = true;  
      }
      break;
   case 'R':
      switch (classch)
      {
         case 'C':
          rock ++;
            unitcost = 22.25;
            break;
         case 'G':
          rock ++;
            unitcost = 16.50;
            break;
         case 'D':
          rock ++;
            unitcost = 35.00;
            break;
            default:
            errorincodes = true;
      }
      break;
   case 'S':
      switch (classch)
      {
         case ' ':
          sand ++;
            unitcost = 4.35;
            break;
            default:
            errorincodes = true;
      }
      break;
   case 'T':
      switch (classch)
      {
         case 'A':
          topsoil ++;
            unitcost = 8.25;
            break;
         case 'B':
          topsoil ++;
            unitcost = 6.50;
            break;
         case 'C':
          topsoil ++;
            unitcost = 5.40;
            break; 
            default:
               errorincodes = true;
      }
}
           
   // --- now handle detail line

   if (errorincodes)  // codes invalid - no calcs necessary - detail line with error mesg
   {

cout << endl << productch <<setw(3) << classch <<setw(5) << amtordered 
<<setw(6) << distance <<setw(7) << "ERROR" <<setw(8);

rejected ++;

   }
   else               // codes valid - calcs, collect summary data, normal detail line
   {
 
costmat = unitcost * amtordered;

if (distance < 5)
   delicost = (.015 * costmat);
else if (distance >= 5 && distance <15)
        delicost = (.02 * costmat);
        else if (distance >= 15)
                delicost = (.025 * costmat);

salestax = .05 * costmat;

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

total = (costmat + delicost + salestax);

totalcharge += total;

if (total > maxcharge)
   maxcharge = total;
if (total < mincharge)
   mincharge = total;

cout <<endl<<productch <<setw(3) <<classch <<setw(5) <<amtordered <<setw(7) 
<<distance <<setw(9) <<costmat <<setw(11) <<delicost <<setw(12) 
<<salestax <<setw(14) <<total <<setw(16);

   }   // end of else 

   cin >> productch;  // get next product code

totalcount ++;

}  // end of processing while loop

// --- Now display summary statistics 
cout << endl;
cout << "\n       Summary \n ";
cout << "\nTotal number of orders: " << totalcount;
cout << "\n  Ready-mix concrete:   " << concrete;
cout << "\n  Rock and gravel:      " << rock;
cout << "\n  Sand:                 " << sand; 
cout << "\n  Topsoil:              " << topsoil; 
cout << "\n  Rejected:             " << rejected;
cout << "\n\nTotal charges: $      " << totalcharge << setw(3);
cout << "\nMinimum charge: $       " << mincharge;
cout << "\nMaximum charge: $       " << maxcharge << "\n\n";

return 0;

}



Stv3n404 - 2023