Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.54 KB | None | 0 0
  1. //Course:        COSC 1435
  2. //Lab #:         7
  3. //Date assigned: Oct 6 2010
  4. //Date due:      Oct  12, 2010
  5. //
  6. //Purpose: The purpose of this assignment is to create a customer invoice
  7. //
  8. //Input:   Keyboard input for the
  9. //           customer’s first and last names
  10. //           length, width and height of a “flat-rate” box
  11. //
  12. //Output:  Screen output for the
  13. //           customer’s full name, last name first
  14. //           dimensions of the box
  15. //           base area and the volume and surface area of the box
  16. //           set rate according to size
  17. //           price of the box (rate * surface area)
  18. //
  19. //Program outline:
  20. //         Prompt the user and enter the customer’s first name and last name.
  21. //         Prompt the user and enter the length, width and height of the box.
  22. //         Calculate the area of the base of the box.
  23. //         Calculate the volume of the box.
  24. //         Calculate surface area.
  25. //         chose rate based on size
  26. //         calculate price by rate * surfacearea
  27.  
  28.  
  29.  
  30. /* this was compiled at home on a windows based system, so i had to slightly
  31. change somethings, i included the source code and my compiled executable. */
  32.  
  33. #include <iostream>
  34. #include <iomanip>    // reqd for setw
  35. #include <string>    // Required for the string class.
  36. using namespace std;
  37.  
  38. int main()
  39. {
  40.  
  41. float length, width, height, area, volume, price, area1, area2, area3, surfacearea, rate;
  42.  
  43. const double rate1=.026 , rate2=.028 , rate3=.030, rate4=0.32;
  44.  
  45. /*Because we need to deal with decimals, an int or double won't work. It needs
  46. to be a float.*/
  47. char str[100]; /*A string is an array of chars, with a null 0 at the end
  48.                so, in order to use cin.get, I had to switch to its real type.*/
  49.  
  50.   cout << "Enter customer name (lastname first) : ";
  51.  
  52.    cin.get(str,99);
  53.    /* We were only getting up to the space. using .get, it will fetch
  54.    the whole string for us.*/
  55.    
  56.    fflush(stdin);/* Since this is compiled in dev-cpp win7
  57.                  We need to clear our input buffer
  58.                  before we can get more input, otherwise
  59.                  our previous input will be used agian.
  60.                  Even if it allowed a second input, we'd
  61.                  be looking at a stack overflow error.
  62.  
  63. Keep in mind, fflush() is not a standered call.  In Unix im not sure if this is neccessary
  64. but maybe
  65.  
  66. void clear_kb(void)
  67. {
  68.     char junk[255];
  69.     fgets (junk,255,stdin);
  70.    
  71. . */
  72.  
  73.   cout << "What is the length of the box in inches? ";
  74.    cin >> length;
  75.     fflush(stdin);
  76.   cout << "What is the width of the box in inches? ";
  77.    cin >> width;
  78.     fflush(stdin);
  79.   cout << "What is the height of the box in inches? ";
  80.    cin >> height;
  81.     fflush(stdin);
  82.   //    cout << "What is price of shipment? ";
  83.   //    cin >> price;
  84.   //    fflush(stdin);
  85.   volume = length * width * height;
  86.   area1 = length * width, area2 = length * height, area3 = width * height;
  87.   surfacearea = (2 * area1 + 2 * area2 + 2 * area3);
  88.  
  89.  if (surfacearea <= 1000)
  90.     rate = rate1;
  91.    
  92.     else if (1000 < surfacearea && surfacearea <= 2000)
  93.     rate = rate2;
  94.    
  95.         else if (2000 < surfacearea && surfacearea <=3000)
  96.         rate = rate3;
  97.        
  98.             else if (3000 > surfacearea)
  99.             rate = rate4;
  100.    
  101.  
  102.    
  103.  /* area1 = length * width ,area2 = length * height ,area3 = width * height ;
  104.     lenght * width = area1 is the wrong format in programming. the destination (for lack
  105.     of a better term is always on the left.
  106.    
  107.    
  108.   area = (2 * area1) + (2 * area2) + (2* area3) for calculating total surface area ;*/
  109.   area = length * width;
  110.  
  111.   cout << "CUSTOMER INVOICE" << endl;
  112.   cout << "\nCUSTOMER NAME: " << str << endl; /*Escape sequences  */
  113.   cout << " " <<endl;
  114.   cout << "BOX SPECIFICATIONS" <<endl;
  115.   cout << " " <<endl;
  116.   cout << "length    :" << setw(8) << length<< " inches" << endl;
  117.   cout << "width     :" << setw(8) << width << " inches"<< endl;
  118.   cout << "height    :" << setw(8) << height << " inches"<< endl;
  119.   cout << " " <<endl;
  120.   cout << "BOX CHARACTERISTICS" << endl;
  121.   cout << " " <<endl;
  122.   cout << setprecision(2) <<fixed;
  123.   cout << "base area    :" << setw(10) << area << " square inches"<< endl;
  124.   cout << "volume       :" << setw(10) << volume <<" cubic inches" << endl;
  125.   cout << "surface area :" << setw(10) << surfacearea <<" square inches"<< endl;
  126.  
  127.  
  128.   cout << "price is     :" << setw(10) << surfacearea * rate << " U.S Dollars" << endl;
  129.    
  130.   getchar(); /*getchar requires the user press enter before closing. Allows
  131.              those of us running windows to be able to see the information.
  132.              Can be removed if needed.*/
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement