C++

C++ program မရေးမီ သူ့ကို ဘယ်လို ပုံစံနဲ့ အလုပ်လုပ်သွားတယ်ဆိုတာကို အရင်ကြည့်ရအောင်။

[Source code] —- compile—>[Object code] —-link—->[Executable Code]

(eg mypr.cpp) —-compile—->(eg mypr.obj) —-link—–> (eg mypr.exe)

Source code ဆိုတာ user ရေးထားတဲ့ C++ program (.cpp)ကို ပြောတာပါ။ အဲဒီ program ကို computer နားလည်တဲ့ format ဖြစ်အောင် translate လုပ်ပေးရတယ်။ compiler သည် translator program တစ်မျိုးဖြစ်ပါတယ်။ C++ source code ကို compile လုပ်လိုက်ရင် machine readable ဖြစ်တဲ့ object code (.obj) ကို generate လုပ်ပေးပါတယ်။ အဲဒီ object code ကို link လုပ်ပြီးမှသာ executable code (.exe) ထွက်လာတာပါ။ အဲဒီအခါမှ program ရဲ့ output ကို မြင်ရပါတယ်။
C++ Program ကို ရေး ရန်အတွက် Turbo C software အရင် Download လုပ်ရပါမယ်။

To Download TC (Click Here)
ထို့နောက ် TC ကို C: ထဲသို့ Install လုပ်ပါ။

ထိုအခါ C: အတွင်းတွင် TC Folder ရောက်နေ မည်ဖြစ်သည်။

အဲဒီ TC Folder ကိုဖွင့်၍ Bin Folder ကိုဖွင့်ပြီး TC ဆိုသော exe file ကို ဖွင့်ပါက Blue Screen Editor ပေါ်လာပေ ဓည်။၎င်း Editor တွင် Program ကို File-> New ယူ၍ စတင်ရေးနိုင်ပါသည်။

Basic Program Construction

Let’s start at simple program


#include
void main()
{
cout<<"Welcome to edu.mysteryzillion.org";
}

C++ Program ကို Run တိုင်း main[[egg]] ကိုအရင် အလုပ် လုပ် ပါတယ်။အဲဒါကြောင့် program တိုင်းမှာmain[[egg]] function
ပါရမယ်။အဲဒီ main() ထဲမှာ programအတွက် instructions တွေ ကိုရေးရပါမယ်။ instructions တိုင်းသည် semi comma(;) ဖြင့် အဆုံးသတ်ရပါမယ်။
အခု program မှာပါတဲ့ statement(instruction)

cout<<"Welcome To edu.mysteryzillion.org";

အရ double code ထဲမှာရှိတဲ့ phrase ကို screen ပေါ်တွင်outputအဖြစ်မြင်ရပါမယ်။
So the output is
Welcome To edu.mysteryzillion.org ဖြစ်ပါတယ်။
output ထုတ်လိုသော string( စာကြောင်း )ကို double code အတွင်းတွင်သာရေးရ မည်။တကယ်လို့ Hello World! ဆိုတဲ့ output ထွက်ချင်ရင် တော့
cout<<"Hello World!";

* Edit post
* Delete post
* Report this post
* Warn user
* Information
* Reply with quote

Chapter 1

Postby Nyo Nyo Myint » Sat Dec 20, 2008 12:14 am
-Basic Program Construction

Let’s start at simple program

Code: Select all
#include
void main()
{
cout<<“Welcome to edu.mysteryzillion.org”;
}

C++ Program ကို Run တိုင်း main[[egg]] ကိုအရင် အလုပ် လုပ် ပါတယ်။အဲဒါကြောင့် program တိုင်းမှာmain[[egg]] function
ပါရမယ်။အဲဒီ main() ထဲမှာ programအတွက် instructions တွေ ကိုရေးရပါမယ်။ instructions တိုင်းသည် semi comma(;) ဖြင့် အဆုံးသတ်ရပါမယ်။
အခု program မှာပါတဲ့ statement(instruction)

Code: Select all
cout<<“Welcome To edu.mysteryzillion.org”;

အရ double code ထဲမှာရှိတဲ့ phrase ကို screen ပေါ်တွင်outputအဖြစ်မြင်ရပါမယ်။
So the output is
Welcome To edu.mysteryzillion.org ဖြစ်ပါတယ်။
output ထုတ်လိုသော string( စာကြောင်း )ကို double code အတွင်းတွင်သာရေးရ မည်။တကယ်လို့ Hello World! ဆိုတဲ့ output ထွက်ချင်ရင် တော့

Code: Select all
cout<<“Hello World!”;

လို့ ရေးရပါမယ်။
‘cout’ သည် Screen ပေါ်တွင်Display ပေါ်ရန်သုံးသော header file အောက်မှ built in object (output stream)ဖြစ်သည်။Example program တွင် cout ကိုသုံးထားသော ကြောင့် #include ဟုရေးရခြင်းဖြစ်သည်။
# သည် preprocessor directive ဖြစ်သည်။ ‘ #include ‘ tells the compiler to insert another file to your source code.
ထို့ကြောင့် source code တွင် iostream.h ဟူသော file ကိုပါ ထည့်သွင်း ၍ အလုပ် လုပ် မည် ဟု အဓိပ္ပါယ် ရသည်။

Comment

Comment ရေး ခြင်းသည် ရှင်းလင်းချက် ရေး ခြင်း(documentation) ပင်ဖြစ်သည်။ မိမိ Program ကို ကြည့်သောသူကို Program ၏ အဓိပ္ပါယ် ကိုသိရှိစေရန်ဖြစ်သည်။ Compiler သည် Compile လုပ်ရာတွင်Commentကို ဖယ်၍ အလုပ်လုပ်သည်။Commentတွင် Single Line Comment နှင့်Multiline Comment နှစ်မျိုး ရှိသည်။Single Line Comment သည်double slash(//) နှင့် စ ၍ Multiline Commentသည် /* စပြီး */နှင့်အဆုံးသတ်ရသည်။


#include//preprocessor directive
void main[[egg]] //function name main
{ //start function body
cout<<"Welcome to C++"; /*statement to display
Welcome to C++*/
} //end function body

ရေးလိုသော Comment သည် တလိုင်းထက်ပိုပါက //ကိုသုံး၍မရပါ။/* နှင့် */အကြား တွင်သာရေးရမည် ။

-Variables

Variable တခု တွင် name (နာမည် )နှင့်variety of values(တန်ဖိုးအမျိုးမျိုး) ရှိနိုင်သည်။
eg: int var=5;
တွင် Integer ၏ name သည် var ဖြစ်၍ value သည် 5 ဖြစ်သည် ။

Basic Data Type

Integer Variable

Integer variable တွင် အပေါင်း ကိန်:ပြည့်၊ အနှုတ်ကိန်:ပြည့် နှင့် သုည တို့ပါဝင်သည်။Integer တခုသည် memory တွင် 4 byte နေရာယူသည်။MSDOS နှင့် early Window version များတွင် 2 byte နေရာယူသည်။
ထို့ကြောင့် Integer ၏ range ယူပုံ မှာ


For 2 byte Integer
216=65536 numbers (because 1byte=8 bit )
So unsign integer are ranged from 0 to 65535
but signed integer are ranged from -32768 to +32767

တွက်ချက်ပုံမှာ 2 byte နေရာယူသဖြင့် 16 bit ဖြစ်သည်။ 216 သည် 65536 ဖြစ်၍ memory ပေါ်တွင် Integer 65536 လုံး နေရာယူနိုင်သည်။ ။အကယ်၍ unsigned int လက္ခ ဏာ မပါ သော(အနှုတ်ကိန်: မပါသော) Integer အတွက် 0 မှ 65535 အထိရှိပြီး signed Interger အတွက် 65536 ကို အပေါင်း အတွက်တဝက် ၊ အနှုတ်အတွက် တဝက်် 2ဖြင့်စား ပါက 32768 ရသည်။ထို့ကြောင့် Signed Integer၏ range သည် -32768 မှ +32767( 0 သည်အပေါင်းကိန်:ဘက်ပါသောကြောင့် )အထိဖြစ်သည်။

For 4 byte Integer
232=4294967296
For unsigned Integer, range is from 0 to 4294967295
For signed integer,range is from -2147483648 to +2147483647

နောက်ထပ် integer 2မျိုးမှာ short နှင့် long တို့ဖြစ်သည်။ int ၏ size သည် Window System ပေါ်မူတည် ၍ 2 byte သို့မဟုတ် 4byte ယူသော် လဲ short နှင့် long ၏ size မှာ မည်သည့် Window System မဆို fix ဖြစ်သည်။short သည် 2 byte နှင့် long သည် 4byte နေရာယူ သည်။

eg short int var1=7;
long int var2=4564767;

Floating Point Types
Floating Point vaiable သည် real number ဖြစ်သည်။ ထို့ကြောင့် float number တွင် ဒသမ ကိန်: များပါဝင်သည်။C++ တွင် floating point variable 3 မျိုးပါဝင်သည်။ float,double ,long double တို့ဖြစ်သည်။
float သည်memory တွင် 4byte ၊double သည် 8byte နေရာယူ သည်။long double သည် compiler အမျိုးအစား အလိုက်နေရာယူသည်။float type ကို temperature, distance, area စသည့် quantity များ တိုင်းတာရာတွင်သုံးသည်။

eg float distance=2.3;

Character Type
Character သည် memory တွင် 1byte နေရာယူသည်။ Character တွင် ‘a’,’S’,’$’,’3′ စသည်ဖြင့် ပါဝင်သည်။ character အားလုံး 256 လုံးရှိသည်။

Eg char ch=’A’;
char alpha=’a’;

Declarations and Definitions

Declaration introduces a variable name into program and specifies its type.
Declaration သည် variable တခု ၏ name နှင့် data type ကိုသတ်မှတ်ပေးခြင်း ဖြစ်သည်။
eg int a; float b; char ch;

Definition sets a value to the variable.
Definition သည် variable ထဲသို့ value တခုကို assign လုပ်ပေးခြင်းဖြစ်သည်။
eg a=11; b=5.5; ch=’a’;

3 Replies to “C++”

  1. ကောင်းတယ်ဗျို ထပ်တင်ပေးပါဦး ကျေးဇူးတင်ပါတယ်

Leave a Reply to homeless Cancel reply

Your email address will not be published. Required fields are marked *