Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain

Size: px
Start display at page:

Download "Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain"

Transcription

1 Duhok Polytechnic University Amedi Technical Institute/ IT Dept. By Halkawt Rajab Hussain

2 : Structure declaration and initialization. Access to fields of structure. Array of Structs. 11/10/2016 1

3 In C# and.net Framework there are two implementations of the concept of "class" from the object-oriented programming: classes and structures. Classes are defined through the keyword class. Structures are defined through the keyword struct. The main difference between a structure and a class is that: 1. Classes are reference types (references to some address in the heap which holds their members). 2. Structures (structs) are value types (they directly hold their members in the program execution stack). 11/10/2016 2

4 Structure declaration and initialization. To define a structure, you must use the struct statement. The struct statement defines a new data type, with more than one member for your program. For example, here is the way you can declare the Book structure: struct Books public string title; public string author; public string subject; public int book_id; ; 11/10/2016 3

5 Initialization: StudentInfo st = new StudentInfo() Id = 123, Name = "Ali", Phone = ; StudentInfo st = new StudentInfo() st.id=123; st.name= Ali ; st.phone= ; Direct set values set values after create new object 11/10/2016 4

6 The following program shows the use of the structure: using System; struct Books public string title; public string author; public string subject; public int book_id; ; public class teststructure public static void Main(string[] args) Books Book1; /* Declare Book1 of type Book */ Books Book2; /* Declare Book2 of type Book */ /* book 1 specification */ Book1.title = "C Programming"; Book1.author = "Nuha Ali"; Book1.subject = "C Programming Tutorial"; Book1.book_id = ; /* book 2 specification */ Book2.title = "Telecom Billing"; Book2.author = "Zara Ali"; Book2.subject = "Telecom Billing Tutorial"; Book2.book_id = ; /* print Book1 info */ Console.WriteLine( "Book 1 title : 0", Book1.title); Console.WriteLine("Book 1 author : 0", Book1.author); Console.WriteLine("Book 1 subject : 0", Book1.subject); Console.WriteLine("Book 1 book_id :0", Book1.book_id); /* print Book2 info */ Console.WriteLine("Book 2 title : 0", Book2.title); Console.WriteLine("Book 2 author : 0", Book2.author); Console.WriteLine("Book 2 subject : 0", Book2.subject); Console.WriteLine("Book 2 book_id : 0", Book2.book_id); Console.ReadKey(); 11/10/2016 5

7 Features of C# Structures: Structures can have methods, fields, indexers, properties, operator methods, and events. Structures can have defined constructors, but not destructors. However, you cannot define a default constructor for a structure. The default constructor is automatically defined and cannot be changed. Unlike classes, structures cannot inherit other structures or classes. Structures cannot be used as a base for other structures or classes. A structure can implement one or more interfaces. Structure members cannot be specified as abstract, virtual, or protected. 11/10/2016 6

8 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 the New operator is not used, the fields remain unassigned and the object cannot be used until all the fields are initialized. HomeWork: Rewrite the previous example, creates two methods, getvalue to get values of book properties and display method to display book information. 11/10/2016 7

9 Example The following program, if the access specifier for struct properties n1,n2 and res are privates, how to set values to n1,n2 and get result of res? using system; namespace Exam class test struct Calc public int n1, n2, res; ; static void Main(string[] args) Clac c; c.n1=5; c.n2=10; c.res=c.n1+c.n2; Console.WriteLine(c.res); 11/10/2016 8

10 Defining (Creating a Custom struct Type) The following example demonstrates how to define a custom struct. In this case,the struct is a StudentInfo with Id, Name and Phone properties. Example Create custom structure for student called StudentInfo? struct StudentInfo private int m_id; public int Id get return m_id; set m_id = value; private string m_name; public string Name get return m_name; set m_name = value; private int m_phone; public int Phone get return m_phone; set m_phone = value; 11/10/2016 9

11 Array of structs: Structures Write a console application that receives the following information for a set of students: studentid, studentname, coursename, date-of-birth.. The application should also be able to display the information being entered.. Implement this using structs? struct student public int s_id; public String s_name, c_name, dob; class Program static void Main(string[] args) student[] arr = new student[4]; for(int i = 0; i < 4; i++) Console.WriteLine("Please enter StudentId, StudentName, CourseName, Date-Of-Birth"); arr[i].s_id = Int32.Parse(Console.ReadLine()); arr[i].s_name = Console.ReadLine(); arr[i].c_name = Console.ReadLine(); arr[i].s_dob = Console.ReadLine(); 11/10/

12 Example This example declares a struct with three members: a property, a method, and a private field. It creates an instance of the struct and puts it to use: using System; struct SimpleStruct private int xval; public int X get return xval; set if (value < 100) xval = value; public void DisplayX() Console.WriteLine("The stored value is: 0", xval); class TestClass public static void Main() SimpleStruct ss = new SimpleStruct(); ss.x = 5; ss.displayx(); 11/10/

13 Example Write complite program in C# console application that demonstrates struct initialization using both default and parameterized constructors. using system; Namespace exam public struct CoOrds public int x, y; public CoOrds(int p1, int p2) x = p1; y = p2; class TestCoOrds static void Main() CoOrds coords1 = new CoOrds(); CoOrds coords2 = new CoOrds(10, 10); // Display results: Console.Write("CoOrds 1: "); Console.WriteLine("x = 0, y = 1", coords1.x, coords1.y); Console.Write("CoOrds 2: "); Console.WriteLine("x = 0, y = 1", coords2.x, coords2.y); // Keep the console window open in debug mode. Console.WriteLine("Press any key to exit."); Console.ReadKey(); 11/10/

14 Thanks Any Questions 11/10/

Lab - 10 Write a c# program to prepend the namespace name by calling the namespaceenabled version of either function or variable?

Lab - 10 Write a c# program to prepend the namespace name by calling the namespaceenabled version of either function or variable? Lab - 10 Write a c# program to prepend the namespace name by calling the namespaceenabled version of either function or variable? namespace first_space class namespace_cl Console.WriteLine("Inside first_space");

More information

PASCAL - RECORDS. To define a record type, you may use the type declaration statement. The record type is defined as

PASCAL - RECORDS. To define a record type, you may use the type declaration statement. The record type is defined as http://www.tutorialspoint.com/pascal/pascal_records.htm PASCAL - RECORDS Copyright tutorialspoint.com Pascal arrays allow you to define of iables that can hold several data items of the same kind but a

More information

Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain

Duhok 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 Objects and classes: Basics of object and class in C#. Private and public members and protected. Static

More information

Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain

Duhok 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 Pointers: Pointer declaration and initialization. Pointer To Pointer. Arithmetic operation on pointer

More information

Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain

Duhok 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 Inheritance: Concept of Inheritance. Types of inheritance. Virtual base class method. Interface. 4/1/2017

More information

cout << "How many numbers would you like to type? "; cin >> memsize; p = new int[memsize];

cout << How many numbers would you like to type? ; cin >> memsize; p = new int[memsize]; 1 C++ Dynamic Allocation Memory needs were determined before program execution by defining the variables needed. Sometime memory needs of a program can only be determined during runtime, or the memory

More information

Department of Networks College of Bardarash Technical Institute DUHOK Polytechnic University Subject: Programming Fundamental by JAVA Course Book

Department of Networks College of Bardarash Technical Institute DUHOK Polytechnic University Subject: Programming Fundamental by JAVA Course Book 1 Department of Networks College of Bardarash Technical Institute DUHOK Polytechnic University Subject: Programming Fundamental by JAVA Course Book Year 1 Lecturer's name: MSc. Sami Hussein Ismael Academic

More information

Getter and Setter Methods

Getter and Setter Methods Example 1 namespace ConsoleApplication14 public class Student public int ID; public string Name; public int Passmark = 50; class Program static void Main(string[] args) Student c1 = new Student(); Console.WriteLine("please..enter

More information

Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain

Duhok 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 Overview. C# program structure. Variables and Constant. Conditional statement (if, if/else, nested if

More information

Apllications. February 17, Indian Institute of Space Science and Technology. MA122 - Computer Programming and. Apllications. Structures.

Apllications. February 17, Indian Institute of Space Science and Technology. MA122 - Computer Programming and. Apllications. Structures. Indian Institute of Space Science Technology February 17, 2017 Lecture 14 1 2 3 Declaration 1 struct inflatable // structure declaration 2 { 3 char name[20]; 4 float volume; 5 double price; 6 }; ++ types

More information

PROGRAMMAZIONE I A.A. 2017/2018

PROGRAMMAZIONE I A.A. 2017/2018 PROGRAMMAZIONE I A.A. 2017/2018 STRUCTURES STRUCTS Arrays allow to define type of variables that can hold several data items of the same kind. Similarly structure is another user defined data type available

More information

Structures can be easily used as a function parameters. It is done similar as with variables.

Structures can be easily used as a function parameters. It is done similar as with variables. 1. Structures in functions. Structures can be easily used as a function parameters. It is done similar as with variables. #include char title[50]; char author[50]; char subject[100]; int book_id;

More information

Objectives: Lab Exercise 1 Part 1. Sample Run. Part 2

Objectives: Lab Exercise 1 Part 1. Sample Run. Part 2 Objectives: king Saud University College of Computer &Information Science CSC111 Lab Object I All Sections - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

More information

Object Oriented Programming in C#

Object 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 information

C# - Reflection. It allows examining various types in an assembly and instantiate these types.

C# - Reflection. It allows examining various types in an assembly and instantiate these types. C# - Reflection Reflection objects are used for obtaining type information at runtime. The classes that give access to the metadata of a running program are in the System.Reflection namespace. The System.Reflection

More information

Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain

Duhok 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 String and files: String declaration and initialization. Strings and Char Arrays: Properties And Methods.

More information

Unit 8. Structures and Unions. School of Science and Technology INTRODUCTION

Unit 8. Structures and Unions. School of Science and Technology INTRODUCTION INTRODUCTION Structures and Unions Unit 8 In the previous unit 7 we have studied about C functions and their declarations, definitions, initializations. Also we have learned importance of local and global

More information

Introduction To C#.NET

Introduction 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 information

Department of Computer Science and Engineering. Programming for Problem Solving. I Year B.Tech. (I - Sem) Assistant Professor (M.

Department of Computer Science and Engineering. Programming for Problem Solving. I Year B.Tech. (I - Sem) Assistant Professor (M. Website : www.aceec.ac.in ACE Engineering College Ankushapur, Ghatkesar, Telangana 501301 (EAMCET Code: ACEG) NAAC Accridated with A Grade Department of Computer Science and Engineering Programming for

More information

EEE-425 Programming Languages (2013) 1

EEE-425 Programming Languages (2013) 1 2 Learn about class concepts How to create a class from which objects can be instantiated Learn about instance variables and methods How to declare objects How to organize your classes Learn about public

More information

What property of a C# array indicates its allocated size? What keyword in the base class allows a method to be polymorphic?

What property of a C# array indicates its allocated size? What keyword in the base class allows a method to be polymorphic? What property of a C# array indicates its allocated size? a. Size b. Count c. Length What property of a C# array indicates its allocated size? a. Size b. Count c. Length What keyword in the base class

More information

Learn C# Errata. 3-9 The Nullable Types The Assignment Operators

Learn C# Errata. 3-9 The Nullable Types The Assignment Operators 1 The following pages show errors from the original edition, published in July 2008, corrected in red. Future editions of this book will be printed with these corrections. We apologize for any inconvenience

More information

And Even More and More C++ Fundamentals of Computer Science

And Even More and More C++ Fundamentals of Computer Science And Even More and More C++ Fundamentals of Computer Science Outline C++ Classes Special Members Friendship Classes are an expanded version of data structures (structs) Like structs, the hold data members

More information

UNIT 2. .NET Languages. C# Language Fundamentals. Operators, Types, and Variables. Variables and Types

UNIT 2. .NET Languages. C# Language Fundamentals. Operators, Types, and Variables. Variables and Types .NET Languages C# Language Fundamentals Operators, Types, and Variables Variables and Types "Variables" are simply storage locations for data. You can place data into them and retrieve their contents as

More information

UNIVERSITY OF THE FREE STATE DEPARTMENT OF COMPUTER SCIENCE AND INFORMATICS CSIS1614

UNIVERSITY OF THE FREE STATE DEPARTMENT OF COMPUTER SCIENCE AND INFORMATICS CSIS1614 UNIVERSITY OF THE FREE STATE DEPARTMENT OF COMPUTER SCIENCE AND INFORMATICS CSIS1614 DATE: 7 May 2015 MARKS: 130 ASSESSOR: Prof. P.J. Blignaut (Bonus marks: 5) MODERATOR: Dr. L. de Wet TIME: 180 minutes

More information

EEE-425 Programming Languages (2013) 1

EEE-425 Programming Languages (2013) 1 2 Learn about class concepts How to create a class from which objects can be instantiated Learn about instance variables and methods How to declare objects How to organize your classes Learn about public

More information

Answer the following questions on the answer sheet that is provided. The computer must be switched off while you are busy with Section A.

Answer the following questions on the answer sheet that is provided. The computer must be switched off while you are busy with Section A. UNIVERSITY OF THE FREE STATE DEPARTMENT OF COMPUTER SCIENCE AND INFORMATICS RIS 114 DATE: 25 April 2013 TIME: 180 minutes MARKS: 100 ASSESSORS: Prof. P.J. Blignaut & Mr. F. Radebe (+2 bonus marks) MODERATOR:

More information

EL2310 Scientific Programming

EL2310 Scientific Programming (pronobis@kth.se) Overview Overview Wrap Up Introduction to Object Oriented Paradigm More on and Members Operator Overloading Last time Intro to C++ Differences between C and C++ Intro to OOP Today Object

More information

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable? Peer Instruction 8 Classes and Objects How can multiple methods within a Java class read and write the same variable? A. Allow one method to reference a local variable of the other B. Declare a variable

More information

Chapter 1 Getting Started

Chapter 1 Getting Started Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different

More information

POLYTECHNIC OF NAMIBIA SCHOOL OF COMPUTING AND INFORMATICS DEPARTMENT OF COMPUTER SCIENCE

POLYTECHNIC OF NAMIBIA SCHOOL OF COMPUTING AND INFORMATICS DEPARTMENT OF COMPUTER SCIENCE /. POLYTECHNIC OF NAMIBIA SCHOOL OF COMPUTING AND INFORMATICS DEPARTMENT OF COMPUTER SCIENCE COUR ENAME: PROGRAMMING 1 COUR ECODE: PRGSlOS NQFLEVEL: 5 DATE: JUNE 20 15 DURATION: 2HOURS MARKS: 100 PAPER:

More information

C# is a modern, g eneral-purpose, object-oriented prog ramming lang uag e developed by Microsoft and approved by Ecma and ISO.

C# is a modern, g eneral-purpose, object-oriented prog ramming lang uag e developed by Microsoft and approved by Ecma and ISO. C# - QUICK GUIDE http://www.tuto rialspo int.co m/csharp/csharp_quick_g uide.htm Copyrig ht tutorialspoint.com C# - OVERVIEW C# is a modern, g eneral-purpose, object-oriented prog ramming lang uag e developed

More information

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor. 3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.

More information

Tutorial 6 CSC 201. Java Programming Concepts مبادئ الربجمة باستخدام اجلافا

Tutorial 6 CSC 201. Java Programming Concepts مبادئ الربجمة باستخدام اجلافا Tutorial 6 CSC 201 Java Programming Concepts مبادئ الربجمة باستخدام اجلافا Chapter 6: Classes and Objects 1. Classes & Objects What is an object? Real Objects Java Objects Classes Defining a class and

More information

Introduction to Programming Using Java (98-388)

Introduction 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 information

Homework 6. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine

Homework 6. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine Homework 6 Yuji Shimojo CMSC 330 Instructor: Prof. Reginald Y. Haseltine July 21, 2013 Question 1 What is the output of the following C++ program? #include #include using namespace

More information

Database Views & Stored Procedures. Hans-Petter Halvorsen, M.Sc.

Database Views & Stored Procedures. Hans-Petter Halvorsen, M.Sc. Database Views & Stored Procedures Hans-Petter Halvorsen, M.Sc. SQL Server Hans-Petter Halvorsen, M.Sc. Microsoft SQL Server 3 1 2 Your SQL Server Your Tables Your Database 4 Write your Query here 5 The

More information

This is an open-book test. You may use the text book Be Sharp with C# but no other sources, written or electronic, will be allowed.

This is an open-book test. You may use the text book Be Sharp with C# but no other sources, written or electronic, will be allowed. UNIVERSITY OF THE FREE STATE DEPARTMENT OF COMPUTER SCIENCE AND INFORMATICS RIS 124 DATE: 5 September 2011 TIME: 3½ hours MARKS: 150 ASSESSORS: Prof. P.J. Blignaut & Mr. M.B. Mase MODERATOR: Dr. A. van

More information

I Mid Semester May 2012 : Class XII : Computer Science Max Mark 50 : Time 2 Hrs. 1. a) What is macro in C++? Give example 2

I Mid Semester May 2012 : Class XII : Computer Science Max Mark 50 : Time 2 Hrs. 1. a) What is macro in C++? Give example 2 I Mid Semester May 01 : Class XII : Computer Science Max Mark 50 : Time Hrs 1. a) What is macro in C++? Give example b) Give the Header file for the following functions:- i) gets ( ) ii) tolower( ) 1 c)

More information

UNIVERSITY OF THE FREE STATE DEPARTMENT OF COMPUTER SCIENCE AND INFORMATICS RIS 114 CLASS TEST 2 and 3 DATE: 4 August 2014 TIME: 180 minutes MARKS: 70

UNIVERSITY OF THE FREE STATE DEPARTMENT OF COMPUTER SCIENCE AND INFORMATICS RIS 114 CLASS TEST 2 and 3 DATE: 4 August 2014 TIME: 180 minutes MARKS: 70 UNIVERSITY OF THE FREE STATE DEPARTMENT OF COMPUTER SCIENCE AND INFORMATICS RIS 114 CLASS TEST 2 and 3 DATE: 4 August 2014 TIME: 180 minutes MARKS: 70 ASSESSOR: Prof. P.J. Blignaut (+1 bonus mark) This

More information

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide AP Computer Science Chapter 10 Implementing and Using Classes Study Guide 1. A class that uses a given class X is called a client of X. 2. Private features of a class can be directly accessed only within

More information

Class CSE F. *slides are from CSE S at SKKU & at MIT

Class CSE F. *slides are from CSE S at SKKU & at MIT Class CSE2013-17F *slides are from CSE2013-16S at SKKU & 6.096 at MIT Representing a Vector In the context of geometry, a vector consists of 2 points: a start and a finish Each point itself has an x and

More information

IST311. Advanced Issues in OOP: Inheritance and Polymorphism

IST311. Advanced Issues in OOP: Inheritance and Polymorphism IST311 Advanced Issues in OOP: Inheritance and Polymorphism IST311/602 Cleveland State University Prof. Victor Matos Adapted from: Introduction to Java Programming: Comprehensive Version, Eighth Edition

More information

Problem 1. Multiple Choice (choose only one answer)

Problem 1. Multiple Choice (choose only one answer) Practice problems for the Final (Tuesday, May 14 4:30-6:30pm MHP 101). The Final Exam will cover all course material. You will be expected to know the material from the assigned readings in the book, the

More information

Static, Final & Memory Management

Static, Final & Memory Management Static, Final & Memory Management The static keyword What if you want to have only one piece of storage regardless of how many objects are created or even no objects are created? What if you need a method

More information

A method is a code block that contains a series of statements. Methods. Console.WriteLine(); Console.ReadKey(); Console.ReadKey(); int.

A method is a code block that contains a series of statements. Methods. Console.WriteLine(); Console.ReadKey(); Console.ReadKey(); int. A method is a code block that contains a series of statements Methods Built-in User Define Built-in Methods (Examples): Console.WriteLine(); int.parse(); Methods Void (Procedure) Return (Function) Procedures

More information

CS 141, Introduction to Computer Science Fall Midterm Exam

CS 141, Introduction to Computer Science Fall Midterm Exam CS 141, Introduction to Computer Science Fall 2006 Midterm Exam Name: Student ID: 1 (12 points) Data Types Where possible give 3 examples of possible values for each of the following data types. Use proper

More information

Advanced Programming C# Lecture 7. dr inż. Małgorzata Janik

Advanced Programming C# Lecture 7. dr inż. Małgorzata Janik Advanced Programming C# Lecture 7 dr inż. Małgorzata Janik majanik@if.pw.edu.pl Winter Semester 2017/2018 C#: classes & objects 3 / 39 Class members Constructors Destructors Fields Methods Properties Indexers

More information

THE GOOD, BAD AND UGLY ABOUT POINTERS. Problem Solving with Computers-I

THE GOOD, BAD AND UGLY ABOUT POINTERS. Problem Solving with Computers-I THE GOOD, BAD AND UGLY ABOUT POINTERS Problem Solving with Computers-I The good: Pointers pass data around efficiently Pointers and arrays 100 104 108 112 116 ar 20 30 50 80 90 ar is like a pointer to

More information

Advanced Programming C# Lecture 7. dr inż. Małgorzata Janik

Advanced Programming C# Lecture 7. dr inż. Małgorzata Janik Advanced Programming C# Lecture 7 dr inż. Małgorzata Janik malgorzata.janik@pw.edu.pl Winter Semester 2018/2019 C#: classes & objects 3 / 34 Class members Constructors Destructors Fields Methods Properties

More information

Programming using C# LECTURE 07. Inheritance IS-A and HAS-A Relationships Overloading and Overriding Polymorphism

Programming using C# LECTURE 07. Inheritance IS-A and HAS-A Relationships Overloading and Overriding Polymorphism Programming using C# LECTURE 07 Inheritance IS-A and HAS-A Relationships Overloading and Overriding Polymorphism What is Inheritance? A relationship between a more general class, called the base class

More information

WWW.STUDENTSFOCUS.COM Unit II OBJECT ORIENTED ASPECTS OF C# Key Concepts of Object Orientation Abstraction Encapsulation Polymorphism Inheritance. Abstraction is the ability to generalize an object as

More information

Java: Classes. An instance of a class is an object based on the class. Creation of an instance from a class is called instantiation.

Java: Classes. An instance of a class is an object based on the class. Creation of an instance from a class is called instantiation. Java: Classes Introduction A class defines the abstract characteristics of a thing (object), including its attributes and what it can do. Every Java program is composed of at least one class. From a programming

More information

Class Test 10. Question 1. Create a console application using visual studio 2012 ultimate.

Class Test 10. Question 1. Create a console application using visual studio 2012 ultimate. Class Test 10 Question 1 Create a console application using visual studio 2012 ultimate. Figure 1 Use recursion to create a menu, DO NOT use a while, do while or for loop. When any value is entered that

More information

CS 116 Week 8 Page 1

CS 116 Week 8 Page 1 CS 116 Week 8: Outline Reading: 1. Dale, Chapter 11 2. Dale, Lab 11 Objectives: 1. Mid-term exam CS 116 Week 8 Page 1 CS 116 Week 8: Lecture Outline 1. Mid-term Exam CS 116 Week 8 Page 2 CS 116 Week 8:

More information

A506 / C201 Computer Programming II Placement Exam Sample Questions. For each of the following, choose the most appropriate answer (2pts each).

A506 / C201 Computer Programming II Placement Exam Sample Questions. For each of the following, choose the most appropriate answer (2pts each). A506 / C201 Computer Programming II Placement Exam Sample Questions For each of the following, choose the most appropriate answer (2pts each). 1. Which of the following functions is causing a temporary

More information

Software and Programming 1

Software and Programming 1 Software and Programming 1 Week 9 Lab - Use of Classes and Inheritance 8th March 2018 SP1-Lab9-2018.ppt Tobi Brodie (Tobi@dcs.bbk.ac.uk) 1 Lab 9: Objectives Exercise 1 Student & StudentTest classes 1.

More information

Microsoft Visual Basic 2005: Reloaded

Microsoft Visual Basic 2005: Reloaded Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 10 Creating Classes and Objects Objectives After studying this chapter, you should be able to: Define a class Instantiate an object from a class

More information

EEE-425 Programming Languages (2013) 1

EEE-425 Programming Languages (2013) 1 2 Namespaces Classes Fields Properties Methods Attributes Events Interfaces (contracts) Methods Properties Events Control Statements if, else, while, for, switch foreach Additional Features Operation Overloading

More information

Objects as a programming concept

Objects as a programming concept Objects as a programming concept IB Computer Science Content developed by Dartford Grammar School Computer Science Department HL Topics 1-7, D1-4 1: System design 2: Computer Organisation 3: Networks 4:

More information

Spring % of course grade

Spring % of course grade Name SOLUTION Final Score 10 ID Extra Credit Section (circle one): MW 8:30-9:50 TTh 9:30-10:50 TTh 11:00-12:20 10% of course grade 2 1. Anonymous Inner Classes In lecture we walked through the following:

More information

Week 5-1: ADT Design

Week 5-1: ADT Design Week 5-1: ADT Design Part1. ADT Design Define as class. Every obejects are allocated in heap space. Encapsulation : Data representation + Operation Information Hiding : Object's representation part hides,

More information

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year Object Oriented Programming Assistant Lecture Omar Al Khayat 2 nd Year Syllabus Overview of C++ Program Principles of object oriented programming including classes Introduction to Object-Oriented Paradigm:Structures

More information

G205 Fundamentals of Computer Engineering. CLASS 3, Wed. Sept Stefano Basagni Fall 2004 M-W, 1:30pm-3:10pm

G205 Fundamentals of Computer Engineering. CLASS 3, Wed. Sept Stefano Basagni Fall 2004 M-W, 1:30pm-3:10pm G205 Fundamentals of Computer Engineering CLASS 3, Wed. Sept. 15 2004 Stefano Basagni Fall 2004 M-W, 1:30pm-3:10pm Function Calls A function is called via its name Actual parameters are passed for the

More information

Lab - 1. Solution : 1. // Building a Simple Console Application. class HelloCsharp. static void Main() System.Console.WriteLine ("Hello from C#.

Lab - 1. Solution : 1. // Building a Simple Console Application. class HelloCsharp. static void Main() System.Console.WriteLine (Hello from C#. Lab - 1 Solution : 1 // Building a Simple Console Application class HelloCsharp static void Main() System.Console.WriteLine ("Hello from C#."); Solution: 2 & 3 // Building a WPF Application // Verifying

More information

Class, Variable, Constructor, Object, Method Questions

Class, Variable, Constructor, Object, Method Questions Class, Variable, Constructor, Object, Method Questions http://www.wideskills.com/java-interview-questions/java-classes-andobjects-interview-questions https://www.careerride.com/java-objects-classes-methods.aspx

More information

VISUAL PROGRAMMING_IT0309 Semester Number 05. G.Sujatha & R.Vijayalakshmi Assistant professor(o.g) SRM University, Kattankulathur

VISUAL PROGRAMMING_IT0309 Semester Number 05. G.Sujatha & R.Vijayalakshmi Assistant professor(o.g) SRM University, Kattankulathur School of Computing, 12/26/2012 1 VISUAL PROGRAMMING_IT0309 Semester Number 05 G.Sujatha & R.Vijayalakshmi Assistant professor(o.g) SRM University, Kattankulathur UNIT 1 School of Computing, Department

More information

Two hours QUESTION PAPER MUST NOT BE REMOVED FROM THE EXAM ROOM UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE

Two hours QUESTION PAPER MUST NOT BE REMOVED FROM THE EXAM ROOM UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE Two hours QUESTION PAPER MUST NOT BE REMOVED FROM THE EXAM ROOM UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE High-Level Programming (Java) Date: Thursday 20th January 2011 Time: 14:00-16:00 Answer

More information

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++ No. of Printed Pages : 3 I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination 05723. June, 2015 BCS-031 : PROGRAMMING IN C ++ Time : 3 hours Maximum Marks : 100 (Weightage 75%)

More information

Developing Microsoft.NET Applications for Windows (Visual Basic.NET)

Developing Microsoft.NET Applications for Windows (Visual Basic.NET) Developing Microsoft.NET Applications for Windows (Visual Basic.NET) Course Number: 2555 Length: 1 Day(s) Certification Exam This course will help you prepare for the following Microsoft Certified Professional

More information

CONSTRUCTOR & Description. String() This initializes a newly created String object so that it represents an empty character sequence.

CONSTRUCTOR & Description. String() This initializes a newly created String object so that it represents an empty character sequence. Constructor in Java 1. What are CONSTRUCTORs? Constructor in java is a special type of method that is used to initialize the object. Java constructor is invoked at the time of object creation. It constructs

More information

This is an open-book test. You may use the text book Be Sharp with C# but no other sources, written or electronic, will be allowed.

This is an open-book test. You may use the text book Be Sharp with C# but no other sources, written or electronic, will be allowed. UNIVERSITY OF THE FREE STATE DEPARTMENT OF COMPUTER SCIENCE AND INFORMATICS RIS 124 DATE: 1 September 2014 TIME: 3 hours MARKS: 105 ASSESSORS: Prof. P.J. Blignaut BONUS MARKS: 3 MODERATOR: Dr. L. De Wet

More information

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line A SIMPLE JAVA PROGRAM Class Declaration The Main Line INDEX The Line Contains Three Keywords The Output Line COMMENTS Single Line Comment Multiline Comment Documentation Comment TYPE CASTING Implicit Type

More information

CS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes

CS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes CS111: PROGRAMMING LANGUAGE II Lecture 1: Introduction to classes Lecture Contents 2 What is a class? Encapsulation Class basics: Data Methods Objects Defining and using a class In Java 3 Java is an object-oriented

More information

Inheritance, and Polymorphism.

Inheritance, and Polymorphism. Inheritance and Polymorphism by Yukong Zhang Object-oriented programming languages are the most widely used modern programming languages. They model programming based on objects which are very close to

More information

Building non-windows applications (programs that only output to the command line and contain no GUI components).

Building non-windows applications (programs that only output to the command line and contain no GUI components). C# and.net (1) Acknowledgements and copyrights: these slides are a result of combination of notes and slides with contributions from: Michael Kiffer, Arthur Bernstein, Philip Lewis, Hanspeter Mφssenbφck,

More information

CSCI 1370 APRIL 26, 2017

CSCI 1370 APRIL 26, 2017 CSCI 1370 APRIL 26, 2017 ADMINISTRATIVIA Quarter Exam #3: scores ranged from 0.70 points to 10.05 points, with a median score of 7.07. Note: a total bonus of 1.00 points (+.5 curve, +.5 group reward) was

More information

PES INSTITUTE OF TECHNOLOGY

PES INSTITUTE OF TECHNOLOGY Seventh Semester B.E. IA Test-I, 2014 USN 1 P E I S PES INSTITUTE OF TECHNOLOGY C# solution set for T1 Answer any 5 of the Following Questions 1) What is.net? With a neat diagram explain the important

More information

Interview Questions of C++

Interview Questions of C++ Interview Questions of C++ Q-1 What is the full form of OOPS? Ans: Object Oriented Programming System. Q-2 What is a class? Ans: Class is a blue print which reflects the entities attributes and actions.

More information

CS32 - Week 4. Umut Oztok. Jul 15, Umut Oztok CS32 - Week 4

CS32 - Week 4. Umut Oztok. Jul 15, Umut Oztok CS32 - Week 4 CS32 - Week 4 Umut Oztok Jul 15, 2016 Inheritance Process of deriving a new class using another class as a base. Base/Parent/Super Class Derived/Child/Sub Class Inheritance class Animal{ Animal(); ~Animal();

More information

Constructor - example

Constructor - example Constructors A constructor is a special member function whose task is to initialize the objects of its class. It is special because its name is same as the class name. The constructor is invoked whenever

More information

More C++ : Vectors, Classes, Inheritance, Templates

More C++ : Vectors, Classes, Inheritance, Templates Vectors More C++ : Vectors,, Inheritance, Templates vectors in C++ basically arrays with enhancements indexed similarly contiguous memory some changes defined differently can be resized without explicit

More information

CSC1322 Object-Oriented Programming Concepts

CSC1322 Object-Oriented Programming Concepts CSC1322 Object-Oriented Programming Concepts Instructor: Yukong Zhang February 18, 2016 Fundamental Concepts: The following is a summary of the fundamental concepts of object-oriented programming in C++.

More information

More C++ : Vectors, Classes, Inheritance, Templates. with content from cplusplus.com, codeguru.com

More C++ : Vectors, Classes, Inheritance, Templates. with content from cplusplus.com, codeguru.com More C++ : Vectors, Classes, Inheritance, Templates with content from cplusplus.com, codeguru.com 2 Vectors vectors in C++ basically arrays with enhancements indexed similarly contiguous memory some changes

More information

Chapter 11. Abstract Data Types and Encapsulation Concepts

Chapter 11. Abstract Data Types and Encapsulation Concepts Chapter 11 Abstract Data Types and Encapsulation Concepts The Concept of Abstraction An abstraction is a view or representation of an entity that includes only the most significant attributes The concept

More information

EXAMINATION FOR THE DIPLOMA IN INFORMATION TECHNOLOGY; YEAR 2

EXAMINATION FOR THE DIPLOMA IN INFORMATION TECHNOLOGY; YEAR 2 FACULTY OF SCIENCE AND TECHNOLOGY EXAMINATION FOR THE DIPLOMA IN INFORMATION TECHNOLOGY; YEAR 2 SAMPLE QUESTION Question 1 A class called TV is required by a programmer who is writing software for a retail

More information

Programming Fundamentals II (C++ II) Final Exam June 17 th, Sun, 2007

Programming Fundamentals II (C++ II) Final Exam June 17 th, Sun, 2007 Programming Fundamentals II (C++ II) Final Exam June 17 th, Sun, 2007 NAME:...Number:... Question 1 Define class section that has the following attributes: coursename, coursenumber as integer, credithours

More information

RIS214. Class Test 3

RIS214. Class Test 3 RIS214 Class Test 3 Use console applications to solve the following problems and employ defensive programming to prevent run-time errors. Every question will be marked as follows: mark = copied? -5 : runs?

More information

Classes. Logical method to organise data and functions in a same structure. Also known as abstract data type (ADT).

Classes. Logical method to organise data and functions in a same structure. Also known as abstract data type (ADT). UNITII Classes Logical method to organise data and functions in a same structure. Also known as abstract data type (ADT). It s a User Defined Data-type. The Data declared in a Class are called Data- Members

More information

DC69 C# and.net JUN 2015

DC69 C# and.net JUN 2015 Solutions Q.2 a. What are the benefits of.net strategy advanced by Microsoft? (6) Microsoft has advanced the.net strategy in order to provide a number of benefits to developers and users. Some of the major

More information

IT 374 C# and Applications/ IT695 C# Data Structures

IT 374 C# and Applications/ IT695 C# Data Structures IT 374 C# and Applications/ IT695 C# Data Structures Module 2.1: Introduction to C# App Programming Xianrong (Shawn) Zheng Spring 2017 1 Outline Introduction Creating a Simple App String Interpolation

More information

Homework 5. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine

Homework 5. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine Homework 5 Yuji Shimojo CMSC 330 Instructor: Prof. Reginald Y. Haseltine July 13, 2013 Question 1 Consider the following Java definition of a mutable string class. class MutableString private char[] chars

More information

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007 Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ 2007 Final Examination Question Max

More information

Question 1 Consider the following structure used to keep employee records:

Question 1 Consider the following structure used to keep employee records: Question 1 Consider the following structure used to keep employee records: struct Employee string firstname; string lastname; float salary; } Turn the employee record into a class type rather than a structure

More information

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #1 Examination 12:30 noon, Tuesday, February 14, 2012

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #1 Examination 12:30 noon, Tuesday, February 14, 2012 MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #1 Examination 12:30 noon, Tuesday, February 14, 2012 Instructor: K. S. Booth Time: 70 minutes (one hour ten minutes)

More information

Lab 10: Structs and Enumeration

Lab 10: Structs and Enumeration 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

More information

Chapter 10. Class & Objects in JAVA. By: Deepak Bhinde PGT Com.Sc.

Chapter 10. Class & Objects in JAVA. By: Deepak Bhinde PGT Com.Sc. Chapter 10 Class & Objects in JAVA By: Deepak Bhinde PGT Com.Sc. Objective In this presentation you will learn about the classes and objects which leads to Object Oriented Programming (OOP) in tha JAVA.

More information

User Defined Classes. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

User Defined Classes. CS 180 Sunil Prabhakar Department of Computer Science Purdue University User Defined Classes CS 180 Sunil Prabhakar Department of Computer Science Purdue University Announcements Register for Piazza. Deleted post accidentally -- sorry. Direct Project questions to responsible

More information

Final Exam CS 251, Intermediate Programming December 10, 2014

Final Exam CS 251, Intermediate Programming December 10, 2014 Final Exam CS 251, Intermediate Programming December 10, 2014 Name: NetID: Answer all questions in the space provided. Write clearly and legibly, you will not get credit for illegible or incomprehensible

More information

C# - ATTRIBUTES. Specifying an Attribute. Predefined Attributes. AttributeUsage

C# - ATTRIBUTES. Specifying an Attribute. Predefined Attributes. AttributeUsage C# - ATTRIBUTES http://www.tutorialspoint.com/csharp/csharp_attributes.htm Copyright tutorialspoint.com An attribute is a declarative tag that is used to convey information to runtime about the behaviors

More information