<< Chapter < Page Chapter >> Page >

2: #include<iostream.h>

3: class Time

4: {

5: public:

6: Time(int = 0, int = 0, int = 0); //Constructor mặc định

7: //Các hàm set

8: void SetTime(int, int, int); //Thiết lập thời gian

9: void SetHour(int); //Thiết lập Hour

10: void SetMinute(int); //Thiết lập Minute

11: void SetSecond(int); //Thiết lập Second

12: //Các hàm get

13: int GetHour() const; //Trả về Hour

14: int GetMinute() const; //Trả về Minute

15: int GetSecond() const; //Trả về Second

16: //Các hàm in

17: void PrintMilitary() const; //In t.gian theo dạng giờ quân đội

18: void PrintStandard() const; //In thời gian theo dạng giờ chuẩn

19: private:

20: int Hour; //0 - 23

21: int Minute; //0 - 59

22: int Second; //0 – 59

23: };

24:

25: //Constructor khởi động dữ liệu private

26: //Các giá trị mặc định là 0

27: Time::Time(int hr, int min, int sec)

28: {

29: SetTime(hr, min, sec);

30: }

31:

32: //Thiết lập các giá trị của Hour, Minute, và Second

33: void Time::SetTime(int h, int m, int s)

34: {

35: Hour = (h>= 0&&h<24) ? h : 0;

36: Minute = (m>= 0&&m<60) ? m : 0;

37: Second = (s>= 0&&s<60) ? s : 0;

38: }

39:

40: //Thiết lập giá trị của Hour

41: void Time::SetHour(int h)

42: {

43: Hour = (h>= 0&&h<24) ? h : 0;

44: }

45:

46: //Thiết lập giá trị của Minute

47: void Time::SetMinute(int m)

48: {

49: Minute = (m>= 0&&m<60) ? m : 0;

50: }

51:

52: //Thiết lập giá trị của Second

53: void Time::SetSecond(int s)

54: {

55: Second = (s>= 0&&s<60) ? s : 0;

56: }

57:

58: //Lấy giá trị của Hour

59: int Time::GetHour() const

60: {

61: return Hour;

62: }

63:

64: //Lấy giá trị của Minute

65: int Time::GetMinute() const

66: {

67: return Minute;

68: }

69:

70: //Lấy giá trị của Second

71: int Time::GetSecond() const

72: {

73: return Second;

74: }

75:

76: //Hiển thị thời gian dạng giờ quân đội: HH:MM:SS

77: void Time::PrintMilitary() const

78: {

79: cout<<(Hour<10 ? "0" : "")<<Hour<<":"

80:     <<(Minute<10 ? "0" : "")<<Minute<<":"

81:     <<(Second<10 ? "0" : "")<<Second;

82: }

83:

84: //Hiển thị thời gian dạng chuẩn: HH:MM:SS AM (hay PM)

85: void Time::PrintStandard() const

86: {

87: cout<<((Hour == 12) ? 12 : Hour % 12)<<":"

88:      <<(Minute<10 ? "0" : "")<<Minute<<":"

89:      <<(Second<10 ? "0" : "")<<Second

90:      <<(Hour<12 ? " AM" : " PM");

91: }

92:

93: int main()

94: {

95: const Time T(19, 33, 52); //Đối tượng hằng

96: T.SetHour(12); //ERROR: non-const member function

97: T.SetMinute(20); //ERROR: non-const member function

98: T.SetSecond(39); //ERROR: non-const member function

99: return 0;

100: }

Chương trình này khai báo một đối tượng hằng của lớp Time và cố gắng sửa đổi đối tượng với các hàm thành viên không hằng SetHour(), SetMinute() và SetSecond(). Các lỗi cảnh báo được phát sinh bởi trình biên dịch (Borland C++) như hình 3.13.

Hình 3.13: Các cảnh báo của chương trình ở ví dụ 3.13

Lưu ý: Hàm thành viên const có thể được đa năng hóa với một phiên bản non-const. Việc lựa chọn hàm thành viên đa năng hóa nào để sử dụng được tạo một cách tự động bởi trình biên dịch dựa vào nơi mà đối tượng được khai báo const hay không.

Một đối tượng const không thể được thay đổi bởi phép gán vì thế nó phải được khởi động. Khi một thành viên dữ liệu của một lớp được khai báo const, một bộ khởi tạo thành viên (member initializer) phải được sử dụng để cung cấp cho constructor với giá trị ban đầu của thành viên dữ liệu đối với một đối tượng của lớp.

Questions & Answers

any tip for igcse economics exam?pls
Stacey Reply
well
The
What is a market
Divine Reply
what are the variables that affect demand
Divine
what are the variables that affect demand
Divine
what are the variables that affect demand
Divine
what are the variables that affect demand
Divine
what are the variables that affect demand
Divine
price of the related goods 2 price of the given commodity 3 income of the consumer 4 taste and preference 5 expectation in the future price
John
pls the taste and preference
Nas
explain briefly
Nas
a consumer taste and preference commodity changes for a time the man becomes
John
sorry sorry
John
is when the price of a commodity becomes high and can't afford example Samsung instead of iPhone
John
consumers who have high intense for goods will purchase the goods even if the price of that commodity increases because he or she preferred that commodity.people will be prefer iphone as its price increase
Yussif
as usual bad taste of preference is when a consumer regrets from one commodity to another in terms of the price
John
thanks alot
Nas
you're welcome
John
#Preference; #Income #Test
Dereje
#price Of Commodity #Income #Taste #Preference
Dereje
#Market is The Place Where Buyers And Sellers Are Exchanging Their Goods And service. #
Dereje
difference between macro and micro economics
Lawrence
Microeconomic Study about individual consumers market But Macroeconomis Study General economic Process Such As #Aggregate Demand #Aggregate Supples #GDp= #GNp
Dereje
nice so can u run down a brife discussion on GDP
Lawrence
good
Chinex
pls can someone differentiate between the perfectly elastic, perfectly inelastic and unitary
yhar Reply
and then again pls what are the types of elasticity, the methods of calculating it thank u
yhar
Perfectly inelastic is when the coefficient is equal to zero Unitary is when the coefficient is equal to one But am not sure if we have perfectly inelastic
John
I'm kind off confuse abt the PED, IED and co are they the types of elasticity we've
yhar
Yh the types are price elasticity cross and income elasticity of demand
John
do we've specific formulaes to calculate for each of them
yhar
yes. PED. changes in quantity demanded divided by changes in price
Vealmurugan
so pls what's the general name given to unitary, elastic n inelastic ? are the names given to the final result after doing the calculations?
yhar
P2-P1÷P1×100or Q2-Q1×Q1×100 PED
John
***tutor2u.net/economics/reference/price-elasticity-of-demand
Vealmurugan
They are elasticity coefficient
John
@John I don't get u well pls
yhar
whichone
John
P2-P1÷P1×100or Q2-Q1×Q1×100 PED @john pls tis is what m talking abt
yhar
Yh is the formula for PED
John
Pls are you having a for PED
John
thank u very
yhar
dy
Jobang
what is economics
Tayyeb
economics is a science which studies human behaviour as a relationship between ends and scarce means which have alternative use
John
is a science which study human behavior as a relationship between ends and scarce means which have alternative uses
Divine
yes this is because economic provide a body of knowledge on human economic principles under theories and these theories can be verified with real world data using science method in other words it was scientific method in arriving at solution identification of problem or basic data collection among
John
unitary ElasticWhen Elasticty =1 Perfectily Elastic When 0<1 inelastic when 0>
Dereje
Pls is anyone having the NovDec questions?
John Reply
No
Emmanuel
what is micro economics
Rakesh Reply
What is PPF
Endam
Production Possibility Frontier
John
It refers to a curve or graph which shows the possible contributions of maximum alternative of commodity that can be produced in an economy
John
thanks
Endam
Thanks John talkx of defination pls
Endam
I don't get you
John
guys Any One With Novdec Questions 2019?
Diana Reply
what did Adam Smith introduce?
Sunday Reply
what is supply
Awunyo Reply
supply relationship shows that the higher the price, the higher the quantity supplied. 
SDADY
what are the dissadvantages of large scale production
Atanga Reply
depreciate of quality taste
Kosiso
Some of the Disadvantages are:- 1. Production not according to individual Tastes 2. Monopoly 3. Not Flexible 4. Over-Production 5. Heavy loss and Dislocation 6. Decline of Cottage and Small Scale Industries 7. Adverse Effect on Labourers 8. Unequal Distribution of Wealth
Asrar
And what can be the advantages too
Enow
1.adequate satisfaction 2.reduce importation
Yussif
Reduce importation how pls
Enow
the country will have enough products.this will reduce the level of government expenditure on imported goods especially
Yussif
Some of Advantage 1. Division of Labour 2. More Production 3. Use of machines 4. Low Cost of Production 5. Standard Goods 6. Advertisements and Salesmanship
Asrar
Some of its disadvantages are : (i) Less Supervision (ii) Individual tastes ignored (iii) Absence of Personal Element (iv) Possibility of depression (v) Dependence on Foreign Markets (vi) International complications and war (vii) Cut-throat Competition (viii) Less Adaptability
Kalu
what are the types of trade cycle
Kenny Reply
depression
DG
explain the following 1.supply 2.mobility of labour 3.why the demand slope downward from left to right
Theresa Reply
Mobility of labor is a the movement of labor (people) geographically or occupationally
Olotu
What is Supply
Kamodu Reply
Supply is quantity of a comodity which is presented in the market for sell on fixed price
Mahwish
Supply is quality of a goods the seller are willing to deliver at the particular price
Chinex
what is economy
Jacob Reply
Economy is defined as the efficient use of resources
Thomas
explain merits and demerit of economic
Portia
What is Unemployment?
Prince Reply
unemployment is a situation where an individual is easily and ready to render services but resources are not available.
Phelix
Unemployment refers to individual who are employable and seeking a job but are unable to find a job or doesn't have a job. To find the unemployment rate in a given economy, you must divide the unemployed people by the total number of employed people in the work force. Indicator of economy's status.
elkanah
unemployment is The level of joblessness in an economy, often measured as a percentage of the workforce. Unemployment was reported at 5.2% in May, up from 4.9% in April
ANNOR
Pls wat are the factors that influence unemployment
Olotu
just trying ⚠ factors that affect unemployment - the rate of imported inflation - interest rates - levels of investment
Wallace
unemployment is a situation where country labour Force who are active capable and are really searching for or willing to work at assistant wage rates but cannot find job
John
working age ppl who have no job for a period of time. there are different types of unemployment like structural, fictional, seasonal n etc. there is a formula to calculate it. n have factors causes this.
Vealmurugan
factors that influence on employment 1 high population growth growth as against low Industries growth rates 2 lack of skills or mass irritracy 3 government policies such as minimum wage trade liberalization and high taxation 4 initial capital requirements
John
I'm an economics student, what I do now will make my life a success,
mostafiz
Thank you
Tantoh
😂😂😂😂😂😂😂☺☺☺🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂👩‍🎓👩‍🎓👩‍🎓👩‍🎓👩‍🎓👩‍🎓
Leta
what is difference between economic growth and economic development?( I want unique &brief answer)?
Leta
unemployment is when legitimate labour Force are not engaged in the economy.
Lawrence
economic growth is the already settled growth of the economy and National income can be used in verification of that while economic development is the process of improvement in an economy
Lawrence
what is rational behavior
Aaron Reply
James what is nationalisation
Awunyo
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





Source:  OpenStax, Lập trình hướng đối tượng. OpenStax CNX. Jul 29, 2009 Download for free at http://cnx.org/content/col10794/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Lập trình hướng đối tượng' conversation and receive update notifications?

Ask