Input/Output Statement Thanachat Thanomkulabut. Input Statement  Console.ReadLine()  Return string  Use to get the input from user  Convert string.

Slides:



Advertisements
Similar presentations
Neal Stublen C# Data Types Built-in Types  Integer Types byte, sbyte, short, ushort, int, uint, long, ulong  Floating Point Types.
Advertisements

Constants Variables change, constants don't final = ; final double PI = ; … area = radius * radius * PI; see Liang, p. 32 for full code.
Introduction to C Programming CE Lecture 2 Basics of C programming.
Fundamental data types Horstmann Chapter 4. Constants Variables change, constants don't final = ; final double PI = ; … areaOfCircle = radius *
Thanachat Thanomkulabut
Performing Simple Calculations with C# Svetlin Nakov Telerik Corporation
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
Introduction to Classes and Objects (Through Ch 5) Dr. John P. Abraham Professor UTPA.
Reading and Writing to the Console Svetlin Nakov Telerik Corporation
Data Types, Operators, Expressions, Statements, Console I/O, Loops, Arrays, Methods Svetlin Nakov Telerik Corporation
Introduction to C# Programming ณภัทร สักทอง Application Program Development.
Input & Output: Console
C# B 1 CSC 298 Writing a C# application. C# B 2 A first C# application // Display Hello, world on the screen public class HelloWorld { public static void.
3. Declaring Value-Type Variables
INPUT/OUTPUT STATEMENT ADDITION SLIDES. Console.ReadLine() – Use to get the input (String) from user Convert string to other data type – int.Parse() 
CSCI 3328 Object Oriented Programming in C# Chapter 3: Introduction to Classes and Objects UTPA – Fall
C# Programming: Expressions, conditions, and repetitions Computer and Programming.
Computer Programming 1.  Editor Console Application Notepad Notepad++ Edit plus etc.  Compiler & Interpreter Microsoft.NET Framework  Microsoft visual.
Simple Data Types and Statements. Namespaces namespace MyNamespace { // …. { MyNamespace::func1() using namespace OtherNamespace; Comments: // /* xxxx.
1 Introduction to C# Programming Console applications No visual components Only text output Two types MS-DOS prompt - Used in Windows 95/98/ME Command.
CS_OOP Lecture #2: Computer Hardware/Software; Variables, C# Data Types, and IO.
CH2 – Using Data. Constant Something which cannot be changed Data Type Format and size of a data item Intrinsic Data Types Pg. 47 – Table 2-1 Basic ones.
Iteration (Loop) partI Thanachat Thanomkulabut. Consider the following program! using System; Namespace SimPleExample { class SimPleC { class SimPleC.
Chapter 2: Using Data.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Type Conversions Implicit Conversion Explicit Conversion.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
CECS 121 Test 1. Functions allow you to group program statements under one name C and C++ are case-sensitive so main(), MAIN(), and Main() are all different.
Reading and Writing to the Console Svetlin Nakov Telerik Corporation
Characters. Character Data char data type – Represents one character – char literals indicated with ' '
C# Basic Concept Thanachat Thanomkulabut. Naming Rules  Letters, digits and underscores(_)  First character  letter or _  Up to 63 characters long.
1 Introduction to C# Programming Console applications No visual components Only text output Two types MS-DOS prompt - Used in Windows 95/98/ME Command.
Input & Output Statement
Selection Statement Thanachat Thanomkulabut. Outline 2  Boolean expression  if  if statement  nested if  nested if statement  switch case  switch.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Console Input / Output Reading and Writing to the Console SoftUni Team Technical Trainers Software University
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 – Introduction to C# Programming Outline 3.1 Introduction 3.2 Simple Program: Printing a Line.
C# Programming: Basic Concept Part 2 Computer and Programming (204111)
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Final Review Author: Thanachat Thanomkulabut Edited by Supaporn Erjongmanee Final Review 22 September 2011.
INPUT/OUTPUT STATEMENT ADDITION SLIDES. Console.ReadLine() – Use to get the input (String) from user Convert string to other data type – int.Parse() 
1 nd Semester Module2 C# Basic Concept Thanawin Rakthanmanon Computer Engineering Department Kasetsart University, Bangkok.
1 INPUT/OUTPUT Statements Dept. of Computer Engineering Faculty of Engineering, Kasetsart University Bangkok, Thailand.
Computer Programs CS 1400 Dennis A. Fairclough Version 1.1 CS 1400 Dennis A. Fairclough Version 1.1.
Lecture 2 Review of 1301 and C# Richard Gesick. Common data types int, long, double, float, char, bool, string.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
Input/Output and Mathematical Functions Computer and Programming Department of Computer Engineering Kasetsart University Cliparts are taken from.
1 nd Semester Module6 Review Thanawin Rakthanmanon Create by: Aphirak Jansang Computer Engineering Department Kasetsart.
C# Basic Syntax, Visual Studio, Console Input / Output
C# Basic Syntax, Visual Studio, Console Input / Output
C# — Console Application
Using the Console.
COMP 170 – Introduction to Object Oriented Programming
Thanachat Thanomkulabut
Chapter 2.
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
C++ fundamentals Lecture 1, Chapter 2 – pp /22/2018 Y K Choi.
Variables, Loops, Decision Statements, etc
ניתוח מערכות מידע תכנות ב C#
Introduction to Primitive Data types
C# Programming.
Chapter 3 – Introduction to C# Programming
elementary programming
C# Programming: From Problem Analysis to Program Design
Thanachat Thanomkulabut
Thanachat Thanomkulabut
Iteration (Loop) part II
Introduction to Primitive Data types
Presentation transcript:

Input/Output Statement Thanachat Thanomkulabut

Input Statement  Console.ReadLine()  Return string  Use to get the input from user  Convert string to other data type  int.Parse() Convert string to integer  double.Parse() Convert string to double Example string st; st = Console.ReadLine(); Statement 2

Example: Input Statement Ex1: string myname; myname = Console.ReadLine(); Ex2: int Width; string temp1; temp1 = Console.ReadLine(); Width = int.Parse(temp1); Statement 3

Output Statements  Use the method Write or WriteLine in the Console class (which is in System namespace)  Basic usage:  Advanced usage:  Even more advanced usage: Console.WriteLine(”Size {0}x{1}”, width, height); double salary=12000; Console.WriteLine("My salary is {0:f2}.", salary); Console.WriteLine("Hello");Console.WriteLine(area); Statement 4

Test I 5  Write the program which  Input : Your name  Output : Your name is.

The Math Class Method/ Constant Value returnedExample CallResult PI Value of  Math.PI Max(x,y)Larger of the twoMath.Max(1,2)2 Abs(x)Absolute value of xMath.Abs(-1.3)1.3 Sqrt(x)Square-root of xMath.Sqrt(4.0)2.0 Round(x)Nearest integer to xMath.Round(0.8)1 Pow(x,y)xyxy Math.Pow(3,2)9.0 Log(x)Natural log of xMath.Log(10) Ceiling(x)Smallest integer greater than or equal to x Math.Ceiling(4.1)5 Cos(x)Cosine of x radiansMath.Cos(Math.PI) Math Class 6

Test II 7  Write the program which  Input : Nothing  Output : cos( π /3). | ln(3) |

Outline 8  Data Types  Conversion  Read Statement  Write Statement

Data Types 9 TypeSizeDescriptionRange bool1 byteStore truth valuetrue / false char1 byteStore one charactercharacter code 0 – 255 byte1 byteStore positive integer0 – 255 short2 byteStore integer-32, ,767 int4 byteStore integer-2.1 x x 10 9 long8 byteStore integer-9.2 x x double16 byteStore real number± 5.0x ± 1.7x stringN/AStore sequence of characters N/A

Outline 10  Data Types  Conversion  Read Statement  Write Statement

Convertion Number Convertion Type Convertion ConvertParse 11

Number Conversion  Number conversion can be done with command  = (type)  Example  byte b; int i; long l; double d;  i = (int)b;  l = (long)b+(long)i; 12 Bigger Smaller int byte long byte int long 100%

 Example  byte b; int i; long l; double d;  d = (double)i /10;  b =(byte) l +3; Number Conversion  i =(int)d – 10; 13 int double byte long double int 100% May wrong in some case 100%

Type Conversion 14 Convertion Number Convertion Type Convertion ConvertParse

 i = Convert.ToInt32(c);  c = Convert.ToChar(b);  st = Convert.ToString(i); Convert.To (); byte b=100; int i=100; double d=100.0; char c=‘d’; string st=“1”;  b = Convert.ToByte(i);  d = Convert.ToDouble(st); 15 int byte char int string double charbyte

.Parse();  Can Convert only from string to others  Example  d = double.Parse(st); 16 byte b=100; int i=100; double d=100.0; char c=‘d’; string st=“1”; string double  i = int.Parse(st);  c = char.Parse(st);  b = byte.Parse(st); stringint

Outline 17  Data Types  Conversion  Read Statement  Write Statement

Read Statement Read statement Console. Read() Console. ReadLine()  Console.Read();  Read Acsii code of first character  Console.ReadLine();  Read all character (in form of string)  Use with Convert or Parse commands frequently 18

Console.Read() Example 19 char c; int i; i = Console.Read(); Console.WriteLine(i); c = Convert.ToChar(i); Console.WriteLine(c); c char i int ABCD 65 A A A monitor

Console.ReadLine() Example 20 string st; st = Console.ReadLine(); Console.WriteLine(st); st string ABCD monitor Console.ReadLine() will always get input in string form

Console.ReadLine() Example  Console.ReadLine() will always get input in string type  if you would like other type you must convert it again  Example 21 string st; int i; st = Console.ReadLine(); i = int.Parse(st); string st; int i; i = int.Parse(Console.ReadLine()); OR

Outline 22  Data Types  Conversion  Read Statement  Write Statement

Write Statement Console. Write() Console. WriteLine()  Console.Write();  Show output  Console.WriteLine();  Show output and shift to new line 23

Write Statement Example 24 Console.Write(“Happy”); Console.Write(2009); Happy2009 Output : Console.WriteLine(“Happy”); Console.WriteLine(2009); Happy 2009 Output : string integer

Write Statement  Write() & WriteLine() can use in many form  Console.Write( );  Console.Write(“ ”,,...); 25 Hello 5 Console.Write(“Hello”); int a=5; Console.Write(a); string name = “Mc”; int score=9; Console.Write(“Score of {0} is {1}”,name,score); Score of Mc is 9 {0}{1}

Write Statement Example 26 int a=7, b=2; Console.WriteLine(“a={0} and b={1}”,a,b); Console.WriteLine(“{1}+{0}={2}”,b,a,a+b); a=7 and b= = 9 {0}{1} {0}{1}{2}

27 Write Statement : Example 27

Write Statement : Formatting Output 28 Console.WriteLine(“{0}”,10); 10 Console.WriteLine(“{0:F}”,10); Console.WriteLine(“{0:X}”,10); A Console.WriteLine(“{0:D}”,10); 10 Console.WriteLine(“{0:P}”,10); 1, % Console.WriteLine(“{0:E}”,10); E+001

Write Statement : Formatting Output 29 SymbolMeaningExampleOutput D, dDecimalConsole.WriteLine( “ {0:D} ",10};10 E, eExponentialConsole.WriteLine( “ {0:E} ",10}; E+001 F, fFix PointConsole.WriteLine( “ {0:F} ",10};10.00 X, xHexadecimalConsole.WriteLine( “ {0:X} ",10};A P, pPercentConsole.WriteLine( “ {0:P} ",10};1, %

Special Character Symbols Output \’Single Quote \”Double Quote \\Backslash \nNew line \tHorizontal tab  What should you do if you would like to WriteLine “C:\mydocument” 30 Console.WriteLine(““C:\mydocument””); Console.WriteLine(“\“C:\mydocument\””); Console.WriteLine(“\“C:\\mydocument\””);

Test III 31  Write the program which  Input : 3 number  Output : average of 3 input number

Test IV 32  Write the program which  Input : lenght of radius of circle  Output : Area of circle

Any question?