Visual C 6 Menu Bar Tool Bar Code


แนะนำ Visual C++ 6 Menu Bar Tool Bar Code Editor Project Workspace Output Window



โปรแกรมแรก โปแกรมแรก #include <stdio. h> #include <conio. h> // class for stream input/output int main () } printf(“Hello Word; (“: return 0; { // start of main function #include <iostream. h> int main () } cout<<“Hello Word: n; “ return 0; { // class for stream input/output // start of main function





Argument_list #include <stdio. h> #include <conio. h> // class for stream input/output using namespace std; // use the standard namespace int main () } int T 1=1000 ; char T 2 =”Rit” char T 3=“G” float T 4=10. 50 ; clrscr(); // start of main function { //clear screen printf(“Display T 1 %d n “, T 1; ( printf(“Display T 2 %s n “, T 2; ( printf(“Display T 3 %c n “, T 3; ( printf(“Display T 4 %. 2 f n “, T 4; ( return 0; Output Display T 11000 Display T 2 Rit Display T 3 G Display T 4 10. 50



Argument_list #include <stdio. h> #include <conio. h> // class for stream input/output int main () } char R 1 ; char R 2[5] ; int R 3; float R 4 ; clrscr(); // start of main function { //clear screen printf(“Enter Character : “); scanf(“%c”, &R 1; ( printf(“Enter String : “) ; scanf(“%s”, &R 2); printf(“Enter Integer : ; (“ scanf(“%d”, &R 3; ( printf(“Enter Float : “); scanf(“%f”, &R 4; ( printf(“%c %s %d %. 2 f n”, R 1, R 2, R 3, R 4; ( return 0; Output Enter Character: A Enter String : Good Enter Integer : 25 Enter Float: 12 A Good 25 12. 00



โปรแกรมHello แบบตางๆ โปแกรมแรก #include <iostream. h> int main () } cout<<“Hello Word: n; “ return 0; { // class for stream input/output // start of main function #include <iostream. h> int main () } cout<<“Hello “ <<“Word: n; “ return 0; { // class for stream input/output // start of main function #include <iostream. h> // class for stream input/output int main () // start of main function } cout<<“Hello “ <<“Word: ” <<‘ n; ’ return 0; {




Applying the software development method Case study: Converting Miles to Kilometers PROBLEM Your summer surveying job requires you to study some maps that give distances in kilometers and some that use miles. You and your coworkers prefer to deal in metric measurements. Write a program that performs the necessary conversion. ANALYSIS The problem states that you prefer to deal in metric measurements, so you must convert distance measurements in miles to kilometers. Therefore, the problem input is distance in miles and the problem output is distance in kilometers. To write the program, you need to know the relationship between miles and kilometers. One mile equal 1. 609 kilometers.

Data requirements Problem input miles the distance in miles Problem output kms the distance in kilometers Relevant formula 1 miles = 1. 609 kilometers DESIGN Algorithm. 1 Get the distance in miles. . 2 Convert the distance to kilometers. . 3 Display the distance in kilometers. Now decide whether any steps of the algorithm need further refinement. Case study: Converting Miles to Kilometers

Step 2 Refinement 2. 1 the distance in kilometers is 1. 609 times the distance in miles. Algorithm with refinements. 1 Get the distance in miles. . 2 Convert the distance to kilometers. 2. 1 the distance in kilometers is 1. 609 times the distance in miles. . 3 Display the distance in kilometers. Desk-checking the algorithm: If step 1 gets a distance of 10. 0 miles, step 2. 1 would convert it to 1. 609 x 10. 00 or 16. 09 kilometers. And this correct result would be displayed by step 3. Case study: Converting Miles to Kilometers

IMPLEMENTATION //Miles. cpp //Converts distance in miles to kilometers. #include <stdio. h> using namespace std; // standard input/output // use the standard namespace int main () // start of main function } const float km_per_mile = 1. 609; // 1. 609 km in a mile float miles, // input: distance in miles kms; // output: distance in kilometers // Get the distance in miles. printf("Enter the distance in miles; (“ : scanf( “ %f ”, &miles; ( // Convert the distance to kilometers. kms = km_per_mile * miles; // Display the distance in kilometers. printf (“The distance in kilometers is %f n“, kms; ( return 0; { Enter the distance in miles: 10. 0 The distance in kilometers is 16. 09 Case study: Converting Miles to Kilometers


Operation ตวดำเนนการทางคณตศาสตร Operation( ตวดำเนนการ )Operation( + * / % (Arithmetic ความหมาย )Meaning( Addition ตวอยาง )Example( A+B Subtraction Multiplication Division Modulus A-B A*B A/B A%B

Operation Integer Division and Modulus Examples of integer division: 5 = 3 / 15 0=2/1 0 = 15 / 0 0 / 15 undefined Examples of integer modulus (yielding a remainder: ( 1=2%7 99 = 100 % 299 ) 1 - = 7 % 15 -system dependent( ) 1 = 7 - % 15 system dependent( 0 % 15 undefined %cannot be used with float or double.

Operation ตวดำเนนการเปรยบเทยบ Operation( ตวดำเนนการ )Operation( > < >= <= == != (Comparative ความหมาย )Meaning( Greater than ตวอยาง )Example( A>B Less than Greater than or Equal Less than or Equal Not Equal A<B A>=B A<=B A==B A!=B


Operation ตวดำเนนการกำหนดคา ตวดำเนนการ )Operation( = (Assignment Operation( ความหมาย )Meaning( Assignment ตวอยาง )Example( A=B += -= Addition Subtraction A+=B มาจาก A=A+B A-=B มาจาก A=A-B *= /= %= &= |= ^= >>= Multiplication Divide Modulus Bitwise And Bitwise Inclusive Or Bitwise Exclusive Or Left Shift A*=B มาจาก A=A*B A/=B มาจาก A=A/B A%=B มาจาก A=A%B A&=B มาจาก A=A&B A|=B มาจาก A=A|B A^=B มาจาก A=A^B A>>=B มาจาก A=A>>B



การเพมและการลดคา โปแกรมแรก #include <iostream. h> int main () } cout<<“Hello Word: n; “ return 0; { // class for stream input/output // start of main function #include <iostream. h> int main () } cout<<“Hello “ <<“Word: n; “ return 0; { // class for stream input/output // start of main function #include <iostream. h> // class for stream input/output int main () // start of main function } cout<<“Hello “ <<“Word: ” <<‘ n; ’ return 0; {

ตว อยางการเพมและการลดคา #include <iostream. h> int main () } int m=44, n=66; // class for stream input/output // start of main function cout<<“m = “ <<m<<“, n = “<<n<<endl; ++ m; - - n; cout<<“m = “ <<m<<“, n = “<<n<<endl; m; + + n; - cout<<“m = “ <<m<<“, n = “<<n<<endl; return 0; {

ตว อยางการเพมและการลดคา กอนและหลง #include <iostream. h> int main () } int m=66; // class for stream input/output // start of main function n= ++ m; cout<<“m = “ <<m<<“, n = “<<n<<endl; n = m; ++ cout<<“m = “ <<m<<“, n = “<<n<<endl; cout<<“m = “ <<m++<<endl; cout<<“m = “ <<m<<endl; cout<<“m = “ <<++m<<endl; return 0; {

Operation คำสงวน (List and_eq asm auto bitand bitor bool break case catch char class compl const_cast continue of All C++ Reserved Words) default delete do double dynamic_cast else enum explicit export extern false float for friend goto if inline int long mutable namespace new not_eq operator or or_eq private protected public register reinter pret_cast return short signed sizeof static_cast struct switch template this throw true try typedef typeid typename union unsigned using virtual void volatile wchar_t while xor_eq
- Slides: 35