computer programming 1. editor console application notepad notepad++ edit plus etc. compiler &...

Post on 31-Dec-2015

230 Views

Category:

Documents

5 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Computer Programming 1

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

Compiler & Interpreter Microsoft .NET Framework

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

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

}}

}

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

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();

}}

}

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!”);

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

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}

}}

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);

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();}

}}

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();}

}}

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();

}}

}

top related