Myanmar IT Resource Forum
Myanmar IT Resource Forum
Myanmar IT Resource Forum

You are not connected. Please login or register

View previous topic View next topic Go down  Message [Page 1 of 1]

C0D3R

C0D3R
MITR Master



MITR Master
ကၽြန္ေတာ္ေလ႔လာမိသေလာက္ေလးေတြကိုေရးေပးသြားမွာျဖစ္ပါတယ္
C++ ကိုစိတ္၀င္စားေသာသူမ်ားအားလံုးကိုလည္းဖိတ္ေခၚပါတယ္
ဒါက 1.cpp
// Our first program
#include

using namespace std;

int main()
{
cout << "Some people think programming Windows"
<< endl
<< "is like nailing jello to the ceiling..."
<< endl
<< "easy with the right kind of nails."
<< endl << endl;
return 0;
}
Save it 1.cpp

endl ေနရာမွာေနာက္ထပ္တစ္ေၾကာင္းဆင္းသြားပါလိမ္႔မယ္
ျပီးေတာ႔ return 0 လ႔ိုျပန္မွာပါ

output ကေတာ႔
Some people think programming Windows
is like nailing jello to the ceiling...
easy with the right kind of nails.

လ႔ိုအေျဖထြက္မွာပါ
//////////////////////////////////////////////////////////////////////////
ဒါက 2.01
// A Simple Example of a Program
#include

using namespace std;

int main()
{
int apples, oranges; // two integer variables ကိုေၾကျငာျခင္း
int fruit; // ...ဒါကအျခားတစ္ခု ကိုေၾကျငာတာပါ

apples = 5; oranges = 6; // တန္ဖိုးသတ္မွတ္ေပးတာပါ
fruit = apples + oranges; // fruit ရဲ႕စုစုေပါင္းတန္ဖိုးရေအာင္ေပါင္းရမွာပါ

cout << endl; // ေနာက္ထပ္လိုင္းတစ္ေၾကာင္းဆင္းဖို႔ေရးထားတာပါ
cout << "Oranges are not the only fruit... " << endl
<< "- and we have " << fruit << " fruits in all."; // fruit ေနရာမွာ apples + oranges ေပါင္းလဒ္တန္ဖိုးရမွာပါ
cout << endl; // ေနာက္ထပ္လိုင္းတစ္ေၾကာင္းဆင္းဖို႔ေရးထားတာပါ

return 0; // program ကေနထြက္ေၾကာင္းအသိေပးတာပါ
}

out put ကေတာ႔
Oranges are not the only fruit..
- and we have 11 fruits in all.
လို႔ေပၚမွာပါ
//////////////////////////////////////////////////////////////////////////////////////
//ဒါက2.02.cpp
// Exercising output
#include

using namespace std;

int main()
{
int num1 = 1234, num2 = 5678; // num1 နဲ႔ num2 ကိုတန္ဖိုးသတ္မွတ္ေပးထားတာပါ
cout << endl; // လိုင္းတစ္ေၾကာင္းဆင္းဖို႔ေရးထားတာပါ
cout << num1 << num2; //တန္ဖိုးႏွစ္ခုကိုျပမွာပါ 1234 နဲ႔ 5678
cout << endl; // ေနာက္ထပ္လိုင္းတစ္ေၾကာင္းဆင္းဖို႔ေရးထားတာပါ
return 0; // program ကေနထြက္ေၾကာင္းအသိေပးတာပါ
}

out put ကေတာ႔
12345678

///////////////////////////////////////////////////////////////////////////////////
/ EX2.03.cpp
// Exercising output
#include
#include

using namespace std;

int main()
{
int num1 = 1234, num2 = 5678;
cout << endl; // လိုင္းတစ္ေၾကာင္းဆင္းဖို႔ေရးထားတာပါ
cout << setw(6) << num1 << setw(6) << num2; //တန္ဖိုးႏွစ္ခုကိုျပမွာပါ
cout << endl; // လိုင္းတစ္ေၾကာင္းဆင္းဖို႔ေရးထားတာပါ
return 0; // program ကေနထြက္ေၾကာင္းအသိေပးတာပါ
}
output ကေတာ႔
1234 5678

setw(6)သံုးထားတဲ႔အတြက္1234 နဲ႔ 5678 ေရွ႕မွာ နွစ္ေနရာစာခ်န္ခဲ႔ပါတယ္
အကယ္ရွ္ setw(4) ကိုသံုးမယ္ဆိုရင္ဂဏန္းကေလးလံုးပဲ႔ရွိတယ္ဆိုေတာ႔ေနရာလြတ္မက်န္ပါဘူး
ဒီလိုပဲ႔ setw(-)ေနရာမွာ အျခားဂဏန္းေတြထည္႔ျပီးစမ္းၾကည္႔ေပါ႔ေနာ္

////////////////////////////////////////////////////////////////////////////

ဆက္ေရးမယ္လာမယ္ၾကာမယ္ေနာ္

http://www.myanmaritresource.info

C0D3R

C0D3R
MITR Master



MITR Master
ဒါေလးကေတာ႔
// EX2_04.CPP
// Calculating how many rolls of wallpaper are required for a room
#include <iostream>

using namespace std;

int main()
{
double height = 0.0, width = 0.0, length = 0.0; // အခန္းရဲ႕ထုထည္ကိုေၾကျငာတာပါ
double perimeter = 0.0; // အခန္းရဲ႕ပတ္လည္အနားကိုေၾကျငာတာပါ

const double rollwidth =21.0; // အနံရဲ႕စံသတ္မွတ္ခ်က္
const double rolllength = 12.*33.; // အလ်ားရဲ႕စံသတ္မွတ္ခ်က္(33ft.)

double strips_per_roll = 0; // roll ကအရွည္ရဲ႕အေရအတြက္
double strips_reqd = 0; // လိုအပ္တဲ႕အရွည္ရဲ႕အေရအတြက္
double nrolls = 0; // rolls ရဲ႕စုစုေပါင္းတန္ဖိုး

cout << endl // ေနာက္ထပ္လိုင္းတစ္ေၾကာင္းဆင္းဖို႔ေရးထားတာပါ
<< "Enter the height of the room in inches: ";
cin >> height;

cout << endl // ေနာက္ထပ္လိုင္းတစ္ေၾကာင္းဆင္းဖို႔ေရးထားတာပါ
<< "Now enter the length and width in inches: ";
cin >> length >> width;

strips_per_roll = rolllength/height; // roll က အရွည္ရဲ႕အေရအတြက္ကိုတြက္ထုတ္ဖို႔ပါ
perimeter = 2.0*(length + width); //room perimeter ကိုတြက္ထုတ္ဖို႔ပါ
strips_reqd = perimeter/rollwidth; // လိုအပ္တဲ႔စုစုေပါင္း strips
nrolls = strips_reqd/strips_per_roll; // rolls ရဲ႕အေရတြက္ကိုတြက္ထုတ္ဖို႔

cout << endl // ေနာက္ထပ္လိုင္းတစ္ေၾကာင္းဆင္းဖို႔ေရးထားတာပါ
<< "For your room you need " << nrolls << " rolls of wallpaper."
<< endl;

return 0;
}
ဂဏန္းေတာင္းတဲအခါ 1 ေပးလိုက္ေတာ႔
output ကေတာ႔

Enter the height of the room in inches: 1
Now enter the length and width in inches:1
1
For your room you need 0.000481 rolls of wallpaper

အဆင္ေျပပါေစဗ်ာ
///////////////////////////////////////////////////////////////////////////////
// EX2_05.CPP
// Exercising the comma operator
#include <iostream>

using namespace std;

int main()
{
long num1 = 0, num2 = 0, num3 = 0, num4 = 0;

num4 = (num1 = 10, num2 = 20, num3 = 30); //အဲဒီေနရာမွာ num3တန္ဖိုးေပၚမွာပါ
cout << endl
<< "The value of a series of expressions "
<< "is the value of the right most: "
<< num4;
cout << endl;

return 0;
}

output ကေတာ႔
The value of a series of expressions is the value of the right most: 30
လိုေပၚမွာပါ
//////////////////////////////////////////////////////////////////////////////////////
// EX2_06.CPP
// Demonstrating variable scope
#include <iostream>

using namespace std;

int main()
{ // Function လုပ္ေဆာင္ခ်က္စတင္
int count1 = 10; //count1 မွာ 10တန္ဖိုးသတ္မွတ္ေပးထားသည္
int count3 = 50; //count3 မွာ 50တန္ဖိုးသတ္မွတ္ေပးထားသည္
cout << endl
<< "Value of outer count1 = " << count1
<< endl;

{ // လုပ္ေဆာင္ခ်က္အသစ္ထပ္စတင္သည္
int count1 = 20; // count1အသစ္ကို 20 တန္ဖိုးသတ္မွတ္ေပးထားသည္
int count2 = 30; //count3 မွာ 30တန္ဖိုးသတ္မွတ္ေပးထားသည္
cout << "Value of inner count1 = " << count1
<< endl;
count1 += 3; // This affects the inner count1
count3 += count2; //count3 50တန္ဖိုးမွာ count2 တန္ဖိုး 30 လာေပါင္းထည္႔သည္
} //လုပ္ေဆာင္ခ်က္အသစ္ျပီးဆံုး

cout << "Value of outer count1 = " << count1
<< endl
<< "Value of outer count3 = " << count3
<< endl;
return 0;
} // Function လုပ္ေဆာင္ခ်က္ျပီးဆံုး

output ကေတာ႔
Value of outer count1 =10
Value of outer count1 =20
Value of outer count1 =10
Value of outer count3 =80

http://www.myanmaritresource.info

C0D3R

C0D3R
MITR Master



MITR Master
///////////////////////////////////////////////////////////
// EX2_08.CPP
// Demonstrating namespace names
#include <iostream>

int value = 0;

int main()
{
std::cout << "enter an integer: "; // User ထံမွဂဏန္းတစ္လံုးေတာင္းသည္
std::cin >> value; //User က input ဂဏန္းတစ္လံုးေပးရမည္
std::cout << "\nYou entered " << value
<< std::endl;
return 0;
}
value ကို 2 လိုေပးလိုက္ေတာ႔

Output ကေတာ႔႔
You entered 2
ဆိုျပီးေပၚမွာပါ
//////////////////////////////
ဒါေလးကေတာ႔အေပၚကပုဒ္စာနဲ႔အလုပ္လုပ္ပံုခ်င္းတူပါတယ္ဒါေပမယ္႔ namespace ကိုေၾကျငာပံုေလးကြဲျပီးအနည္းငယ္ကြဲလြဲမွူရွိပါတယ္ေလ႔လာၾကည္႔႔ပါ
// EX2_09.CPP
// Declaring a namespace
#include <iostream>

namespace myStuff
{
int value = 0;
}

int main()
{
std::cout << "enter an integer: ";
std::cin >> myStuff::value;
std::cout << "\nYou entered " << myStuff::value
<< std::endl;
return 0;
}
value ကို 3 လိုေပးလိုက္ေတာ႔

Output ကေတာ႔႔
You entered 3
ဆိုျပီးေပၚမွာပါ
//////////////////////////////////////////////////////////////////////
// EX2_10.CPP
// Using a using directive
#include <iostream>

namespace myStuff
{
int value = 0;
}

using namespace myStuff;

int main()
{
std::cout << "enter an integer: ";
std::cin >> value;
std::cout << "\nYou entered " << value
<< std::endl;

return 0;
}

value ကို 3 လိုေပးလိုက္ေတာ႔

Output ကေတာ႔႔
You entered 3
------------------------------------
/////////////////////////////////////////////////////

http://www.myanmaritresource.info

C0D3R

C0D3R
MITR Master



MITR Master
ဒါေလးကေတာ႔ စာလံုးအၾကီးအေသးစစ္တာပါ
// EX3_01.CPP
// A nested if demonstration
#include <iostream>

using namespace std;

int main()
{
char letter = 0; // Store input in here

cout << endl
<< "Enter a letter: "; // Prompt for the input
cin >> letter; // then read a character

if(letter >= 'A') // Test for 'A' or larger
if(letter <= 'Z') // Test for 'Z' or smaller
{
cout << endl
<< "You entered a capital letter."
<< endl;
system("pause");
return 0;
}

if(letter >= 'a') // Test for 'a' or larger
if(letter <= 'z') // Test for 'z' or smaller
{
cout << endl
<< "You entered a small letter."
<< endl;
system("pause");
return 0;
}

cout << endl << "You did not enter a letter." << endl;

return 0;
}

http://www.myanmaritresource.info

C0D3R

C0D3R
MITR Master



MITR Master
သင္ရိုက္ထည္႔မည္႔ ဂဏန္းကစံုကိန္းလား မကိန္းလားဆိုတာသိေအာင္လုပ္တဲ႔ function ေလးပါ
// EX3_02.CPP
// Using the extended if
#include <iostream>

using namespace std;

int main()
{
long number=0;
cout<<endl<<"Enter an interger number less than 2 billion:";
cin >> number;
if(number%2L)
cout<<endl<<"Your number is odd." <<endl;
else
cout<<endl<<"Your number is even."<<endl;
return 0;
}
output ကေတာ႔
number ေတာင္းတဲ႔အခါ 5 ေပးလိုက္ရင္
Your number is odd
number ေတာင္းတဲ႔အခါ 6 ေပးလိုက္ရင္
Your number is even
ဆိုျပီးေပၚမွာပါ
////////////////////////////////////////////////////////////////
ဒါကေေတာ႔ ရိုက္ထည္႔လိုက္တဲ႔ input ကို letter ? ဆိုတာစစ္ေပးတာပါ
if statemnet ကိုသံုးျပီး logical operators ကိုသံုးျပထားတာပါ
// EX3_03.CPP
// Testing for a letter using logical operators
#include <iostream>

using namespace std;

int main()
{
char letter = 0; // Store input in here

cout << endl
<< "Enter a character: ";
cin >> letter;

if(((letter>='A')&&(letter<='Z')) ||
((letter>='a')&&(letter<='z'))) // Test for alphabetic
cout << endl
<< "You entered a letter." << endl;
else
cout << endl
<< "You didn't enter a letter." << endl;
return 0;
}
output ကေတာ႔ ကၽြန္ေတာ္တို႔က myanmar လို႔ရိုက္ထည္႔ရင္
You entered a letter
လို႔ေပၚမွာပါ
အကယ္ရွ္ကၽြန္ေတာ္တို႔က myanmar လို႔မရိုက္ပဲ႔ ဂဏန္း (3)လို႔ရိုက္ထည္႔ရင္
You didn't enter a letter
လို႔ေပၚမွာပါ

http://www.myanmaritresource.info

C0D3R

C0D3R
MITR Master



MITR Master
//////////////////////////////////////////////
// EX3_04.CPP
// The conditional operator selecting output
#include <iostream>

using namespace std;

int main()
{
int nCakes = 1; // cakes ကိုတန္ဖိုးသတ္မွတ္ေပးထားတာပါ

cout << endl
<< "We have " << nCakes << " cake" << ((nCakes>1) ? "s." : ".") //Cakes တန္ဖိုးက 1ခုဆိုရင္ s ကမပါေတာ႔ပါဘူး
<< endl;

++nCakes; //Cakes တန္ဖိုးကို ++ လုပ္ထားတဲ႔အတြက္1ထပ္တိုးမွာပါ

cout << endl
<< "We have " << nCakes << " cake" << ((nCakes>1) ? "s." : ".") //Cakes တန္ဖိုးက 1ထက္ၾကီးတယ္ဆိုရင္ s ကိုေပါင္းထည္႔ေပးမွာပါ
<< endl;
return 0;
}
output ကေတာ႔
We have 1 cake.

We have 2 cakes.
လို႔ေပၚမွာပါ
//////////////////////////////////////////////////////////////////////////////////////
switch statement ကိုသံုးထားပံုေလးပါ
// EX3_05.CPP
// Using the switch statement
#include <iostream>

using namespace std;

int main()
{
int choice=0;
cout<< endl
<< "What is your relish website in myanmar." << endl
<< "You can choose from the following website: "
<< endl
<< endl << "1 MZ"
<< endl << "2 MITR"
<< endl << "3 MMSO"
<< endl << "4 MITP"
<< endl << endl << "Enter your selection website number: ";
cin>>choice;
switch(choice)
{
case 1: cout<<endl<<"[You must be registered and logged in to see this link.]
break;
case 2: cout<<endl<<"[You must be registered and logged in to see this link.]
break;
case 3:cout<<endl<<"[You must be registered and logged in to see this link.]
break;
case 4:cout<<endl<<"[You must be registered and logged in to see this link.]
break;
default:cout<<endl<<"Your enter a woring number,try site number.";
}
return 0;
}
output ကေတာ႔
What is your relish website in myanmar.
You can choose from the following website:

1 MZ
2 MITR
3 MMSO
4 MITP

Enter your selection website number:2 //2လို႔ရိုက္ထည္႔ရင္

[You must be registered and logged in to see this link.]
//////////////////////////////////////////////////////////

http://www.myanmaritresource.info

C0D3R

C0D3R
MITR Master



MITR Master
case action ကိုအမ်ိဳးမ်ိဳးအသံုးျပဳပံုေလးပါ
// EX3_06.CPP
// Multiple case actions
#include <iostream>

using namespace std;

int main()
{
char letter = 0;
cout << endl
<< "Enter a small letter: ";
cin >> letter;

switch(letter*(letter>='a' && letter <='z'))
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u': cout << endl << "You entered a vowel.";
break;

case 0: cout << endl << "It is not a small letter.";
break;

default: cout << endl << "You entered a consonant.";
}
cout << endl;
return 0;
}
output ကေတာ႔ a,e,i,o,u ဆိုတဲ႔ ဂဏန္းေတြကိုရိုက္ရင္
You entered a vowel.
မဟုတ္ဘူးဆိုရင္
You entered a consonant.
ဂဏန္းရုိက္ထည္႔ရင္ေတာ႔
It is not a small letter.
လို႔ေပၚမွာပါ

http://www.myanmaritresource.info

Sponsored content


View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum

 

Free forum | ©phpBB | Free forum support | Report an abuse | Forumotion.com