Professional Documents
Culture Documents
#include <iostream>
////////////////////////////////////////////////
class Interval
public:
Long GetTime()
void Print()
private:
long minutes;
long seconds;
};
////////////////////////////////////////////////
int main(void)
Interval jack;
jack.Print();
Interval jeff;
jeff.Print();
==========================================================================
#include <iostream>
////////////////////////////////////////////////
class Interval
public:
time = value;
Long GetTime()
{
return time;
void Print()
else
private:
long time;
};
////////////////////////////////////////////////
int main(void)
{
Interval jack;
jack.SetTime(125);
jack.Print();
Interval jeff;
jeff.SetTime(200);
jeff.Print();
========================================================================
3 Constructors…………………………………………………………………………………………………….
#include <iostream>
////////////////////////////////////////////////
class Interval
public:
Interval()
time = 0;
Interval(long t)
time = t;
//parameterized constructor
Interval(long s, long m)
time = 60 * m + s;
time = value;
Long GetTime()
return time;
void Print()
else
}
private:
long time;
};
////////////////////////////////////////////////
void Run(void)
john.Print();
int main(void)
jack.SetTime(125);
jack.Print();
Run();
jeff.Print();
}
=======================================================================
4 ConstrDestr…………………………………………………………
#include <iostream>
////////////////////////////////////////////////
class Interval
public:
time = 60 * m + s;
++count;
time = value;
}
Long GetTime()
return time;
//receives (hidden) this argument which points to the object on which it is invoked
void Print()
else
return count;
}
//destructor
~Interval()
count--;
private:
long time; //instance field - each object contains its own value for this field
static int count; //class field - its value is shared by all the objects
};
////////////////////////////////////////////////
void Run(void)
john.Print();
}
int main(void)
jack.SetTime(125);
jack.Print();
Run();
jeff.Print();
<< Interval::GetCount()
<<endl;
===================================================================
5 ConstrDestrr use of const…………………
#include <iostream>
////////////////////////////////////////////////
class Interval
public:
time = 60 * m + s;
++count;
voidSetTime(long value)
time = value;
}
longGetTime() const//long Interval::GetTime(const Interval* this)
else
staticintGetCount()
return count;
~Interval()
count--;
private:
long time;
staticint count;
};
int Interval::count = 0;
////////////////////////////////////////////////
int main(void)
Interval jack;
jack.SetTime(125);
jack.Print();
<< Interval::GetCount()
<<endl
=========================================================================
Commands………..
1 cd Foundations/C++/
2 mkdir Classes
3 cd Classes/
4 vi classtest1.cpp
6 vi classtest1.cpp
8 ./classtest1
9 vi classtest1.cpp
11 ./classtest1
12 vi classtest1.cpp
14 ./classtest1
15 cp classtest1.cpp classtest2.cpp
16 vi classtest2.cpp
17 c++ -o classtest2 classtest2.cpp
18 ./classtest2
19 cp classtest2.cpp ctortest.cpp
20 vi ctortest.cpp
22 ./ctortest
23 vi ctortest.cpp
25 ./ctortest
26 vi ctortest.cpp
28 ./ctortest
29 vi ctortest.cpp
31 vi ctortest.cpp
33 ./ctortest
34 vi ctortest.cpp
36 vi ctortest.cpp
38 ./ctortest
39 vi ctortest.cpp
41 ./ctortest
42 cp ctortest.cpp dtortest.cpp
43 vi dtortest.cpp
45 ./dtortest
46 vi dtortest.cpp
48 ./dtortest
49 vi dtortest.cpp
51 ./dtortest
52 vi dtortest.cpp
54 ./dtortest
55 vi dtortest.cpp
57 vi dtortest.cpp
58 cp dtortest.cpp objreftest.cpp
59 vi objreftest.cpp
61 ./objreftest
62 vi objreftest.cpp
64 ./objreftest
65 vi objreftest.cpp
68 vi objreftest.cpp
70 vi objreftest.cpp
72 ./objreftest
73 vi objreftest.cpp
75 vi objreftest.cpp
76 vi dtortest.cpp
77 history>cmd09-04-15.txt