Lab 10: Structs and Enumeration
|
|
- Florence Wheeler
- 5 years ago
- Views:
Transcription
1 Lab 10: Structs and Enumeration There is one more way to create your own value types in C#. You can use the struct keyword. A struct (short for structure) can have its own fields, methods, and constructors just like a class (and unlike an enumeration), but it is a value type and not a reference type. Declaring Struct Types To declare your own struct value type, you use the struct keyword followed by the name of the type, followed by the body of the struct between an opening and closing brace. For example, here is a struct called Time that contains three public int fields called hours, minutes, and seconds: struct Time public int hours, minutes, seconds; However, making the fields of a struct public is a violation of encapsulation and in most cases is not advisable. There is no way to ensure the values of public fields are valid. For example, anyone could set the value of minutes or seconds to greater than 60. A better idea is to make the fields private and provide your struct with constructors and methods, as shown in this example: struct Time public Time(int hh, int mm, int ss) hours = hh % 24; minutes = mm % 60; seconds = ss % 60; public int Hours() return hours; private int hours, minutes, seconds; Remarks It is an error to declare a default (parameterless) constructor for a struct. A default constructor is always provided to initialize the struct members to their default values. It is an error to initialize an instance field in a struct. When you create a struct object using the new operator, it gets created and the appropriate constructor is called. Unlike classes, structs can be instantiated without using the new operator. If you do not use new, the fields will remain unassigned and the object cannot be used until all of the fields are initialized. Now let s proceed to the exercises by typing the following program in exercise 1 Computer & Programming: Structs and Enumerations 1/13 Powered by MIKE TM
2 1:// struct declaration and initialization 2:using System; 3:namespace ex10_1 4: 5: public struct Point 6: 7: public int x, y; 8: 9: public Point(int p1, int p2) 10: 11: x = p1; 12: y = p2; 13: 14: 15: class MainClass 16: 17: public static void Main() 18: 19: // Initialize: 20: Point mypoint = new Point(); 21: Point yourpoint = new Point(10,10); 22: 23: // Display results: 24: Console.Write("My Point: "); 25: Console.WriteLine("x = 0, y = 1", mypoint.x, mypoint.y); 26: Console.Write("Your Point: "); 27: Console.WriteLine("x = 0, y = 1", yourpoint.x, 28:yourPoint.y); 29: 30: 31: 1.1 Run the above program, write your output below, and explain how the program works: My Point: x=0, y=0 Your Point: x=10, y=10 เน องจากเราไม ได ก าหนดค าเร มต นให mypoint ด งน นค า mypoint.x, mypoint.y จ งเป น 0 แต yourpoint เราก าหนดค าให ด วย constructor Point(10,10) ด งน นค า yourpoint.x, yourpoint.y จ งม ค าเป น If the line #9 is REPLACED by public Point() and line #11 is INSERTED with int p1, int p2; Can the program still compile? If not, explain why. โปรแกรมจะคอมไพล ไม ได เน องจากม ข อห ามในการสร าง constructor ท ไม ม parameter เลย (default constructor) เช น Point() เป นต น เน องจาก constructor ประเภทน จะถ กก าหนดให สร างค าต งต นเป น default ของ สมาช กใน struct อย แล ว Computer & Programming: Structs and Enumerations 2/13 Powered by MIKE TM
3 1.3. Change both lines (9 and 11) back to their original conditions as they were in question 1. Then comment out the line #12 (to look like // y = p2;) and try compiling the program. Can the program still compile? If not, explain why. โปรแกรมจะคอมไพล ไม ได เน องจากการสร าง constructor ( method ท ม ช อเด ยวก บช อ struct ) น น จะต อง สามารถก าหนดค าเร มต นให ก บสมาช กท กต วของ struct น นได ในกรณ น constructor ไม สามารถก าหนดค าต งต นให ก บ สมาช ก y ได จ งเก ด error ข น 1.4. Change the line #12 back to its original condition as it was in question 1. Then change the line #7 to public int x=0, y; Try compiling the program. Can the program still compile? If not, explain why. โปรแกรมจะคอมไพล ไม ได เน องจากในการสร าง struct เราไม สามารถก าหนดค าเร มต นให ก บแต ละฟ ลด (เช น x หร อ y) ได โปรแกรมจะยอมให ก าหนดค าเร มต นผ านทาง constructor หร อการก าหนดค าให จากภายนอกเท าน น ด งน นเม อ เราพยายามท จะก าหนดค าต งต นให x จ งเก ด error ข น Computer & Programming: Structs and Enumerations 3/13 Powered by MIKE TM
4 1.5 Write a program to store contact information of your friends by using struct as a method to store each of your friend s contact. Your program will accept n number of contacts. Each Contact struct contains first name, last name, address, phone number, address, and date of birth (DOB) fields. All of the fields, except for the DOB, are of string type. The DOB field is also a struct type consisting of three integer fields: day, month, and year. An example of the ouput of the program is shown below; The bold-faced texts are what you type in. Please enter the number of contacts: 2 Please enter the first name: monchai Please enter the last name: sopitkamon Please enter an address: fengmcs@ku.ac.th Please enter the day of birth (1-31): 01 Please enter the month of birth (1-12): 01 Please enter the year of birth: 1970 Please enter the first name: somchai Please enter the last name: ratanachote Please enter an address: fengscr@ku.ac.th Please enter the day of birth (1-31): 18 Please enter the month of birth (1-12): 11 Please enter the year of birth: 1960 monchai sopitkamon 50 Phaholyothin Rd x 1432 fengmcs@ku.ac.th 1/1/1970 somchai ratanachote 50 Phayothin Rd x 1111 fengscr@ku.ac.th 18/11/1960 Computer & Programming: Structs and Enumerations 4/13 Powered by MIKE TM
5 Fill in the blanks of the following part of code to make the program work. using System; namespace ex10_15 public struct DOB // Declares Date of Birth (DOB) struct public int day; // declares day field public int month; // declares month field public int year; // declare year field public DOB(int d,int m, int y) // Constructor for DOB struct day=d; // day assignment month=m; // month assignment year=y; // year assignment public struct Contact // Declare Contact struct public string firstname; // declares first name field public string lastname; // declares last name field public string ; // declares field public DOB dateofbirth; // declares DOB field class MainClass public static void entercontact(ref Contact cont) // This method is used to fill in all fields of Contact struct Console.Write("Please enter the first name: "); cont.firstname=console.readline(); Console.Write("Please enter the last name: "); cont.lastname=console.readline(); Console.Write("Please enter an address: "); cont. =console.readline(); Console.Write("Please enter the day of birth (1-31): "); int dd=int.parse(console.readline()); Console.Write("Please enter the month of birth (1-12): "); int mm=int.parse(console.readline()); Console.Write("Please enter the year of birth: "); int yy=int.parse(console.readline()); cont.dateofbirth = new DOB(dd,mm,yy); // Instantiate DOB struct public static void showcontact(contact cont) // This method writes out all fields of a Contact struct Console.Write("0 ",cont.firstname);// writes first name Console.WriteLine(cont.lastname); // writes last name Console.WriteLine(cont. ); // writes // writes DOB in DD/MM/YY format Console.WriteLine("0/1/2", cont.dateofbirth.day,cont.dateofbirth.month,cont.dateofbirth.year); Computer & Programming: Structs and Enumerations 5/13 Powered by MIKE TM
6 public static void Main() Console.Write("Please enter the number of contacts: "); int n = int.parse(console.readline()); // creates and instantiates a one-dimension array // of Contact struct with n elements Contact[] conts = new Contact[n]; for (int i=0; i<n; i++) // Fills in all fields of each element of Contact struct Console.WriteLine(" ", i); entercontact(ref conts[i]); Console.WriteLine(); for (int i=0; i<n; i++) //Writes out all fields of each element of Contact struct Console.WriteLine(" ", i); showcontact(conts[i]); Console.WriteLine(""); // ends Main() // ends class // ends namespace 2 Enumerations An enum type is a distinct value type (Section 4.1) that declares a set of named constants. The example enum Color Red, Green, Blue declares an enum type named Color with members Red, Green, and Blue. Enum declarations An enum declaration declares a new enum type. An enum declaration begins with the keyword enum, and defines the name, accessibility, underlying type, and members of the enum. enum-declaration: attributesopt enum-modifiersopt enum identifier enum-baseopt enum-body ;opt enum-base: ; integral-type enum-body: enum-member-declarationsopt enum-member-declarations, Each enum type has a corresponding integral type called the underlying type of the enum type. This underlying type must be able to represent all the enumerator values defined in the enumeration. An enum declaration may explicitly declare an underlying type of byte, sbyte, short, ushort, int, uint, long or ulong. Note that char cannot be used as an underlying type. An enum declaration that does not explicitly declare an underlying type has an underlying type of int. The example Computer & Programming: Structs and Enumerations 6/13 Powered by MIKE TM
7 enum Color: long Red, Green, Blue declares an enum with an underlying type of long. A developer might choose to use an underlying type of long, as in the example, to enable the use of values that are in the range of long but not in the range of int, or to preserve this option for the future. 2.1 Create an enumeration type named Month of integral type whose members are months of year (i.e., Jan, Feb,, Dec). Write your code below. enum Month: int Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec Enum members The body of an enum type declaration defines zero or more enum members, which are the named constants of the enum type. No two enum members can have the same name. enum-member-declarations: enum-member-declaration enum-member-declarations, enum-member-declaration enum-member-declaration: attributesopt identifier attributesopt identifier = constant-expression Each enum member has an associated constant value. The type of this value is the underlying type for the containing enum. The constant value for each enum member must be in the range of the underlying type for the enum. Multiple enum members may share the same associated value. The example enum Color Red, Green, Blue, Max = Blue shows an enum in which two enum members Blue and Max have the same associated value. The associated value of an enum member is assigned either implicitly or explicitly. If the declaration of the enum member has a constant-expression initializer, the value of that constant expression, implicitly converted to the underlying type of the enum, is the associated value of the enum member. If the declaration of the enum member has no initializer, its associated value is set implicitly, as follows: * If the enum member is the first enum member declared in the enum type, its associated value is zero. * Otherwise, the associated value of the enum member is obtained by increasing the associated value of the textually preceding enum member by one. This increased value must be Computer & Programming: Structs and Enumerations 7/13 Powered by MIKE TM
8 within the range of values that can be represented by the underlying type; otherwise, a compiletime error occurs. The example using System; enum Color Red, Green = 10, Blue class Test static void Main() Console.WriteLine(StringFromColor(Color.Red)); Console.WriteLine(StringFromColor(Color.Green)); Console.WriteLine(StringFromColor(Color.Blue)); static string StringFromColor(Color c) switch (c) case Color.Red: return String.Format("Red = 0", (int) c); case Color.Green: return String.Format("Green = 0", (int) c); case Color.Blue: return String.Format("Blue = 0", (int) c); default: return "Invalid color"; prints out the enum member names and their associated values. The output is: Red = 0 Green = 10 Blue = Apply the enumeration type Month from exercise 2.1 to your final code of exercise 1.5, so that the output of the date of birth (DOB) in exercise 1.5 shows a month of year (Jan, Feb, etc.), instead of an integer (1, 2, and etc.). For example, with the same set of input data as in exercise 1.5, the output of the showcontact() method would produce the result as follows: monchai sopitkamon fengmcs@ku.ac.th 1/Jan/1970 somchai ratanachote fengscr@ku.ac.th 18/Nov/1960 Computer & Programming: Structs and Enumerations 8/13 Powered by MIKE TM
9 Write your updated codes in the DOB struct and entercontact() method in the provided blanks below. public enum Month: int Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec public struct DOB // Declares Date of Birth (DOB) struct public int day; // declares day field public Month month; // declares month field public int year; // declare year field public DOB(int d,month m, int y) // Constructor for DOB struct day=d; // day assignment month=m; // month assignment year=y; // year assignment public struct Contact // Declare Contact struct public string firstname; // declares first name field public string lastname; // declares last name field public string ; // declares field public DOB dob; // declares DOB field class MainClass public static void entercontact(ref Contact cont) // This method is used to fill in all fields of Contact struct Console.Write("Please enter the first name: "); cont.firstname=console.readline(); Console.Write("Please enter the last name: "); cont.lastname=console.readline(); Console.Write("Please enter an address: "); cont. =console.readline(); Console.Write("Please enter the day of birth (1-31): "); int dd=int.parse(console.readline()); Console.Write("Please enter the month of birth (1-12): "); int mm=int.parse(console.readline()); Console.Write("Please enter the year of birth: "); int yy=int.parse(console.readline()); cont.dob = new DOB(dd,(Month) mm-1,yy); // Instantiate DOB struct Enum values and operations Each enum type defines a distinct type; an explicit enumeration conversion (Section 6.2.2) is required to convert between an enum type and an integral type, or between two enum types. The set of values that an enum type can take on is not limited by its enum members. In particular, any value of the underlying type of an enum can be cast to the enum type, and is a distinct valid value of that enum type. Enum members have the type of their containing enum type (except within other enum member initializers: see Section 14.3). The value of an enum member declared in enum type E with associated value v is (E)v. The following operators can be used on values of enum types: ==,!=, <, >, <=, >=, +, -, ^, &,, ~, ++, --, sizeof. Computer & Programming: Structs and Enumerations 9/13 Powered by MIKE TM
10 2.3 Using the result of exercise 2.2, together with codes from exercises 1.5 and 2.2, add a method called IsSameMonth() and add extra codes to the end of the Main() method of exercise 1.5, to check to see if two people from Contact i and Contact j (i j and i and j are both valid Contact numbers), i) are born in the same month, ii) Contact i is younger than Contact j in term of month, and iii) Contact i is older than Contact j in term of month. The IsSameMonth() method takes two different Contacts as its input, performs the month comparison, writes out the comparison result, and returns nothing back to Main(). An example of the output showing all three possible cases as shown below (The bold-faced texts represent the user s input): Please enter the number of contacts: 2 Please enter the first name: monchai Please enter the last name: sopitkamon Please enter an address: fengmcs@ku.ac.th Please enter the day of birth (1-31): 01 Please enter the month of birth (1-12): 01 Please enter the year of birth: 1970 Please enter the first name: somchai Please enter the last name: ratanachote Please enter an address: fengscr@ku.ac.th Please enter the day of birth (1-31): 18 Please enter the month of birth (1-12): 11 Please enter the year of birth: 1960 monchai sopitkamon fengmcs@ku.ac.th 1/Jan/1970 somchai ratanachote fengscr@ku.ac.th 18/Nov/1960 Enter contact number of the first person to compare months: 0 Enter contact number of the second person to compare months: 1 monchai is older than somchai in term of month Please enter the number of contacts: 2 Please enter the first name: monchai Please enter the last name: sopitkamon Please enter an address: fengmcs@ku.ac.th Please enter the day of birth (1-31): 01 Please enter the month of birth (1-12): 06 Please enter the year of birth: 1970 Please enter the first name: somchai Please enter the last name: ratanachote Please enter an address: fengscr@ku.ac.th Please enter the day of birth (1-31): 10 Please enter the month of birth (1-12): 06 Please enter the year of birth: 1960 Computer & Programming: Structs and Enumerations 10/13 Powered by MIKE TM
11 monchai sopitkamon 1/Jun/1970 somchai ratanachote 10/Jun/1960 Enter contact number of the first person to compare months: 0 Enter contact number of the second person to compare months: 1 monchai was born on the same month as somchai Please enter the number of contacts: 2 Please enter the first name: monchai Please enter the last name: sopitkamon Please enter an address: fengmcs@ku.ac.th Please enter the day of birth (1-31): 01 Please enter the month of birth (1-12): 12 Please enter the year of birth: 1970 Please enter the first name: somchai Please enter the last name: ratanachote Please enter an address: fengscr@ku.ac.th Please enter the day of birth (1-31): 10 Please enter the month of birth (1-12): 6 Please enter the year of birth: 1960 monchai sopitkamon fengmcs@ku.ac.th 1/Dec/1970 somchai ratanachote fengscr@ku.ac.th 10/Jun/1960 Enter contact number of the first person to compare months: 0 Enter contact number of the second person to compare months: 1 monchai is younger than somchai in term of month Computer & Programming: Structs and Enumerations 11/13 Powered by MIKE TM
12 Fill in the provided blanks below. using System; namespace ex10_15 public enum Month: int Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec public struct DOB // Declares Date of Birth (DOB) struct public int day; public Month month; public int year; // declares day field // declares month field // declare year field public DOB(int d,month m, int y) // Constructor for DOB struct day=d; // day assignment month=m; // month assignment year=y; // year assignment public struct Contact // Declare Contact struct public string firstname;// declares first name field public string lastname; // declares last name field public string ; // declares field public DOB dob; // declares DOB field class MainClass public static void entercontact(ref Contact cont) // This method is used to fill in all fields of Contact struct Console.Write("Please enter the first name: "); cont.firstname=console.readline(); Console.Write("Please enter the last name: "); cont.lastname=console.readline(); Console.Write("Please enter an address: "); cont. =console.readline(); Console.Write("Please enter the day of birth (1-31): "); int dd=int.parse(console.readline()); Console.Write("Please enter the month of birth (1-12): "); int mm=int.parse(console.readline()); Console.Write("Please enter the year of birth: "); int yy=int.parse(console.readline()); cont.dob = new DOB(dd,(Month) mm-1,yy); // Instantiate DOB struct public static void showcontact(contact cont) // This method writes out all fields of a Contact struct Console.Write("0 ",cont.firstname);// writes first name Console.WriteLine(cont.lastname); // writes last name Console.WriteLine(cont. ); // writes // writes DOB in DD/MM/YY format Console.WriteLine("0/1/2", cont.dob.day,(month) cont.dob.month,cont.dob.year); Computer & Programming: Structs and Enumerations 12/13 Powered by MIKE TM
13 public static void IsSameMonth(Contact cont1, Contact cont2) if(cont1.dob.month==cont2.dob.month) Console.WriteLine("0 was born on the same month as 1", cont1.firstname,cont2.firstname); else if(cont1.dob.month<cont2.dob.month) Console.WriteLine("0 is older than 1 in term of month", cont1.firstname,cont2.firstname); else if(cont1.dob.month>cont2.dob.month) Console.WriteLine("0 is younger than 1 in term of month", cont1.firstname,cont2.firstname); public static void Main() Console.Write("Please enter the number of contacts: "); int n = int.parse(console.readline()); // creates and instantiates a one-dimension array of Contact struct // with n elements Contact[] conts = new Contact[n]; for (int i=0; i<n; i++) // Fills in all fields of each element of Contact struct Console.WriteLine(" ", i); entercontact(ref conts[i]); Console.WriteLine(); for (int i=0; i<n; i++) //Writes out all fields of each element of Contact struct Console.WriteLine(" ", i); showcontact(conts[i]); Console.WriteLine(""); Console.Write("Enter contact number of the first person to compare months: "); int a = int.parse(console.readline()); Console.Write("Enter contact number of the second person to compare months: "); int b = int.parse(console.readline()); IsSameMonth(conts[a],conts[b]); // ends Main() // ends class // ends namespace Computer & Programming: Structs and Enumerations 13/13 Powered by MIKE TM
Chapter 3 Outline. Relational Model Concepts. The Relational Data Model and Relational Database Constraints Database System 1
Chapter 3 Outline 204321 - Database System 1 Chapter 3 The Relational Data Model and Relational Database Constraints The Relational Data Model and Relational Database Constraints Relational Model Constraints
More informationC Programming
204216 -- C Programming Chapter 5 Repetition Adapted/Assembled for 204216 by Areerat Trongratsameethong Objectives Basic Loop Structures The while Statement Computing Sums and Averages Using a while Loop
More informationC Programming
204216 -- C Programming Chapter 9 Character Strings Adapted/Assembled for 204216 by Areerat Trongratsameethong A First Book of ANSI C, Fourth Edition Objectives String Fundamentals Library Functions Input
More informationCPE 426 Computer Networks. Chapter 5: Text Chapter 23: Support Protocols
CPE 426 Computer Networks Chapter 5: Text Chapter 23: Support Protocols 1 TOPICS สร ปเร อง IP Address Subnetting Chapter 23: Supporting Protocols ARP: 23.1-23.7 ใช ส าหร บหา HW Address(MAC Address) ICMP:
More informationChapter 9: Virtual-Memory Management Dr. Varin Chouvatut. Operating System Concepts 8 th Edition,
Chapter 9: Virtual-Memory Management Dr. Varin Chouvatut, Silberschatz, Galvin and Gagne 2010 Chapter 9: Virtual-Memory Management Background Demand Paging Copy-on-Write Page Replacement Allocation of
More informationIntroduction to C# Applications
1 2 3 Introduction to C# Applications OBJECTIVES To write simple C# applications To write statements that input and output data to the screen. To declare and use data of various types. To write decision-making
More informationว ธ การต ดต ง Symantec Endpoint Protection
ว ธ การต ดต ง Symantec Endpoint Protection 1. Download File ส าหร บการต ดต ง 2. Install Symantec Endpoint Protection Manager 3. Install License 4. Install Symantec Endpoint Protection Client to Server
More informationISI Web of Science. SciFinder Scholar. PubMed ส บค นจากฐานข อม ล
2.3.3 Search Chem. Info. in Journal ส บค นจากฐานข อม ล - ฐานข อม ลท รวบรวมข อม ลของ journal จากหลาย ๆ แหล ง ISI http://portal.isiknowledge.com/portal.cgi/ SciFinder ต องต ดต งโปรแกรมพ เศษ และสม ครสมาช
More informationI/O. Output. Input. Input ของจาวา จะเป น stream จะอ าน stream ใช คลาส Scanner. standard input. standard output. standard err. command line file.
I/O and Exceptions I/O Input standard input keyboard (System.in) command line file Output standard output Screen (System.out) standard err file System.err Input ของจาวา จะเป น stream จะอ าน stream ใช คลาส
More informationเคร องว ดระยะด วยแสงเลเซอร แบบม อถ อ ย ห อ Leica DISTO ร น D110 (Bluetooth Smart) ประเทศสว ตเซอร แลนด
เคร องว ดระยะด วยแสงเลเซอร แบบม อถ อ ย ห อ Leica DISTO ร น D110 (Bluetooth Smart) ประเทศสว ตเซอร แลนด 1. ค ณล กษณะ 1.1 เป นเคร องว ดระยะทางด วยแสงเลเซอร แบบม อถ อ 1.2 ความถ กต องในการว ดระยะทางไม เก น
More informationกล ม API ท ใช. Programming Graphical User Interface (GUI) Containers and Components 22/05/60
กล ม API ท ใช Programming Graphical User Interface (GUI) AWT (Abstract Windowing Toolkit) และ Swing. AWT ม ต งต งแต JDK 1.0. ส วนมากจะเล กใช และแทนท โดยr Swing components. Swing API ปร บปร งความสามารถเพ
More informationINPUT Input point Measuring cycle Input type Disconnection detection Input filter
2 = TEMPERATURE CONTROLLER PAPERLESS RECORDER หน าจอเป น Touch Sceen 7-Inch LCD เก บข อม ลผ าน SD Card และ USB Memory ร บ Input เป น TC/RTD/DC Voltage/DC Current ร บ Input 6 Channel ช วงเวลาในการอ านส
More informationDigiPen Institute of Technology
DigiPen Institute of Technology Presents Session Two: Overview of C# Programming DigiPen Institute of Technology 5001 150th Ave NE, Redmond, WA 98052 Phone: (425) 558-0299 www.digipen.edu 2005 DigiPen
More informationSEARCH STRATEGIES KANOKWATT SHIANGJEN COMPUTER SCIENCE SCHOOL OF INFORMATION AND COMMUNICATION TECHNOLOGY UNIVERSITY OF PHAYAO
SEARCH STRATEGIES KANKWATT SHIANGJEN CMPUTER SCIENCE SCHL F INFRMATIN AND CMMUNICATIN TECHNLGY UNIVERSITY F PHAYA Search Strategies Uninformed Search Strategies (Blind Search): เป นกลย ทธ การ ค นหาเหม
More informationJava Classes & Primitive Types
Java Classes & Primitive Types Rui Moreira Classes Ponto (from figgeom) x : int = 0 y : int = 0 n Attributes q Characteristics/properties of classes q Primitive types (e.g., char, byte, int, float, etc.)
More informationA First Book of ANSI C Fourth Edition. Chapter 9 Character Strings
A First Book of ANSI C Fourth Edition Chapter 9 Character Strings Objectives String Fundamentals Library Functions Input Data Validation Formatting Strings (Optional) Case Study: Character and Word Counting
More informationC# Fundamentals. Hans-Wolfgang Loidl School of Mathematical and Computer Sciences, Heriot-Watt University, Edinburgh
C# Fundamentals Hans-Wolfgang Loidl School of Mathematical and Computer Sciences, Heriot-Watt University, Edinburgh Semester 1 2018/19 H-W. Loidl (Heriot-Watt Univ) F20SC/F21SC 2018/19
More informationC++ Important Questions with Answers
1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children
More informationTokens, Expressions and Control Structures
3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type
More informationIS311. Data Structures and Java Collections
IS311 Data Structures and Java Collections 1 Algorithms and Data Structures Algorithm Sequence of steps used to solve a problem Operates on collection of data Each element of collection -> data structure
More informationC# Types. Industrial Programming. Value Types. Signed and Unsigned. Lecture 3: C# Fundamentals
C# Types Industrial Programming Lecture 3: C# Fundamentals Industrial Programming 1 Industrial Programming 2 Value Types Memory location contains the data. Integers: Signed: sbyte, int, short, long Unsigned:
More informationIntroduction To C#.NET
Introduction To C#.NET Microsoft.Net was formerly known as Next Generation Windows Services(NGWS).It is a completely new platform for developing the next generation of windows/web applications. However
More informationIndustrial Programming
Industrial Programming Lecture 3: C# Fundamentals Industrial Programming 1 C# Types Industrial Programming 2 Value Types Memory location contains the data. Integers: Signed: sbyte, int, short, long Unsigned:
More informationLecture 6 Register Transfer Methodology. Pinit Kumhom
Lecture 6 Register Transfer Methodology Pinit Kumhom VLSI Laboratory Dept. of Electronic and Telecommunication Engineering (KMUTT) Faculty of Engineering King Mongkut s University of Technology Thonburi
More informationChapter 4. Introducing Oracle Database XE 11g R2. Oracle Database XE is a great starter database for:
Oracle Database XE is a great starter database for: Chapter 4 Introducing Oracle Database XE 11g R2 Developers working on PHP, Java,.NET, XML, and Open Source applications DBAs who need a free, starter
More informationIS311 Programming Concepts 2/59. AVA Exception Handling Jการจ ดการส งผ ดปรกต
1 IS311 Programming Concepts 2/59 AVA Exception Handling Jการจ ดการส งผ ดปรกต 2 Introduction Users have high expectations for the code we produce. Users will use our programs in unexpected ways. Due to
More informationJava Classes & Primitive Types
Java Classes & Primitive Types Rui Moreira Classes Ponto (from figgeom) x : int = 0 y : int = 0 n Attributes q Characteristics/properties of classes q Primitive types (e.g., char, byte, int, float, etc.)
More informationTypes, Operators and Expressions
Types, Operators and Expressions CSE 2031 Fall 2011 9/11/2011 5:24 PM 1 Variable Names (2.1) Combinations of letters, numbers, and underscore character ( _ ) that do not start with a number; are not a
More informationChapter 2: Using Data
Chapter 2: Using Data Declaring Variables Constant Cannot be changed after a program is compiled Variable A named location in computer memory that can hold different values at different points in time
More informationChapter 11 Object-Oriented Design Exception and binary I/O can be covered after Chapter 9
Chapter 6 Arrays Chapter 8 Strings Chapter 7 Objects and Classes Chapter 9 Inheritance and Polymorphism GUI can be covered after 10.2, Abstract Classes Chapter 12 GUI Basics 10.2, Abstract Classes Chapter
More informationTypes, Operators and Expressions
Types, Operators and Expressions EECS 2031 18 September 2017 1 Variable Names (2.1) l Combinations of letters, numbers, and underscore character ( _ ) that do not start with a number; are not a keyword.
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationCS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation
CS113: Lecture 3 Topics: Variables Data types Arithmetic and Bitwise Operators Order of Evaluation 1 Variables Names of variables: Composed of letters, digits, and the underscore ( ) character. (NO spaces;
More informationจาวา : Threads สมชาย ประส ทธ จ ตระก ล
จาวา : Threads สมชาย ประส ทธ จ ตระก ล Threads A thread == A virtual CPU Threads == Virtual CPUs sharing the same memory space running virtually at the same time Java supports multithreading Typically used
More informationHigh Performance Computing
High Performance Computing MPI and C-Language Seminars 2009 Photo Credit: NOAA (IBM Hardware) High Performance Computing - Seminar Plan Seminar Plan for Weeks 1-5 Week 1 - Introduction, Data Types, Control
More informationJavaScript Framework: AngularJS
บทท 8 JavaScript Framework: AngularJS ว ชา เทคโนโลย เว บ (รห สว ชา 04-06-204) ว ตถ ประสงค การเร ยนร เพ อให ผ เร ยนม ความร ความเข าใจเก ยวก บ JavaScript Framework: AngularJS เพ อให ผ เร ยนสามารถนาเสนอการดาเน
More informationChapter 8: Memory- Management Strategies Dr. Varin Chouvatut
Part I: Overview Part II: Process Management Part III : Storage Management Chapter 8: Memory- Management Strategies Dr. Varin Chouvatut, Silberschatz, Galvin and Gagne 2010 Chapter 8: Memory Management
More informationISRA University Faculty of IT. Textbook BARBARA DOYLE C# Programming: From Problem Analysis to Program Design 4 th Edition
4 Programming Fundamentals 605116 ISRA University Faculty of IT Textbook BARBARA DOYLE C# Programming: From Problem Analysis to Program Design 4 th Edition Prepared by IT Faculty members 1 5 Console Input
More informationWhy Use Generics? Generic types Generic methods Bounded type parameters Generics, Inheritance, and Subtypes Wildcard types
Why Use Generics? Generic types Generic methods Bounded type parameters Generics, Inheritance, and Subtypes Wildcard types generics enable types (classes and interfaces) to be parameters when defining
More informationการสร างเว บเซอร ว สโดยใช Microsoft.NET
การสร างเว บเซอร ว สโดยใช Microsoft.NET อ.ดร. กานดา ร ณนะพงศา ภาคว ชาว ศวกรรมคอมพ วเตอร คณะว ศวกรรมคอมพ วเตอร มหาว ทยาล ยขอนแก น บทน า.NET เป นเคร องม อท เราสามารถน ามาใช ในการสร างและเร ยกเว บเซอร ว สได
More informationร จ กก บ MySQL Cluster
ร จ กก บ MySQL Cluster ก ตต ร กษ ม วงม งส ข (Kittirak Moungmingsuk) kittirak@clusterkit.co.th May 19, 2012 @ossfestival #11 `whoami` A part of team at Cluster Kit Co.,Ltd. Since 2007. Adjacent Lecturer
More informationIntroduce C# as Object Oriented programming language. Explain, tokens,
Module 2 98 Assignment 1 Introduce C# as Object Oriented programming language. Explain, tokens, lexicals and control flow constructs. 99 The C# Family Tree C Platform Independence C++ Object Orientation
More informationLooking forward to a successful coopertation : TEIN
Space Krenovation Park : SKP Looking forward to a successful coopertation : TEIN Geo-Informatics and Space Technology Development Agency : GISTDA Space Krenovation Park @ Chonburi 1 Mission TC/TM House
More informationFundamentals of Database Systems
204222 - Fundamentals of Database Systems Chapter 24 Database Security Adapted for 204222 by Areerat Trongratsameethong Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Outline
More informationProgramming for Engineers Structures, Unions
Programming for Engineers Structures, Unions ICEN 200 Spring 2017 Prof. Dola Saha 1 Structure Ø Collections of related variables under one name. Ø Variables of may be of different data types. Ø struct
More informationLecture 5: Introducing Dialog Boxes & Child Window Controls for Win 32 API
Lecture 5: Introducing Dialog Boxes & Child Window Controls for Win 32 API What is Dialog Box? How to make your project to have a Dialog Box Modal Dialog Modeless Dialog WM_INITDIALOG Child Window Controls
More informationWhat s Hot & What s New from Microsoft ส มล อน นตธนะสาร Segment Marketing Manager
What s Hot & What s New from Microsoft ส มล อน นตธนะสาร Segment Marketing Manager 1 โปรแกรมท น าสนใจส าหร บไตรมาสน Crisis Turing Point II Oct-Dec 09 Windows 7 งานเป ดต วสาหร บล กค าท วไป, Paragon Hall,
More informationObject Oriented Programming in C#
Introduction to Object Oriented Programming in C# Class and Object 1 You will be able to: Objectives 1. Write a simple class definition in C#. 2. Control access to the methods and data in a class. 3. Create
More informationC++ PROGRAMMING LANGUAGE: CLASSES. CAAM 519, CHAPTER 13
C++ PROGRAMMING LANGUAGE: CLASSES. CAAM 519, CHAPTER 13 This chapter focuses on introducing the notion of classes in the C++ programming language. We describe how to create class and use an object of a
More informationObjectives. Describe ways to create constants const readonly enum
Constants Objectives Describe ways to create constants const readonly enum 2 Motivation Idea of constant is useful makes programs more readable allows more compile time error checking 3 Const Keyword const
More informationObject Oriented Design
Object Oriented Design Lecture 3: Introduction to C++ (Continue) Examples using declarations that eliminate the need to repeat the std:: prefix 1 Examples using namespace std; enables a program to use
More informationHistory. used in early Mac development notable systems in Pascal Skype TeX embedded systems
Overview The Pascal Programming Language (with material from tutorialspoint.com) Background & History Features Hello, world! General Syntax Variables/Data Types Operators Conditional Statements Functions
More informationC Programming. Lecture no. 2 More on Control Statements
C Programming Lecture no. 2 More on Control Statements คำส งในกำรควบค มโปรแกรม 2 คำส ง if อย ำงง ำย ค ำส ง if เป นค ำส งสำหร บกำร สร ำงสำยกำรควบค มกำรท ำงำน ออกเป น 2 สำย ร ปแบบ if (condition) statement;
More informationSyntax and Variables
Syntax and Variables What the Compiler needs to understand your program, and managing data 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line
More informationConsole Input / Output
Table of Contents Console Input / Output Printing to the Console Printing Strings and Numbers Reading from the Console Reading Characters Reading Strings Parsing Strings to Numeral Types Reading Numeral
More informationIT 374 C# and Applications/ IT695 C# Data Structures
IT 374 C# and Applications/ IT695 C# Data Structures Module 2.5: Methods A Deeper Look Xianrong (Shawn) Zheng Spring 2017 1 Outline static Methods, static Variables, and Class Math Methods with Multiple
More informationPart VII. Object-Oriented Programming. Philip Blakely (LSC) C++ Introduction 194 / 370
Part VII Object-Oriented Programming Philip Blakely (LSC) C++ Introduction 194 / 370 OOP Outline 24 Object-Oriented Programming 25 Member functions 26 Constructors 27 Destructors 28 More constructors Philip
More informationCrystal Report & Crystal Server 2016
Crystal Report & Crystal Server 206 Crystal Report เป นเคร องม อในการสร าง Report ท ม จ ดเด นในความสามารถเช อมต อฐานข อม ลท หลากหลาย เพ อนำา เอาข อม ลมาใช สร างรายงานสำาหร บการใช งานท วไปในงานธ รก จ ประจำาว
More informationDuhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain
Duhok Polytechnic University Amedi Technical Institute/ IT Dept. By Halkawt Rajab Hussain 2016-04-02 : Structure declaration and initialization. Access to fields of structure. Array of Structs. 11/10/2016
More informationMethods: A Deeper Look
1 2 7 Methods: A Deeper Look OBJECTIVES In this chapter you will learn: How static methods and variables are associated with an entire class rather than specific instances of the class. How to use random-number
More informationToday Topics. Artificial Intelligent??? Artificial Intelligent??? Intelligent Behaviors. Intelligent Behavior (Con t) 20/07/52
Today Topics Artificial Intelligent Applications Opas Wongtaweesap (Aj OaT) Intelligent Information Systems Development and Research Laboratory Centre Faculty of Science, Silpakorn University Webpage :
More informationObjectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments
Basics Objectives Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments 2 Class Keyword class used to define new type specify
More informationPRICE LIST Video Transmission Fiber Optic Cable TEL: (May 2015) HD-AHD CCTV System
COMMUNICATION PRODUCTS Video Transmission Fiber Optic Cable PRICE LIST 2015 HD-AHD CCTV System HD-CVI CCTV System HD-TVI CCTV System Analog CCTV System (May 2015) www.facebook.com/bismonthailand TEL: 0-2563-5000
More informationC# Fundamentals. built in data types. built in data types. C# is a strongly typed language
C# Fundamentals slide 2 C# is a strongly typed language the C# compiler is fairly good at finding and warning about incorrect use of types and uninitialised and unused variables do not ignore warnings,
More informationComputers and Programming Section 450. Lab #1 C# Basic. Student ID Name Signature
Lab #1 C# Basic Sheet s Owner Student ID Name Signature Group partner 1. Identifier Naming Rules in C# A name must consist of only letters (A Z,a z), digits (0 9), or underscores ( ) The first character
More informationFeatures of C. Portable Procedural / Modular Structured Language Statically typed Middle level language
1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC
More informationHierarchical inheritance: Contains one base class and multiple derived classes of the same base class.
1. What is C#? C# (pronounced "C sharp") is a simple, modern, object oriented, and type safe programming language. It will immediately be familiar to C and C++ programmers. C# combines the high productivity
More informationChapter 9 Technicalities: Classes, etc.
Chapter 9 Technicalities: Classes, etc. Dr. Hyunyoung Lee Based on slides by Dr. Bjarne Stroustrup www.stroustrup.com/programming Abstract This lecture presents language technicalities, mostly related
More information3. Basic Concepts. 3.1 Application Startup
3.1 Application Startup An assembly that has an entry point is called an application. When an application runs, a new application domain is created. Several different instantiations of an application may
More informationLAB 9 Arrays. Topics. Array of data types Accessing array elements Initializing array elements
LAB 9 Arrays Topics Array of data types Accessing array elements Initializing array elements Array of data types An array is an indexed collection of objects, all of the same type. We can declare a C#
More informationFunctions and Recursion
Functions and Recursion 1 Outline Introduction Program Components in C++ Math Library Functions Functions Function Definitions Function Prototypes Header Files Random Number Generation Example: A Game
More informationโปรแกรมท น าสนใจส าหร บไตรมาสน
แคมเปญ และก จกรรมทางการตลาด (ต ลาคม ธ นวาคม 2552) โปรแกรมท น าสนใจส าหร บไตรมาสน Crisis Turing Point II Oct-Dec 09 Windows 7 งานเป ดต วสาหร บล กค าท วไป, Paragon Hall, 31 Oct -1 Nov งานเป ดต วสาหร บล กค
More informationChapter 9 Technicalities: Classes, etc. Walter C. Daugherity Lawrence Pete Petersen Bjarne Stroustrup Fall 2007
Chapter 9 Technicalities: Classes, etc. Walter C. Daugherity Lawrence Pete Petersen Bjarne Stroustrup Fall 2007 Abstract This lecture presents language technicalities, mostly related to user defined types;
More informationZhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson
Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Introduction History, Characteristics of Java language Java Language Basics Data types, Variables, Operators and Expressions Anatomy of a Java Program
More informationLecture Outline. 1. Semantic Web Technologies 2. A Layered Approach 3. Data Integration
Semantic Web Lecture Outline 1. Semantic Web Technologies 2. A Layered Approach 3. Data Integration Semantic Web Technologies Explicit Metadata Ontologies Logic and Inference Agents 3 On HTML Web content
More informationNOIDATUT E Leaning Platform
NOIDATUT E Leaning Platform Dot Net Framework Lab Manual COMPUTER SCIENCE AND ENGINEERING Presented by: NOIDATUT Email : e-learn@noidatut.com www.noidatut.com C SHARP 1. Program to display Hello World
More informationIntroduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview
Introduction to Visual Basic and Visual C++ Introduction to Java Lesson 13 Overview I154-1-A A @ Peter Lo 2010 1 I154-1-A A @ Peter Lo 2010 2 Overview JDK Editions Before you can write and run the simple
More informationChapter-8 DATA TYPES. Introduction. Variable:
Chapter-8 DATA TYPES Introduction To understand any programming languages we need to first understand the elementary concepts which form the building block of that program. The basic building blocks include
More informationDefinition: Data Type A data type is a collection of values and the definition of one or more operations on those values.
Data Types 1 Definition: Data Type A data type is a collection of values and the definition of one or more operations on those values. Base Data Types All the values of the type are ordered and atomic.
More informationChapter 9 Technicalities: Classes, etc.
Chapter 9 Technicalities: Classes, etc. Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/~hkaiser/spring_2011/csc1253.html Slides adapted from: Bjarne Stroustrup, Programming Principles and Practice
More informationFlashback Technicalities: Classes, etc. Lecture 11 Hartmut Kaiser
Flashback Technicalities: Classes, etc. Lecture 11 Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/~hkaiser/fall_2013/csc1254.html Overview Classes Implementation and interface Constructors Member
More informationRemote Monitoring and Controlling of a Material Science Experiment
Walailak J Sci & Tech 2004; 1(1):43-52. 43 Remote Monitoring and Controlling of a Material Science Experiment Wattanapong KURDTHONGMEE School of Engineering and Resources, Walailak University, Thasala,
More informationTemplate Issue Resolutions from the Stockholm Meeting
96-0153/N0971 Template Issue Resolutions from the Stockholm Meeting 1 X3J16/96-0153 WG21/N0971 July 9 th, 1996 John H. Spicer, Edison Design Group Template Issue Resolutions from the Stockholm Meeting
More informationStarting Savitch Chapter 10. A class is a data type whose variables are objects. Some pre-defined classes in C++ include int,
Classes Starting Savitch Chapter 10 l l A class is a data type whose variables are objects Some pre-defined classes in C++ include int, char, ifstream Of course, you can define your own classes too A class
More informationtypedef int Array[10]; String name; Array ages;
Morteza Noferesti The C language provides a facility called typedef for creating synonyms for previously defined data type names. For example, the declaration: typedef int Length; Length a, b, len ; Length
More informationบทท 4 ข นตอนการทดลอง
บทท 4 ข นตอนการทดลอง ในบทน จะท าการทดลองในส วนของซ นเซอร ว ดอ ณหภ ม เพ อผลท ได มาใช ในการเข ยน โปรแกรมและท าโครงงานให ได ประส ทธ ภาพข น 4.1 การทดสอบระบบเซ นเซอร ว ตถ ประสงค การทดลอง ว ตถ ประสงค ของการทดลองน
More informationMT7049 การออกแบบและฐานข อม ลบนเว บ
MT7049 การออกแบบและฐานข อม ลบนเว บ 3 (2-2-5) Web Design and Web Database ส พจน เฮงพระพรหม http://home.npru.ac.th/supoj คาอธ บายรายว ชา แนวค ดองค ประกอบของเว บ หล กการออกแบบเว บ การว เคราะห เน อหา การออกแบบโครงสร
More informationOBJECT ORIENTED PROGRAMMING
Classes and Objects So far you have explored the structure of a simple program that starts execution at main() and enables you to declare local and global variables and constants and branch your execution
More informationBasic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java
Chapter 5 Methods Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word Chapter 1 Introduction to Computers, Programs, and Java Chapter 2 Primitive Data Types and Operations
More informationUEE1302 (1102) F10: Introduction to Computers and Programming
Computational Intelligence on Automation Lab @ NCTU Learning Objectives UEE1302 (1102) F10: Introduction to Computers and Programming Programming Lecture 00 Programming by Example Introduction to C++ Origins,
More informationCS2141 Software Development using C/C++ C++ Basics
CS2141 Software Development using C/C++ C++ Basics Integers Basic Types Can be short, long, or just plain int C++ does not define the size of them other than short
More informationChapter 9 Technicalities: Classes
Chapter 9 Technicalities: Classes Bjarne Stroustrup www.stroustrup.com/programming Abstract This lecture presents language technicalities, mostly related to user defined types; that is, classes and enumerations.
More informationEEE145 Computer Programming
EEE145 Computer Programming Content of Topic 2 Extracted from cpp.gantep.edu.tr Topic 2 Dr. Ahmet BİNGÜL Department of Engineering Physics University of Gaziantep Modifications by Dr. Andrew BEDDALL Department
More informationCMIS 102 Hands-On Lab
CMIS 10 Hands-On Lab Week 8 Overview This hands-on lab allows you to follow and experiment with the critical steps of developing a program including the program description, analysis, test plan, and implementation
More informationC++ : Object Oriented Features. What makes C++ Object Oriented
C++ : Object Oriented Features What makes C++ Object Oriented Encapsulation in C++ : Classes In C++, a package of data + processes == class A class is a user defined data type Variables of a class are
More informationC#.Net. Course Contents. Course contents VT BizTalk. No exam, but laborations
, 1 C#.Net VT 2009 Course Contents C# 6 hp approx. BizTalk 1,5 hp approx. No exam, but laborations Course contents Architecture Visual Studio Syntax Classes Forms Class Libraries Inheritance Other C# essentials
More informationVerified by Visa Activation Service For Cardholder Manual. November 2016
Verified by Visa Activation Service For Cardholder Manual November 2016 Table of Contents Contents Registration for Card Holder verification on ACS... 3 1. Direct Activation... 4 2. Changing personal information
More informationDAD Lab. 1 Introduc7on to C#
DAD 2017-18 Lab. 1 Introduc7on to C# Summary 1..NET Framework Architecture 2. C# Language Syntax C# vs. Java vs C++ 3. IDE: MS Visual Studio Tools Console and WinForm Applica7ons 1..NET Framework Introduc7on
More informationAppendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.
A Appendix Grammar There is no worse danger for a teacher than to teach words instead of things. Marc Block Introduction keywords lexical conventions programs expressions statements declarations declarators
More informationArrays in C C Programming and Software Tools. N.C. State Department of Computer Science
Arrays in C C Programming and Software Tools N.C. State Department of Computer Science Contents Declaration Memory and Bounds Operations Variable Length Arrays Multidimensional Arrays Character Strings
More information