C++ (Lesson 2)

Posted by Black Magic | Posted in | Posted on 6:50 PM



 ဒီေန႕ေတာ့ C++ ကို ဘယ္လိုေရးလဲဆိုတာ စလိုက္ၾကရေအာင္ ဟိုေန႕က အေခၚအေ၀ၚေတြလည္း မွတ္မိ
မယ္ထင္ပါတယ္..ေအာက္က Example ေလးအတုိင္း Turbo C မွာေရးလိုက္ၾကရေအာင္ေနာ္.. ( C: or D:>TC>BIN>TC.EXE )

#include<iostream.h>
void main()
{
   count<<"Hello World";
}

-Code ေတြအေၾကာင္းရွင္းျပပါ့မယ္ C++ ေရးရင္ #include<iostream.h> နဲ႕စပါတယ္ Header file ပါ..ဒါကို ဟိုတစ္ေန႕က ေျပာခဲ့ပါတယ္။
-Void ကို ဘာလို႕ထည့္ထားသလဲဆိုရင္ Retrun ျပန္စရာမလိုေအာင္လို႕ပါ.. Void ကိုသာ ျဖဳတ္ေရးခဲ့မယ္ဆိုရင္ Program အဆံုးမွာ Return true ဒါမွမဟုတ္ Retrun false ျပန္ေပးရပါတယ္..။
-Body ထဲကစာေတြကို {} အဖြင့္အပိတ္နဲ႕ေရးပါတယ္.. User က Hello World ဆိုတာကို Out Put
ျပခ်င္တာေၾကာင့္ count ( Console Output ) ကိုသံုးထားတာပါ။ ျပခ်င္တဲ့စာသား (String) ေတြကို
double code ( " " ) ထဲ ထည့္ေရးရပါမယ္ ။ C++ မွာ Program တစ္ေၾကာင္းဆံုးတိုင္း semi commer
( ; ) ပါပါတယ္.. semi commer မပါတာဆိုလို႕  header file နဲ႕ function name ေတြပဲရွိပါတယ္..
semi commer မပါခဲ့ရင္ Error တက္ပါလိမ့္မယ္။

-ေရးၿပီးရင္ Alt+F9 ကိုႏွိပ္ပါ..Compile လုပ္တာပါ ။ Compile ဆိုတာ Error (အမွား) ရွိမရွိ အရင္စစ္တာ
ပါ
-ပံုျပထားတဲ့အတိုင္း Warnings 0 , Error 0 ျဖစ္ရင္ Run လို႕ရပါၿပီ .. ။


- Run မယ္ဆိုရင္ Clt + F9 ကိုႏွိပ္လုိက္ပါ။ "Hello World" က်လာပါလိမ့္မယ္..တစ္ခ်ိဳ႕ေသာ Computer
ေတြက Turbo C ကို Run လိုက္ရင္ေတာင္ Full Screen မျပႏိုင္ပါဘူး.. အဲလိုမျပႏိုင္ရင္ Run လိုက္ရင္ အေျဖေပၚလာမွာ မဟုတ္ပါ.. Compile ေတာ့စစ္လို႕ရပါတယ္...။

ညီမကြန္ပ်ဴတာလည္း အဲလိုျဖစ္ေနလို႕ Print Screen ဖမ္းၿပီးမျပႏိုင္ပါဘူး :(
- Program တစ္ခုေရးၿပီးသြားလို႕ Save လုပ္ခ်င္ရင္ File >> Save ကိုႏွိပ္လိုက္ပါ။
ေအာက္မွာျပထားတဲ့အတိုင္း က်လာပါလိမ့္မယ္..။


- NONAME00.CPP ကိုဖ်က္ၿပီး နာမည္တစ္ခုခုေပးလုိက္ပါ..။ " .CPP " ကေတာ့ ပါရပါမယ္ ညီမကေတာ့
helloworld.CPP ဆိုၿပီးေပးလိုက္ပါတယ္

- C++ code ေတြရဲ႔..ထိပ္နားမွာ.. helloworld.CPP ဆိုၿပီး..ေၿပာင္းသြားပါလိမ့္မယ္..။

ဒီေလာက္ဆုိရင္.. C++ ကုိ..နည္းနည္းနားလည္လာလိမ့္မယ္လို႔..ယံုၾကည္ပါတယ္..။ ဆက္သြားလိုက္ဦးမယ္ေနာ္.... ^_^

ဒီတစ္ခါ.. user က.. screen ေပၚမွာ.. Good Morning ဆိုတာ..ၿပခ်င္တယ္.. ဘယ္လိုေရးၾကမလဲ..။ လြယ္ပါတယ္.။ ခုနအတိုင္းပဲ. Hello World ေနရာမွာ.. Good Morning ပဲေၿပာင္းသြားမွာပါ..။ အသစ္ထပ္ေရးၿပီး.. Run ၾကည့္ၾကေနာ္..။ အရင္ဆံုး.. Complie စစ္ဦးေနာ္.. :)

#include<iostream.h>
void main( )
{
   cout<<"Good Morning";
}


Variable Declaration


Data Type            Name        Values
int           Integer(ကိန္းၿပည့္)    1,40,584,1000
float        Float(ဒသမကိန္း)    0.12, 1.04, 0.057
double        Double(ဒသမကိန္း)    0.246, 1.224, 3.00445
char               Character    a, b , c , ...... z
String           String(စာေၾကာင္း)    "hello", "ab", "Welcome"

Math Sign

Type    Name
+          Plus
-           Minus or Sub
*          Multiply
/           Divide
%         Modulus ( အၾကြင္း )

ဒါေလးေတြကုိ.. အရင္မွတ္ထားလိုက္ဦးေနာ္..။ ေရးထားတာကုိ..ၾကည့္ရင္..နားလည္မယ္လို႔ထင္ပါတယ္..။

Input tow number and output sum result

#include<iostream.h>
void main( )
{
  int a,b,c;
  a=2;
  b=3;
  c=a+b;
 cout<<"c="<<c;
}
ဒါေလးကို.. Turbo C မွာေရးၾကည့္ၿပီး.. Run ၾကည့္လိုက္ၾကေနာ္..

- int a,b,c; ဆိုတာ.. user က variables ( a,b,c သံုးခု )ကုိ.. int ဆိုၿပီး.. Integer သတ္မွတ္လိုက္တာပါ..။ C++ မွာ.. ကိုယ္သံုးခ်င္တဲ့.. variables ေတြကုိ.. ေရွ႔ကေန.. Data Type ေၾကညာေပးရပါတယ္..။
- a=2; ဆိုတာက.. a ထဲကုိ.. 2ထည့္ထားတယ္လို႔..ဆုိလိုတာပါ..။ Programming code ေတြမွာ.. equal ဆိုတာ.. ညီတယ္လို႔..မဆုိလိုပါဘူး.။ Assign ထည့္တယ္လုိ႔..သတ္မွတ္ပါတယ္.။ left ဘက္က..values ကုိ.. right ဘက္ထဲ ထည့္ထားတာပါ..။
- c=a+b; ဆုိတာလည္း.. a နဲ႔ b ေပါင္းလို႔ရတဲ့အေၿဖကို.. c ထဲထည့္မယ္လုိ႔..ေၿပာထားတာပါ.။
- user က cout ထုတ္လိုက္ေတာ့..ပထမဆံုး. screen မွာ.. "c=" လို႔ေရးထားတဲ့အတြက္.. String ၿဖစ္လုိ႔.. user ေရးထားတဲ့အတုိင္း c= ဆိုၿပီးထြက္လာပါလိမ့္မယ္.။ ေနာက္ေတာ့ c တစ္လံုးေရးထားေတာ့.. c ရဲ႔အေၿဖထြက္လာပါလိ္မ့္မယ္..။ c မွာ. a နဲ႔ b ေပါင္းလို႔ရတဲ့.. အေၿဖ 5 ထြက္လာပါလိမ့္မယ္..။

ဒါက.. အေပါင္းပုဒ္စာေလးပါ.. အဲ့ေနရာမွာ. -, *, / ေၿပာင္းေရးလို႔ရပါတယ္.. ။ ေအာက္မွာ.. အိမ္စာေလးေပးလိုက္မယ္ေနာ္..။ လုပ္ၾကည့္လိုက္ၾက..။ အေၿဖကုိ.. ေနာက္ေန႔.. Comment Box မွာ..စာခ်န္ခဲ့ေပးပါ့မယ္.. ^_^

Write a program to input two numbers from the keyboard and display their sum,sub,mul,div on the screen. Input two numbers are as you like.  

Credit to $U Y4T4N4R
ဒီ Post အတြက္ $U Y4T4N4R ကို ေက်းဇူးတင္ပါတယ္
ကူးယူေဖာ္ၿပရာမွာ ခ်ိဳ႔ယြင္းခ်က္တစ္ခုခုရွိပါက ကၽြန္ေတာ္ရဲ့အသံုးမက်မႈသာၿဖစ္ပါတယ္...

 Copied Answer from Comment of $U Y4T4N4R  Reply

Que: Write a program to input two numbers from the keyboard and display their sum,sub,mul,div on the screen. Input two numbers are as you like.

Answer,

#include
void main( )
{
int a,b,c;
a = 20;
b = 5;
c = a+b;
cout<<"c="<<c;
c = a - b;
cout<<"c="<<c;
c = a*b;
cout<<"c="<<c;
c = a/b;
cout<<"c="<<c;
}


Or another answer,

#inculde<iostream.h>
void main( )
{
int a,b,c;
a = 20;
b = 5;
c = a+b;
c = a-b;
c = a*b;
c = a/b;
cout<<"sum="<<c;
cout<<"sub="<<c;
cout<<"mul="<<c;
cout<<"div="<<c;
}

Comments (0)

လိုခ်င္တာရွိရင္ေအာ္ခဲ့ေနာ္ !

Don't Forget to Like & Follow

Daily Email Updates
Subscribe to Get Latest Updates Free


Check IP

IP
ask4linksask4pc

ကၽြန္ေတာ့ Blog မွာ ဘာကို အဓိကတင္ေစခ်င္လည္း?

ယေန႔ေငြလဲႏႈန္း

DMCA.com Protection

Powered By:

Black Magic © 2013 - All Rights Reserved.