Advertisement
TheWhiteFang

Tutorial 6 Section B

Dec 17th, 2014
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 KB | None | 0 0
  1. //http://pastebin.com/u/TheWhiteFang
  2. //Tutorial 6 Section B
  3. #include <iostream>
  4. #include <string>
  5. using namespace std;
  6. // Class prototype
  7. class Measurements{
  8. private:
  9.  
  10.     string m_Type;
  11.     float m_Yard;
  12.     float m_Feet;
  13.     float m_Inches;
  14.  
  15. public:
  16.     static double m_TotalYards;
  17.     static double m_TotalFeet;
  18.     static double m_TotalInch;
  19.    
  20.  
  21.     Measurements(string inType, double inVal){
  22.  
  23.        
  24.         if (inType == "Y"){
  25.             m_Type = inType;
  26.             m_Yard = inVal;
  27.             m_Feet = 3.0 * inVal;
  28.             m_Inches = inVal * 36.0;
  29.  
  30.         }
  31.         else if (inType == "I"){
  32.             m_Type = inType;
  33.             m_Inches = inVal;
  34.             m_Yard = inVal*(1.0 / 36.0);
  35.             m_Feet = inVal * (1.0 / 12.0);
  36.         }
  37.         else if (inType == "F"){
  38.             m_Type = inType;
  39.             m_Feet = inVal;
  40.             m_Yard = inVal*(1.0 / 3.0);
  41.             m_Inches = inVal * 12.0;
  42.         }
  43.         else (m_Type = " ", m_Yard = 0.0, m_Inches = 0.0, m_Feet = 0.0);
  44.  
  45.     }
  46.  
  47.     void Print(){
  48.         m_TotalYards += m_Yard;
  49.         m_TotalFeet += m_Feet;
  50.         m_TotalInch += m_Inches;
  51.        
  52.  
  53.         cout << "Measurement in Yards: " << m_Yard << endl;
  54.         cout << "Measurement in Feets: "<< m_Feet << endl;
  55.         cout << "Measurement in Inches: "<< m_Inches << endl;
  56.         cout << m_TotalInch << endl;
  57.     }
  58.  
  59. };
  60.  
  61. double Measurements::m_TotalYards = 0.0;
  62. double Measurements::m_TotalFeet = 0.0;
  63. double Measurements::m_TotalInch = 0.0;
  64.  
  65.  
  66.  
  67. // Main function program (Driver program)
  68. int main()
  69. {
  70.     string measureType;
  71.     double measureValue;
  72.     for (int i = 0; i < 4; i++)
  73.     {
  74.         cout << "Enter measurement type (Y for yards, F for feet or I for inches): ";
  75.         cin >> measureType;
  76.         cout << "Enter measurement: ";
  77.         cin >> measureValue;
  78.         Measurements measureObj(measureType, measureValue);
  79.         measureObj.Print();
  80.        
  81.  
  82.     }
  83.    
  84.     cout << "Total measurements in Yards: " << Measurements::m_TotalYards << endl;
  85.     cout << "Total measurements in Feet: " << Measurements::m_TotalFeet << endl;
  86.     cout << "Total measurements in Inches: " << Measurements::m_TotalInch << endl;
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement