Pages

Friday, August 28, 2015

Flowchart เบื้องต้น

1. ความหมายผังงาน

ผังงาน (Flowchart) คือ รูปภาพ (Image) หรือสัญลักษณ์(Symbol) ที่ใช้เขียนแทนขั้นตอน คำอธิบาย ข้อความ หรือคำพูด ที่ใช้ในอัลกอริทึม (Algorithm) เพราะการนำเสนอขั้นตอนของงานให้เข้าใจตรงกัน ระหว่างผู้เกี่ยวข้อง ด้วยคำพูด หรือข้อความทำได้ยากกว่า

2. ประเภทผังงาน

  1. ผังงานระบบ (System Flowchart) คือ ผังงานที่แสดงขั้นตอนการทำงานในระบบอย่างกว้างๆ แต่ไม่เจาะลงในระบบงานย่อย
  2. ผังงานโปรแกรม (Program Flowchart) คือ ผังงานที่แสดงถึงขั้นตอนในการทำงานของโปรแกรม ตั้งแต่รับข้อมูล คำนวณ จนถึงแสดงผลลัพธ์

3. ประโยชน์ของผังงาน

  1. ทำให้เข้าใจ และแยกแยะปัญหาได้ง่าย (Problem Define)
  2. แสดงลำดับการทำงาน (Step Flowing)
  3. หาข้อผิดพลาดได้ง่าย (Easy to Debug)
  4. ทำความเข้าใจโปรแกรมได้ง่าย (Easy to Read)
  5. ไม่ขึ้นกับภาษาใดภาษาหนึ่ง (Flexible Language)

4. สัญลักษณ์ผังงาน



 

5. รูปแบบการจัดภาพของผังงาน

1) การทำงานแบบตามลำดับ (Sequence)

รูปแบบการเขียนโปรแกรมที่ง่ายที่สุดคือ เขียนให้ทำงานจากบนลงล่าง เขียนคำสั่งเป็นบรรทัด และทำทีละบรรทัดจากบรรทัดบนสุดลงไปจนถึงบรรทัดล่างสุด สมมติให้มีการทำงาน 3 กระบวนการคือ อ่านข้อมูล คำนวณ และพิมพ์


2) การเลือกกระทำตามเงื่อนไข (Decision or Selection)

การตัดสินใจ หรือเลือกเงื่อนไขคือ เขียนโปรแกรมเพื่อนำค่าไปเลือกกระทำ โดยปกติจะมีเหตุการณ์ให้ทำ 2 กระบวนการ คือเงื่อนไขเป็นจริงจะกระทำกระบวนการหนึ่ง และเป็นเท็จจะกระทำอีกกระบวนการหนึ่ง แต่ถ้าซับซ้อนมากขึ้น จะต้องใช้เงื่อนไขหลายชั้น เช่นการตัดเกรดนักศึกษา เป็นต้น ตัวอย่างผังงานนี้ จะแสดงผลการเลือกอย่างง่าย เพื่อทำกระบวนการเพียงกระบวนการเดียว


3) การทำซ้ำ (Repeation or Loop)
การทำกระบวนการหนึ่งหลายครั้ง โดยมีเงื่อนไขในการควบคุม หมายถึงการทำซ้ำเป็นหลักการที่ทำความเข้าใจได้ยากกว่า 2 รูปแบบแรก เพราะการเขียนโปรแกรมแต่ละภาษา จะไม่แสดงภาพอย่างชัดเจนเหมือนการเขียนผังงาน ผู้เขียนโปรแกรมต้องจินตนาการด้วยตนเอง

3.1) เงื่อนไขแบบ while

 

3.2) เงื่อนไขแบบ do while

 

3.3) เงื่อนไขแบบ for

 

6. ตัวอย่างผังงาน




 

การใช้ Tense


1. Present Simple Tense

  1. เหตุการณ์ที่เป็นจริงทั่วๆไป (general truth)
  2. การกระทำที่ทำเป็นประจำจนติดเป็นนิสัย
  3. เหตุการณ์ที่เป็นความจริงในขณะที่พูด
  4. สิ่งที่กำหนดแน่นอนว่าจะทำในอนาคต
  5. บอกคำพูด นิยาย หรือคำประพันธ์ที่ผู้ประพันธ์ได้กล่าวไว้
  6. ใช้กับประโยค If-Cluase เพื่อบอกเหตุผลที่จะเกิดขึ้น หรือเงื่อนไขบางประการที่เป็นไปได้
  7. ใช้กับประโยคอุทาน หลังคำว่า here หรือ there
  • The earth moves round the sun.
  • He gets up early everyday.
  • She sleeps in the bed.
  • He sets sail tomorrow and comes back next week.
  • Obama says that we must change.
  • If she comes, I will see her.
  • Here comes the bus! / There goes your friends!

2. Present Continuous Tense

  1. การกระทำที่กำลังเกิดขึ้นขณะพูด
  2. เหตุการณ์ที่กำลังเกิดขึ้นเป็นประจำขณะที่พูด (ใช้แทน Present Simple Tense ได้)
  3. เหตุการณ์ที่กำลังจะเกิดขึ้นในอนาคตอันใกล้ คากว่าเกิดขึ้นแน่นอน (ส่วนใหญ่ใช้กับกริยาเคลื่นที่)
  4. กริยาที่ใช้กับ continuous tense ไม่ได้
    • สภาวะจิตใจหรือความรู้สึก believe feel doubt want wish know like love suppose hate remember recognize see think
    • การรับรู้ appear hear look seem smell taste
    • ความเป็นเจ้าของ posses own have belong
    • อื่นๆ agree consist deny depend disagree mean please promise include need satisfy surprise
  • He is walking now.
  • My dad is just sleeping in the bed. (เน้นว่ากำลังเกิดขึ้น ให้หนักแน่นยิ่งขึ้น)
  • He is working hard this month.
  • She is coming here next week.
  • I am going to hunt next week.

3. Present Pefect Tense

  1. เหตุการณ์ที่เกิดขึ้นในอดีต และยังคงดำเนินต่อเนื่องเรื่อยมาจนถึงปัจจุบัน แม้ในขณะที่พูดถึงเหตุการณ์นั้นอยู่ มักมีคำต่อไปนี้ since, for, so far, up to now, up to the present
  2. เหตุการณ์ที่แสดงว่า เคยหรือไม่เคยทำ นับตั้งแต่อดีตเรื่อยมาจนถึงปัจจุบัน มีกมีคำเหล่านี้ never, ever, once, twice
  3. เหตุการณ์ที่เพิ่งจบลงใหม่ๆ มีกมีคำเหล่านี้ just, yet, already
  4. เหตุการณ์ที่จบลงไปแล้ว แต่ผู้พูดยังคงรู้สึกถึงผลของเหตุการณ์นั้นอยู่
  • I have lived in Bangkok since I was 18 years old.
  • She has slept in the room for 8 hours.
  • Have you ever been to Tokyo?
  • I have just com back from Japan.
  • Has he finished the work yet? No. not yet.
  • I’ve seen her before.

4. Present Perfect Continuous Tense

  1. เหตุการณ์ที่เกิดขึ้นในอดีต และดำเนินต่อเนื่องเรื่อยมาจนถึงปัจจุบัน มีความต่อเนื่องของการกระทำ มักมีคำว่า since, for
  2. คำกริยาที่ใช้ใน tense นี้ ต้องเป็นคำที่แสดงถึงความต่อเนื่องเท่านั้น ได้แก่ learn, live, wait, eat ฯลฯ กริยาที่ใช้ไม่ได้ เช่น stop, lie, arrive
  3. เน้นความต่อเนื่องของการกระทำมากกว่า Present Pefect Tense จึงไม่ใช้กับคำเหล่านี้ just, already, never, finally
  4. ใช้ since แบบนี้ Present Perfect Continuous Tense + since + Past Tense
  • I have been studying English since 2007.
  • He has been sleeping since he came back from the office.
  • Q: You look tired. A: Yes, I have been working all day.
  • I have known her for several years. (ไม่ใช่ have been knowing)
  • I have been living here since I was a child.
  • She have been working since she woke up.

5. Past Simple Tense

  1. การกระทำที่เกิดขึ้นและจบลงไปแล้วในอตีค มักมีคำแสดงอดีต yesterday, last year, ago, once upon a time, durng the war
  2. การกระทำที่เกิดขึ้นเป็นประจำในอดีต แต่ปัจจุบันเลิกทำแล้ว มักมีคำ always frequently, usually, never (ถ้ามีคำบอกความถี่อย่างเดียว ไม่บอกเวลา จะใช้ Present Simple Tense)
  • She went to the movie last night.
  • Jane always went to school late last year. (แต่ปัจจุบันไม่ได้สายแล้ว)
  • I used to get up early in the morning when I was young.

6. Past Continuous Tense

  1. ใช้ได้โดยลำพังเมื่อมีช่วงเวลาแสดงว่ากำลังเกิดเหตุการณ์
  2. ใช้กับเหตุการณ์ 2 อย่าง ซึ่งกำลังดำเนินอยู่พร้อมๆกันในอดีต มักมี while, as, when
  3. เหตุการณ์ 1 ดำเนินอยู่ในอดีต (Past Continuous Tense) และเหตุการณ์ 2 เกิดขึ้นแทรก (Past Simple Tense)
  • At 8 o’clock yesterday he was having breakfast.
  • He was running all evening long.
  • His wife was sleeping while he was working.
  • While I was sleeping last night, it rained.
  • As I was running down the street, I saw Sam driving a car.

7. Past Perfect Tense

  1. ใช้กับเหตุการณ์ 2 อย่างที่เกิดขึ้นในอดีต เหตุการณ์ 1 เกิดขึ้นและจบลงก่อน (Past Perfect Tense) และเหตุการณ์ 2 เกิดทีหลัง (Past Simple Tense)
  2. ใช้แทน Present Perfect Tense และ Past Simple Tense ในประโยค Indirect Speech
  3. ใช้ตามหลัง wish แสดงสิ่งที่อยากเป็นในอดีต (แต่ในอดีตไม่ได้เกิดเช่นนั้น)
  • He had already woken up when the alarm rang.
  • He said, “I have finished my homework.” (Direct) –> He said he had finished his homework. (Indirect)
  • I wish I had been rich.

8. Past Perfect Continous Tense

  1. เหตุการณ์ 1 เกิดขึ้นและจบลงก่อน (Past Perfect Tense) และเหตุการณ์ 2 เกิดทีหลัง (Past Simple Tense) เหมือน Past Perfect แต่แสดงเน้นความต่อเนื่อง
  2. ใช้ในประโยค Indirect Speech
  • We had been waiting for half an hour before she came.
  • He said, “I have been waiting for you 2 hours.” (Direct) –> He said he had been waiting for you 2 hours. (Indirect)

9. Future Simple Tense

  1. การกระทำที่ยังไม่เกิด แต่จะเกิดขึ้นในอนาคต มักใช้กับ Adverb ต่อไปนี้ tomorrow, next month, soon, shortly, in the future, in a short time, this evening
  2. เหตุการณ์ที่จะเกอดขึ้นในอนาคต ใช้ Future Simple, Present Continous, Present Simple, going to
  3. ใช้ to be going to
    • แสดงความตั้งใจหรือตัดสินใจไปแล้ว
    • คาดคะเนว่าเหตุการณ์นั้นกำลังจะเกิดขึ้น
    • แสดงความเชื่อมั่นว่าเหตุการณ์จะเกิดขึ้นแน่นอน
    • ใช้ was/were going to เพื่อแสดงเหตุการณ์ที่ไม่เกิดขึ้นในอดีต เพียงแต่คาดว่าจะเป็นเช่นนั้น
    • ไม่นิยมใช้ going to เพื่อแสดงความหมายที่เป็นอนาคตอย่างแท้จริง
    • ไม่นิยมใช้ going to กับกริยาแสดงการรับรู้ เช่น forget, know, understand, remember หรือ  come, go (เนื่องจากเป็นคำซ้ำซ้อน)
  • He will fly to … tomorrow. / He is flying to … tomorrow. / He flies to .. tomorrow.
  • I am going to write a letter to Jane tonight.
  • I think it is going to rain.
  • My sister is going to have a baby. / She’s gonna have a baby.
  • I was going to meet you yesterday, but I forgot.
  • Today is Monday. Tommorow wil be Tuesday.
  • I will remember your tel no.

10. Future Continous Tense

  1. เพื่อบอกว่า ณ เวลาหนึ่งในอนาคตจะมีเหตุการณ์นั้นเกิดขึ้นหรือดำเนินอยู่
  2. เหตุการณ์ในอนาคตที่ผู้พูดตัดสินใจแล้ว่าจะทำ
  • At this time tomorrow she will be staying in New York.
  • I will be watching television all evening tomorrow.

11. Future Perfect Tense

  1. บอกเมื่อถึงเวลาหนึ่งในอนาคต ว่าเหตุการณ์นั้นจะสิ้นสุดแน่นอน มักมีคำบอกเวลา เช่น by next week, before next year
  2. ถ้าเป็นประโยคอนาคต 2 ประโยคที่เชื่อมกันอยู่ ประโยคที่อยู่หลังคำเชื่อมต้องเป็น Present Simple Tense
  3. ใช้ในการคาดคะเนหรือมีความสงสัย
  4. คาดการณ์เหตุการณ์ล่วงหน้าว่า เมื่อถึงเวลานั้นเหตุการณ์ 1 จบลงไปแล้ว (Future Perfect Tense) และมีเหตุการณ์ 2 เกิดขึ้นทีหลัง (Present Simple Tense)
  • The leaves will have fallen from the trees after 2 months.
  • She will have finished dressing by the time you get there.
  • I suspect that she will have slept by now.
  • He will have eaten the meal when you arrive.
  • By next week I will have worked for 2 months. (ทำครบ 2 เดือน)

12. Future Perfect Continuous Tense

  1. เหมือน Future Perfect แต่แสดงเน้นความต่อเนื่อง เมื่อมาถึงเวลาหนึ่งในอนาคต เหตุการณ์ที่ดำเนิดมาก่อนหน้านั้น จะยังคงดำเนินอยู่และดำเนินต่อไปอีก
  • By next week I will have been working for 2 months. (ทำครบ 2 เดือนก็จะยังทำงานต่อไปอีก)

Print สามเหลี่ยมตัวเลขด้วย For Loop

This post I tried to print numbers like triangle line-by-line. A little bit fun ^o^

        for (i=1;i<=5;i++) {
            for (j=1;j<=i;j++) {
                System.out.print(j+"_");
            }
            System.out.println();
        }

1_
1_2_
1_2_3_
1_2_3_4_
1_2_3_4_5_


       for (i=5;i>=1;i--) {
           for (j=1;j<=i;j++) {
                System.out.print(j+"_");
           }
           System.out.println();
       }

1_2_3_4_5_
1_2_3_4_
1_2_3_
1_2_
1_


       for (i=1;i<=5;i++) {
           for (j=5;j>=i;j--) {
                System.out.print(j+"_");
           }
           System.out.println();
       }

5_4_3_2_1_
5_4_3_2_
5_4_3_
5_4_
5_


       for (i=5;i>=1;i--) {
           for (j=5;j>=i;j--) {
                System.out.print(j+"_");
           }
           System.out.println();
       }

5_
5_4_
5_4_3_
5_4_3_2_
5_4_3_2_1_


        for (i=1;i<=5;i++) {
            for (j=1;j<i;j++) {
                System.out.print("_*");
            }
            for(k=i;k<=5;k++) {
                System.out.print(k+" ");
            }
            System.out.println();
        }

1 2 3 4 5
_*2 3 4 5
_*_*3 4 5
_*_*_*4 5
_*_*_*_*5


        for (i=5;i>=1;i--) {
            for (j=1;j<i;j++) {
                System.out.print("_*");
            }
            for(k=i;k<=5;k++) {
                System.out.print(k+" ");
            }
            System.out.println();
        }

_*_*_*_*5
_*_*_*4 5
_*_*3 4 5
_*2 3 4 5
1 2 3 4 5


        for (i=5;i>=1;i--) {
            for (j=5;j>i;j--) {
                System.out.print("_*");
            }
            for(k=i;k>=1;k--) {
                System.out.print(k+" ");
            }
            System.out.println();
        }

5 4 3 2 1
_*4 3 2 1
_*_*3 2 1
_*_*_*2 1
_*_*_*_*1

Thursday, August 27, 2015

[Essay] Reason to attend colleges or universities

People attend to colleges or universities for a lot of different reasons. I believe that the three most reasons are to prepare for career, to have new experiences, and to increase their knowledge of themselves and the word around them.

Career preparation is become more and more important for young people. For many, this is the primary reason to go to college. They know that the job market is competitive. At college, they can learn new skill for careers with a lot of opportunities. This means careers, such as information technology, are expected to need a large workforce in the coming years.

Also, students go to college and universities to have new experiences. This means having the opportunity to meet people different from those in their hometowns. For most students, going to college is the first time they have been away from home by themselves. In addition, this is the first time they have had to make decisions on their own. Making these decisions increase their knowledge of themselves.

Besides looking for self-knowledge, people also attend a university or college to expand their knowledge in subject they find interesting. For many, this will be their last chance for a long time to learn about something that does not related to their career.

I would recommend people not be so focused on a career. They should go to college to have new experience and learn about themselves and the world they live in.


--------------------

1. Introduction
  • People do it for many reasons.
  • I believe that the 3 most common reasons are...
2. Body
  1. Prepare for a career
    • Competitive job market
    • New skill with opportunity
  2. Have new experiences
    • Meet different people
    • Away from home --> make decisions --> increase knowledge
  3. Expand interesting knowledge
    • Last chance to do
3. Conclusion
  • I would recommend that people not to...
  • They should do to... (3 reasons)

[Essay] Knowledge gained from experience

Experience is the best teacher is an old cliche  but I agree with it. The most importance, and sometimes the hardest lessons we learn in life come from our participation in situations. We cannot learn everything from a book.

Of course, learning from books in the formal educational setting is also valuable. It is in school that we learn the information we need to function in our society. We learn how to speak, write, and understand mathematical equations. This is all information that we need to live in our communities and earn a living.

Nevertheless, I think that the most important lessons can’t be taught. They have to be experienced. No one can teach us how to get along with others or how to have self-respect. As we grow from children into teenagers, no one can teach us how to deal with peer pressure. As we leave adolescence behind and enter adult life, no one can teach us how to fall in love and get married.

This should not stop us from looking for guidelines along the way. Teachers and parents are valuable sources of advice when we are young. As we enter into new stages in our lives, the advice we receive from them is very helpful because they have already had similar experiences. But experiencing our own triumphs and disasters is really the only way to learn how to deal with life.


--------------------

1. Introduction
  • It's true that experience is the best teacher because we cannot learn everything from a book
2. Body
  1. Learning from books (General fact)
    • Learn information to live in society and earning
  2. Learn from experiences (My opinion)
    • No one can teach, you need to learn it by yourself, i.e...
3. Conclusion
  • Learning from books or others is still good but experience is better

พื้นฐาน PHP (1)

บันทึกจากคลิปนี้