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។

Nested IF in Excel - Tutorial

Nested IF in Excel

📘 What is Nested IF?

Nested IF allows multiple conditional checks in Excel. It is useful for grading, categorization, and logical decision-making.

Excel Logo for SEO

Example Formula

=IF(A2>=90,"A",IF(A2>=80,"B",IF(A2>=70,"C",IF(A2>=60,"D","F"))))

This formula assigns grades based on score ranges.

💻 Interactive Demo

Enter a score to see the grade:

📝 More Examples

Nested IF can handle multiple scenarios. Here is another common use case:

Price Category

=IF(B2<50,"Cheap",IF(B2<100,"Moderate","Expensive"))

⚠️ When to Avoid Nested IF

While powerful, deeply nested IF formulas are hard to read and maintain. Consider using the IFS function (Excel 2016 and later) or lookup functions (VLOOKUP, INDEX/MATCH) for clearer logic.

🔗 Related Functions & Alternatives

  • IFS – evaluates multiple conditions without nesting.
  • SWITCH – matches an expression against a list of values.
  • VLOOKUP, INDEX/MATCH – lookup tables for multi‑criteria logic.

🛠 Tips for Writing Nested IFs

  • Start with the most restrictive condition first.
  • Use line breaks and indenting (Alt+Enter) in the Excel formula bar for readability.
  • Label ranges or cells with names to make formulas self‑documenting.

how to use Vlookup function in Excel

Use VLOOKUP when you need to find things in a table or a range by row. For example, look up a price of an automotive part by the part number, or find an employee name based on their employee ID. In its simplest form, the VLOOKUP function says: =VLOOKUP(What you want to look up, where you want to look for it, the column number in the range containing the value to return, return an Approximate or Exact match – indicated as 1/TRUE, or 0/FALSE).

how to use vlookup function

Use VLOOKUP when you need to find things in a table or a range by row. For example, look up a price of an automotive part by the part number, or find an employee name based on their employee ID. In its simplest form, the VLOOKUP function says: =VLOOKUP(What you want to look up, where you want to look for it, the column number in the range containing the value to return, return an Approximate or Exact match – indicated as 1/TRUE, or 0/FALSE).

how to create formulas in excel

here you can Start to Learn you basic Excel Spreadsheet in Shorttime and upgrade your Skill in Excel Formula

Top 10 Most Useful Excel Formulas

  • sum
  • Count
  • countif
  • Countifs
  • Average
  • Rank
  • Counta
  • sumIF
  • sumIFs
  • Logical IF
click me

How to use if function

 Use the IF function, one of the logical functions, to return one value if a condition is true and another value if it's false. For example: =IF(A2>B2,"Over Budget","OK") =IF(A2=B2,B4-A4,"")

Countif

COUNTIFS function

Definition

The COUNTIFS function applies criteria to cells across multiple ranges and counts the number of times all criteria are met.

Syntax

COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2]…) The COUNTIFS function syntax has the following arguments:

  • criteria_range1 Required. The first range in which to evaluate the associated criteria.
  • criteria1 Required. The criteria in the form of a number, expression, cell reference, or text that define which cells will be counted. For example, criteria can be expressed as 32, ">32", B4, "apples", or "32".
  • criteria_range2, criteria2, ... Optional. Additional ranges and their associated criteria. Up to 127 range/criteria pairs are allowed.
Remark
  • Each range's criteria is applied one cell at a time. If all of the first cells meet their associated criteria, the count increases by 1. If all of the second cells meet their associated criteria, the count increases by 1 again, and so on until all of the cells are evaluated.
  • If the criteria argument is a reference to an empty cell, the COUNTIFS function treats the empty cell as a 0 value.
  • You can use the wildcard characters— the question mark (?) and asterisk (*) — in criteria. A question mark matches any single character, and an asterisk matches any sequence of characters. If you want to find an actual question mark or asterisk, type a tilde (~) before the character.
Salesperson Exceeded Q1 quota Exceeded Q2 quota Exceeded Q3 quota
Burke Yes Yes No
Davidoski Yes No No
Sundaram Yes Yes Yes
Levitan No Yes Yes
Formula Description Result
=COUNTIFS(B2:D2,"=Yes") Counts how many times Davidoski exceeded a sales quota for periods Q1, Q2, and Q3 (only in Q1). 1
=COUNTIFS(B2:B5,"=Yes",C2:C5,"=Yes") Counts how many salespeople exceeded both their Q1 and Q2 quotas (Burke and Sundaram). 2
=COUNTIFS(B5:D5,"=Yes",B3:D3,"=Yes") Counts how many times Levitan and Burke exceeded the same quota for periods Q1, Q2, and Q3 (only in Q2). 1

SumIF

Excel SUMIF Function

Purpose

Sum numbers in a range that meet supplied criteria Return value The sum of values supplied.

Syntax

=SUMIF (range, criteria, [sum_range])

Arguments

range - Range to apply criteria to. criteria - Criteria to apply. sum_range - [optional] Range to sum. If omitted, cells in range are summed.

Using if Function Excel

Mastering the basic Excel formulas is critical for beginners to become highly proficient in financial analysis. Microsoft Excel is considered the industry standard piece of software in data analysis. Microsoft’s spreadsheet program also happens to be one of the most preferred software by investment bankers and financial analysts in data processing, financial modeling, and presentation. This guide will provide an overview and list of basic Excel functions.

Basic Terms in Excel

There are two basic ways to perform calculations in Excel: Formulas and Functions.

  1. Formulas

In Excel, a formula is an expression that operates on values in a range of cells or a cell. For example, =A1+A2+A3, which finds the sum of the range of values from cell A1 to cell A3.

  1. Functions

Functions are predefined formulas in Excel. They eliminate laborious manual entry of formulas while giving them human-friendly names. For example: =SUM(A1:A3). The function sums all the values from A1 to A3.

Basic Excel Formulas Guide

Mastering the basic Excel formulas is critical for beginners to become highly proficient in financial analysis. Microsoft Excel is considered the industry standard piece of software in data analysis. Microsoft’s spreadsheet program also happens to be one of the most preferred software by investment bankers and financial analysts in data processing, financial modeling, and presentation. This guide will provide an overview and list of basic Excel functions.

Basic Terms in Excel

There are two basic ways to perform calculations in Excel: Formulas and Functions.

  1. Formulas

In Excel, a formula is an expression that operates on values in a range of cells or a cell. For example, =A1+A2+A3, which finds the sum of the range of values from cell A1 to cell A3.

  1. Functions

Functions are predefined formulas in Excel. They eliminate laborious manual entry of formulas while giving them human-friendly names. For example: =SUM(A1:A3). The function sums all the values from A1 to A3.

how to create formulas in excel

here you can Start to Learn you basic Excel Spreadsheet in Shorttime and upgrade your Skill in Excel Formula

Top 10 Most Useful Excel Formulas

  • sum
  • Count
  • countif
  • Countifs
  • Average
  • Rank
  • Counta
  • sumIF
  • sumIFs
  • Logical IF