SlideShare ist ein Scribd-Unternehmen logo
1 von 3
Downloaden Sie, um offline zu lesen
Bài Giải Đề PP LTHĐT 2011 – 2012 Khóa 10
                             (Bài giải chỉ mang tính chất tham khảo)

Câu 1:
  a. Hàm main trong đề bài có 2 constructor (phương thức khởi tạo/thiết lập) ở dòng 02 và 05 và 2
     destructor (phương thức hủy) được gọi ở dòng 10 và sau khi kết thúc khối lệnh if.
  b.
         i. Dòng /*1*/ lỗi do không thể truy suất được tới thuộc tính this->m_tgian do có
              tầm vực truy cập là private.
         ii. Dòng /*2*/ lỗi do phương thức float MayLoc::congSuat() có tầm vực truy
              cập là protected.
         iii. Dòng /*3*/ lỗi do con trỏ pm gán với biến tĩnh mà trước đó, nó đã được cấp phát một
              vùng nhớ động và chưa được hủy, vì vậy tạo nên sự rò rỉ bộ nhớ (Memory Leak).
         iv. Dòng /*4*/ lỗi do pm lưu địa chỉ của một biến tĩnh mà nó còn được hủy trước đó khi
              thoát khỏi khối lệnh if cho nên khi hủy sẽ phát sinh lỗi.
  c. Dòng /*1*/:
     this->m_tgian = t;             /*1*/
     sẽ được sửa thành:
     this-> setTgian(t);          /*1*/
  d. Nếu xóa đi dòng /*2*/, kết quả xuất ra màn hình là:

                                          Luong nuoc = 819
  e. Để sửa lỗi ở dòng /*4*/, ta sẽ dời nó trước dòng gán biến tĩnh ml cho con trỏ pm (dòng 06):

                    01: void main() {
                    02:    MayLoc *pm = new MayLoc();
                    03:    if (pm->congSuat() < 5) /*2*/
                    04:    {
                    05:       MayLyTam ml(81.9, 10);
                    06:       delete pm;           /*4*/
                    07:       pm = &ml;            /*3*/
                    08:       cout << "Luong nuoc = "
                    09:            << pm->tinhLuongNuoc();
                    10:    }
Câu 2:
#include <iostream>
using namespace std;
class MayLocXucTac :
       public MayLoc
{
private:
       float m_luongHoaChat;
       float m_cs;
public:
       static const float DON_GIA_HOA_CHAT;
       static const float DON_GIA_THUE;

public:
       void nhap()
       {
              float tgian = 0;

             cout << "Nhap thoi gian su dung: ";
             cin >> tgian;
             this->setTgian(tgian);

             cout << "Nhap cong suat: ";
             cin >> this->m_cs;
      }
      float tinhThoiGian()
      {
             return MayLoc::tinhLuongNuoc() / m_cs;
      }
      float congSuatLocThucTe()
      {
             float cong_suat = m_cs * (m_luongHoaChat / 100.0f);
             if (tinhThoiGian() >= 10.0f)
                    cong_suat = cong_suat / (tinhThoiGian() / 10.0f);

             return cong_suat;
      }
      float tinhChiPhi()
      {
             return DON_GIA_THUE * tinhThoiGian() + m_luongHoaChat * DON_GIA_HOA_CHAT;
      }
      float tinhLuongNuoc()
      {
             return congSuatLocThucTe() * tinhThoiGian();
      }
};

static const float DON_GIA_HOA_CHAT = 10.0f;
static const float DON_GIA_THUE = 80000.0f;
void main() {
     cout << "Don gia hoa chat: " << MayXucTac::DON_GIA_HOA_CHAT << endl;
     MayXucTac m;
     m.nhap();   // Nhập thông tin sử dụng của máy xúc tác này
     cout << "Chi phi su dung may: " << m.tinhChiPhi() << endl;
     cout << "Luong nuoc loc duoc: " << m.tinhLuongNuoc() << endl;
}

Weitere ähnliche Inhalte

Empfohlen

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Empfohlen (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

Bai giai de pp lthđt 2011 – 2012 khoa 10 (1)

  • 1. Bài Giải Đề PP LTHĐT 2011 – 2012 Khóa 10 (Bài giải chỉ mang tính chất tham khảo) Câu 1: a. Hàm main trong đề bài có 2 constructor (phương thức khởi tạo/thiết lập) ở dòng 02 và 05 và 2 destructor (phương thức hủy) được gọi ở dòng 10 và sau khi kết thúc khối lệnh if. b. i. Dòng /*1*/ lỗi do không thể truy suất được tới thuộc tính this->m_tgian do có tầm vực truy cập là private. ii. Dòng /*2*/ lỗi do phương thức float MayLoc::congSuat() có tầm vực truy cập là protected. iii. Dòng /*3*/ lỗi do con trỏ pm gán với biến tĩnh mà trước đó, nó đã được cấp phát một vùng nhớ động và chưa được hủy, vì vậy tạo nên sự rò rỉ bộ nhớ (Memory Leak). iv. Dòng /*4*/ lỗi do pm lưu địa chỉ của một biến tĩnh mà nó còn được hủy trước đó khi thoát khỏi khối lệnh if cho nên khi hủy sẽ phát sinh lỗi. c. Dòng /*1*/: this->m_tgian = t; /*1*/ sẽ được sửa thành: this-> setTgian(t); /*1*/ d. Nếu xóa đi dòng /*2*/, kết quả xuất ra màn hình là: Luong nuoc = 819 e. Để sửa lỗi ở dòng /*4*/, ta sẽ dời nó trước dòng gán biến tĩnh ml cho con trỏ pm (dòng 06): 01: void main() { 02: MayLoc *pm = new MayLoc(); 03: if (pm->congSuat() < 5) /*2*/ 04: { 05: MayLyTam ml(81.9, 10); 06: delete pm; /*4*/ 07: pm = &ml; /*3*/ 08: cout << "Luong nuoc = " 09: << pm->tinhLuongNuoc(); 10: }
  • 2. Câu 2: #include <iostream> using namespace std; class MayLocXucTac : public MayLoc { private: float m_luongHoaChat; float m_cs; public: static const float DON_GIA_HOA_CHAT; static const float DON_GIA_THUE; public: void nhap() { float tgian = 0; cout << "Nhap thoi gian su dung: "; cin >> tgian; this->setTgian(tgian); cout << "Nhap cong suat: "; cin >> this->m_cs; } float tinhThoiGian() { return MayLoc::tinhLuongNuoc() / m_cs; } float congSuatLocThucTe() { float cong_suat = m_cs * (m_luongHoaChat / 100.0f); if (tinhThoiGian() >= 10.0f) cong_suat = cong_suat / (tinhThoiGian() / 10.0f); return cong_suat; } float tinhChiPhi() { return DON_GIA_THUE * tinhThoiGian() + m_luongHoaChat * DON_GIA_HOA_CHAT; } float tinhLuongNuoc() { return congSuatLocThucTe() * tinhThoiGian(); } }; static const float DON_GIA_HOA_CHAT = 10.0f; static const float DON_GIA_THUE = 80000.0f;
  • 3. void main() { cout << "Don gia hoa chat: " << MayXucTac::DON_GIA_HOA_CHAT << endl; MayXucTac m; m.nhap(); // Nhập thông tin sử dụng của máy xúc tác này cout << "Chi phi su dung may: " << m.tinhChiPhi() << endl; cout << "Luong nuoc loc duoc: " << m.tinhLuongNuoc() << endl; }