13
Computer Programming 1

Computer Programming 1. Editor Console Application Notepad Notepad++ Edit plus etc. Compiler & Interpreter Microsoft.NET Framework Microsoft visual

Embed Size (px)

Citation preview

Page 1: Computer Programming 1.  Editor Console Application Notepad Notepad++ Edit plus etc.  Compiler & Interpreter Microsoft.NET Framework  Microsoft visual

Computer Programming 1

Page 2: Computer Programming 1.  Editor Console Application Notepad Notepad++ Edit plus etc.  Compiler & Interpreter Microsoft.NET Framework  Microsoft visual

Editor Console Application• Notepad• Notepad++• Edit plus• etc.

Compiler & Interpreter Microsoft .NET Framework

Microsoft visual studio 2005, 2008,(Full & Express)

Page 3: Computer Programming 1.  Editor Console Application Notepad Notepad++ Edit plus etc.  Compiler & Interpreter Microsoft.NET Framework  Microsoft visual

The contents of your first console app appear as follows:

using ….. // call class to use namespace ….. // define definition of class{

class ….. // name of class{

static void Main() // starting write to program{

// programming area

}}

}

Page 4: Computer Programming 1.  Editor Console Application Notepad Notepad++ Edit plus etc.  Compiler & Interpreter Microsoft.NET Framework  Microsoft visual

Along the left edge of the code window, you see several small plus (+) and minus (–) signs in boxes. Click the + sign next to

using.... This expands a code region, a handy Visual Studio feature that keeps down the clutter. Here are the directives

when you expand the region in the default console app:

• using System;• using System.Collections.Generic;• using System.Text;

using System;

Contain every class ex. Console to use input & output to display on monitor

Page 5: Computer Programming 1.  Editor Console Application Notepad Notepad++ Edit plus etc.  Compiler & Interpreter Microsoft.NET Framework  Microsoft visual

Edit the test.cs template file until it appears as follows:

using System;namespace ConsoleAppTemplate{

public class Program{

static void Main(string[] args){

Console.WriteLine(“Hello World !”);Console.WriteLine(“I am a bird !! in the sky”);Console.Read();

}}

}

Page 6: Computer Programming 1.  Editor Console Application Notepad Notepad++ Edit plus etc.  Compiler & Interpreter Microsoft.NET Framework  Microsoft visual

Console.WriteLine• Display on monitor with add new line number on new

cursor Syntax: Console.WriteLine(parameter); Ex. Console.WriteLine(“Hello World!”);

Console.Write• Display on monitor

Syntax: Console.Write(parameter); Ex. Console.Write(“Hello World!”);

Page 7: Computer Programming 1.  Editor Console Application Notepad Notepad++ Edit plus etc.  Compiler & Interpreter Microsoft.NET Framework  Microsoft visual

Ex1. Console.WriteLine(“Hello World!”);

Ex2. Console.Write (“Hello”); Console.Write (“ ”); Console.WriteLine (“World!”);

This example are same as the result program

Escape character Mean\n Newline\t Horizontal tab\” Double quotation mask\’ Single quotation mask\\ Backspace\r Carriage return\a Alert

Page 8: Computer Programming 1.  Editor Console Application Notepad Notepad++ Edit plus etc.  Compiler & Interpreter Microsoft.NET Framework  Microsoft visual

using System;namespace ESCConsoleAppTemplate{

public class Program{

static void Main(){

Console.WriteLine(“This line \tcontain two \ttabs”);

Console.WriteLine(“This \ncontain new line”);Console.WriteLine(“This sound alert \a\a\a”);

Console.WriteLine(“This \’ 555 \’”);Console.Read(); // cursor waiting to any

key}

}}

Page 9: Computer Programming 1.  Editor Console Application Notepad Notepad++ Edit plus etc.  Compiler & Interpreter Microsoft.NET Framework  Microsoft visual

Ex 3. Console.WriteLine(“Hello” + “World!”);

Ex 4. String s = “Rujipan”Console.WriteLine(“My name is” + s + “and my Age is”

+ 33);

PlaceHolderSyntax:• Console.WriteLine(“Statement {0} {1} {2} … {n}”,x0,x1,

…,xn)• {0} … {n} position to display• x0 … xn value to {0}…{n}

Ex 3. Console.WriteLine(“My name is {0} and Age is {1}”,”Boon”,45);

Page 10: Computer Programming 1.  Editor Console Application Notepad Notepad++ Edit plus etc.  Compiler & Interpreter Microsoft.NET Framework  Microsoft visual
Page 11: Computer Programming 1.  Editor Console Application Notepad Notepad++ Edit plus etc.  Compiler & Interpreter Microsoft.NET Framework  Microsoft visual

using System;namespace DisplayFormat1{

public class Program{

static void Main(){ Console.WriteLine(“A={0} B={1}”,123,456);

Console.WriteLine(“123456789”); // 9 number display 1234XXXXX X=space Console.WriteLine(“{0,9}”,1234);

Console.WriteLine(“123456789”); // 9 number left align XXXXX1234 X=space Console.WriteLine(“{0,-9},1234”); Console.Read();}

}}

Page 12: Computer Programming 1.  Editor Console Application Notepad Notepad++ Edit plus etc.  Compiler & Interpreter Microsoft.NET Framework  Microsoft visual

using System;namespace DisplayFormat2{

public class Program{

static void Main(){ Console.WriteLine(“{0:C}”,123456789); Console.WriteLine(“{0:E}”,123456789); Console.WriteLine(“{0:F}”,123456789); // floating point 2 position Console.WriteLine(“{0:F2}”,1234.12345); Console.WriteLine(“{0:G}”,123456789); Console.WriteLine(“{0:N}”,123456789); Console.WriteLine(“{0:X}”,123456789); Console.WriteLine(“{0,20:G}”,123456789); Console.Read();}

}}

Page 13: Computer Programming 1.  Editor Console Application Notepad Notepad++ Edit plus etc.  Compiler & Interpreter Microsoft.NET Framework  Microsoft visual

using System;namespace ConsoleAppTemplate{

public class Program{

static void Main(string[] args){

Console.WriteLine(“Enter your name, please:”);

string sName = Console.ReadLine();Console.WriteLine(“Hello, “ + sName);Console.WriteLine(“Press Enter to

terminate...”);Console.Read();

}}

}