Advertisement
M_A_Tabarani

Some School stuff (11)

Oct 21st, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 KB | None | 0 0
  1. //Class and stuff
  2.  
  3. // Class Drill for Drill Object
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. const double PI = 3.142;
  9.  
  10. class Drill {
  11.  
  12. public:
  13.     Drill () {}
  14.     Drill (double,double,double);
  15.     double mrr() const;
  16.     double torque (double) const;
  17.  
  18. private:
  19.     double diameter,
  20.            feed,
  21.            speed;
  22.  
  23. friend istream& operator >> (istream&, Drill&);
  24. friend ostream& operator << (ostream&, const Drill&);
  25. };
  26.  
  27. //
  28. // Constructor 2: Initializes all components
  29. //
  30. Drill::Drill(double drillDiam, double drillFeed, double drillSpeed)
  31. {
  32.     diameter = drillDiam;
  33.     feed = drillFeed;
  34.     speed = drillSpeed;
  35. }
  36.  
  37. //
  38. // material removal rate: mm^3/sec
  39. //
  40. double Drill :: mrr() const
  41. {
  42.     return (PI*0.25*diameter*diameter*feed*speed/60.0);
  43. }
  44.  
  45. //
  46. // torque (W.s) on drill based on unit power (W.s/mm^3)
  47. // dissipated
  48. // in cutting workpiece material
  49. //
  50. double Drill :: torque (double unitPower) const
  51. {
  52.     double radSec; // rotational speed in radians per second
  53.  
  54.     radSec = speed*2*PI/60.0;
  55.     return (unitPower*mrr()/radSec);
  56. }
  57. //
  58. // Extract from input source the three components of a Drill object
  59. //
  60. istream& operator >> (istream& is, Drill& dr)
  61. {
  62.     is >> dr.diameter >> dr.feed >> dr.speed;
  63.     return is;
  64. }
  65.  
  66. //
  67. // Display a drill object, labeling all components
  68. //
  69. ostream& operator << (ostream& os, const Drill& dr)
  70. {
  71.     os << "Drill " << endl << " diameter: " << dr.diameter << " mm" <<endl
  72.         <<" feed: " << dr.feed << "  mm/rev" << endl << "    speed: " << dr.speed << "   rpm" << endl;
  73.         return os;
  74. }
  75.  
  76. //
  77. // Driver to declare and manipulate a drill object
  78. //
  79. int main ()
  80. {
  81.     Drill drillA;
  82.     double unitPower;
  83.  
  84.     cout << "Describe a drill by entering diameter (mm), feed (mm/rev). "
  85.         << "speed (rpm) " << endl << "=>";
  86.     cin >> drillA;
  87.     cout << "Enter average power unit for workpiece material (W.s/mm^3)"
  88.         <<endl << "=>";
  89.         cin>>unitPower;
  90.  
  91.         cout << endl << drillA << endl;
  92.         cout << "Drill's material removal rate is: " <<
  93.     drillA.mrr() <<
  94.                 " mm^3/sec" << endl;
  95.         cout << "Torque on the drill when drilling the given workpiece material: "
  96.              << drillA.torque(unitPower) << "W.s" << endl;
  97.         return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement