Control Structure in C++ Programming

C++ Programming Tutorial

Control Structure in C++ Programming

Control Structure គឺជាការបញ្ជាការប្រតិបត្តិកម្មវិធី (Program Flow) ក្នុង C++ ដើម្បីសម្រេចចិត្ត ឬធ្វើការងារដដែលៗ។

1. Introduction to Control Structure

Control Structure មាន 3 ប្រភេទសំខាន់៖

  • Sequential Structure
  • Selection Structure
  • Loop Structure
---

2. If Statement

ប្រើសម្រាប់ពិនិត្យលក្ខខណ្ឌ។

#include <iostream>

using namespace std;

int main(){

int age;

cout<<"Enter age: ";
cin>>age;

if(age >= 18)
cout<<"You are adult";

}
---

3. If Else Statement

#include <iostream>

using namespace std;

int main(){

int number;

cout<<"Enter number:";
cin>>number;

if(number % 2 == 0)
cout<<"Even Number";

else
cout<<"Odd Number";

}
---

4. Switch Case

#include <iostream>

using namespace std;

int main(){

int day;

cout<<"Enter day number:";
cin>>day;

switch(day){

case 1:
cout<<"Monday";
break;

case 2:
cout<<"Tuesday";
break;

default:
cout<<"Invalid Day";

}

}
---

5. Loop Structure

Loop ប្រើសម្រាប់ធ្វើការងារដដែលៗ។

For Loop Example

#include <iostream>

using namespace std;

int main(){

for(int i=1;i<=5;i++)
cout<

While Loop Example

#include <iostream>

using namespace std;

int main(){

int i=1;

while(i<=5){

cout<

---



6. Project Practice – Student Grade System

Create program to calculate student grade using Control Structure.

#include <iostream>

using namespace std;

int main(){

int score;

cout<<"Enter Score:";
cin>>score;

if(score >= 90)
cout<<"Grade A";

else if(score >= 80)
cout<<"Grade B";

else if(score >= 70)
cout<<"Grade C";

else if(score >= 60)
cout<<"Grade D";

else
cout<<"Fail";

}
---

Control Structure Summary

Type Example
Selection If, If Else, Switch
Loop For, While, Do While
Sequential Program runs step by step

© 2026 C++ Programming Tutorial Blog

STL and Header File in C++ Tutorial

STL and Header File in C++

Complete Tutorial with Project Practice

1. What is STL in C++?

STL (Standard Template Library) គឺជាក្រុម Library ស្រាប់នៅក្នុង C++ ដែលផ្តល់ Data Structure និង Algorithms សម្រាប់ការសរសេរកម្មវិធី។

STL មាន 3 ផ្នែកសំខាន់៖

  • Containers
  • Algorithms
  • Iterators

2. Vector Container

Vector គឺជា Dynamic Array ដែលអាចបន្ថែម Data បានដោយប្រើ push_back().

#include <iostream>
#include <vector>

using namespace std;

int main()
{
vector<int> numbers;

numbers.push_back(10);
numbers.push_back(20);
numbers.push_back(30);

for(int i=0;i<numbers.size();i++)
{
cout<<numbers[i]<<endl;
}

return 0;
}

3. Stack Container

Stack ប្រើគោលការណ៍ LIFO (Last In First Out)

#include <iostream>
#include <stack>

using namespace std;

int main()
{
stack<int> s;

s.push(10);
s.push(20);
s.push(30);

cout<<s.top();

return 0;
}

4. Queue Container

Queue ប្រើ FIFO (First In First Out)

#include <iostream>
#include <queue>

using namespace std;

int main()
{
queue<int> q;

q.push(1);
q.push(2);
q.push(3);

cout<<q.front();

return 0;
}

5. Algorithms in STL

Algorithm Library ប្រើសម្រាប់ Sorting និង Searching

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{

vector<int> num = {5,2,8,1,9};

sort(num.begin(), num.end());

for(int x : num)
cout<<x<<" ";

return 0;

}

6. Header File in C++

Header File គឺជា File ដែលផ្ទុក Function Declaration និង Class Definition។

Example Header Files:

  • iostream
  • vector
  • stack
  • queue
  • algorithm

7. Creating Custom Header File

#ifndef MATHFUNCTIONS_H
#define MATHFUNCTIONS_H

int add(int a,int b);
int sub(int a,int b);

#endif

8. Project Practice – Student Management System

Features:

  • Add Student
  • Display Student
  • Search Student
#include <iostream>
#include <vector>

using namespace std;

class Student
{
public:

int id;
string name;
float score;

};

int main()
{

vector<Student> students;

Student s;

cout<<"Enter ID: ";
cin>>s.id;

cout<<"Enter Name: ";
cin>>s.name;

cout<<"Enter Score: ";
cin>>s.score;

students.push_back(s);

for(Student st : students)
{
cout<<st.id<<" "<<st.name<<" "<<st.score<<endl;
}

return 0;

}

9. Common STL Header Files

Header Purpose
vector Dynamic Array
stack Stack Data Structure
queue Queue Data Structure
map Key Value Pair
algorithm Sorting and Searching

© 2026 C++ Programming Tutorial | STL and Header Files

ការប្រើ QR Code និង Barcode ក្នុង Excel

ការប្រើរូបមន្ត QR Code និង Barcode ក្នុង Excel

ក្នុងការងារ Inventory, POS System, Student ID, Product Management យើងអាចបង្កើត QR Code និង Barcode នៅក្នុង Excel បានយ៉ាងងាយ។


🔹 1. បង្កើត QR Code ក្នុង Excel (Using Formula)

យើងអាចប្រើ Google Chart API ដើម្បី Generate QR Code:

=IMAGE("https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl="&A2)

👉 A2 = ទិន្នន័យដែលយើងចង់បំលែងជា QR Code

ចំណាំ: ត្រូវប្រើ Excel Version ថ្មី (Microsoft 365 / Excel 2021) ដែលគាំទ្រ Function IMAGE()

2. បង្កើត Barcode ក្នុង Excel

Step 1: Install Barcode Font

Download Font ដូចជា:

  • Code 39
  • Code 128

Step 2: ប្រើរូបមន្ត

="*"&A2&"*"

បន្ទាប់មក Change Font ទៅជា Code 39 នោះវានឹងបង្ហាញជា Barcode ភ្លាមៗ។


3. Example Table

Product Code QR Code Barcode
P001 =IMAGE("https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=P001") *P001*

អត្ថប្រយោជន៍

  • ប្រើសម្រាប់ POS System
  • Stock Management
  • Student ID Card
  • Invoice System

សន្និដ្ឋាន

Excel អាចប្រើសម្រាប់បង្កើត QR Code និង Barcode បានដោយមិនចាំបាច់ប្រើ Software បន្ថែម។ វាជាវិធីងាយស្រួលសម្រាប់ Project ដូចជា POS System, Inventory System និង eCommerce System។