Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //http://pastebin.com/u/TheWhiteFang
- //Tutorial 6 Section B
- #include <iostream>
- #include <string>
- using namespace std;
- // Class prototype
- class Measurements{
- private:
- string m_Type;
- float m_Yard;
- float m_Feet;
- float m_Inches;
- public:
- static double m_TotalYards;
- static double m_TotalFeet;
- static double m_TotalInch;
- Measurements(string inType, double inVal){
- if (inType == "Y"){
- m_Type = inType;
- m_Yard = inVal;
- m_Feet = 3.0 * inVal;
- m_Inches = inVal * 36.0;
- }
- else if (inType == "I"){
- m_Type = inType;
- m_Inches = inVal;
- m_Yard = inVal*(1.0 / 36.0);
- m_Feet = inVal * (1.0 / 12.0);
- }
- else if (inType == "F"){
- m_Type = inType;
- m_Feet = inVal;
- m_Yard = inVal*(1.0 / 3.0);
- m_Inches = inVal * 12.0;
- }
- else (m_Type = " ", m_Yard = 0.0, m_Inches = 0.0, m_Feet = 0.0);
- }
- void Print(){
- m_TotalYards += m_Yard;
- m_TotalFeet += m_Feet;
- m_TotalInch += m_Inches;
- cout << "Measurement in Yards: " << m_Yard << endl;
- cout << "Measurement in Feets: "<< m_Feet << endl;
- cout << "Measurement in Inches: "<< m_Inches << endl;
- cout << m_TotalInch << endl;
- }
- };
- double Measurements::m_TotalYards = 0.0;
- double Measurements::m_TotalFeet = 0.0;
- double Measurements::m_TotalInch = 0.0;
- // Main function program (Driver program)
- int main()
- {
- string measureType;
- double measureValue;
- for (int i = 0; i < 4; i++)
- {
- cout << "Enter measurement type (Y for yards, F for feet or I for inches): ";
- cin >> measureType;
- cout << "Enter measurement: ";
- cin >> measureValue;
- Measurements measureObj(measureType, measureValue);
- measureObj.Print();
- }
- cout << "Total measurements in Yards: " << Measurements::m_TotalYards << endl;
- cout << "Total measurements in Feet: " << Measurements::m_TotalFeet << endl;
- cout << "Total measurements in Inches: " << Measurements::m_TotalInch << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement