Cpt S 122 Data Structures. Introduction to C++ Part II

Size: px
Start display at page:

Download "Cpt S 122 Data Structures. Introduction to C++ Part II"

Transcription

1 Cpt S 122 Data Structures Introduction to C++ Part II Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University

2 Topics Objectives Defining class with a member function Defining a member function with a parameter Data member, set function and get function Initializing objects with constructors Placing Class in a separate file for reusability Software reusability Separating Interface from Implementation

3 Objectives How to define a class and use it to create an object? How to implement a class s behaviors as member function? How to implement class s attributes as a data member? How to call a member function of an object to perform a task? How to use constructor to initialize an object s data when object is created? How to use object of class string?

4 Defining a Class with a Member Function An example that consists of class GradeBook Define a GradeBook object. Function main uses this object and its member function. Member Function displaymessage() display a message on the screen

5 GradeBook Class

6 GradeBook Object

7 Defining a Class with a Member Function (Cont.) The GradeBook class definition begins with keyword class Contains a member function called displaymessage Make an object of class GradeBook Call its displaymessage member function Function main is always called automatically when you execute a program. Call member function displaymessage explicitly to tell it to perform its task.

8 Defining a Class with a Member Function (Cont.) The access-specifier label public: contains the keyword public is an access specifier. Indicates that the function is available to the public can be called by other functions in the program (such as main) by member functions of other classes (if there are any). Access specifiers are always followed by a colon (:).

9 Defining a Member Function with Parameter class GradeBook with a display-message member function displays the course name as part of the welcome message. The new version of displaymessage requires a parameter (coursename ) that represents the course name to output. A variable of type string represents a string of characters. A string is actually an object of the C++ Standard Library class string. Defined in header file <string> and part of namespace std. For now, you can think of string variables like variables of other types such as int.

10 Defining a Member Function with Parameter (Cont.)

11 Defining a Member Function with Parameter (Cont.)

12 Output

13 Defining a Member Function with Parameter Library function getline reads a line of text into a string. The function call getline( cin, nameofcourse ) reads characters from the standard input stream object cin (i.e., the keyboard). places the characters in the string variable nameofcourse The <string> header file must be included in the program to use function getline.

14 Defining Data Members An object has attributes that are carried with it as it s used in a program. Such attributes exist throughout the life of the object. A class normally consists of one or more member functions manipulate the attributes Attributes are represented as variables in a class definition. Such variables are called data members Declared inside a class definition but outside the bodies of the class s member-function definitions. Each object of a class maintains its own copy of its attributes in memory.

15 Data Members, set Functions and get Functions (cont.)

16 Data Members, set Functions and get Functions (cont.)

17 Data Members, set Functions and get Functions (cont.)

18 Private Data Members and Functions Most data-member declarations appear after the accessspecifier label private: Like public, keyword private is an access specifier. Variables or functions declared after access specifier private are accessible only to member functions of the class. The default access for class members is private so all members after the class header and before the first access specifier are private.

19 Points to remember Generally data members should be declared private and member functions should be declared public. An attempt by a function, which is not a member of a particular class (or a friend of that class) to access a private member of that class is a compilation error

20 Data Members (cont.) Declaring data members with access specifier private is known as data hiding. When a program creates (instantiates) an object, its data members are encapsulated (hidden) in the object. accessed only by member functions of the object s class.

21 Mutators and Accessors A client of an object any class or function that calls the object s member functions from outside the object. Calls the class s public member functions to request the class s services. Statements in main call member functions setcoursename, getcoursename and displaymessage on a GradeBook object. Classes often provide public member functions to allow clients of the class to set (i.e., assign values to) or get (i.e., obtain the values of) private data members. These member function names need not begin with set or get. Set functions are also sometimes called mutators mutate, or change, values Get functions are also sometimes called accessors access values

22 Initializing Objects with Constructor Each class can provide a constructor used to initialize an object of the class when the object is created. A constructor is a special member function that must be defined with the same name as the class compiler can distinguish it from the class s other member functions. An important difference between constructors and other functions constructors cannot return values, so they cannot specify a return type (not even void). Normally, constructors are declared public.

23 Initializing Objects with Constructor C++ requires a constructor call for each object that is created helps ensure that each object is initialized before it s used in a program. The constructor call occurs implicitly when the object is created. If a class does not explicitly include a constructor the compiler provides a default constructor. a constructor with no parameters.

24 Initializing Objects with Constructor

25 Initializing Objects with Constructor

26 Initializing Objects with Constructor

27 Initializing Objects with Constructor A constructor specifies in its parameter list the data it requires to perform its task. When you create a new object, you place this data in the parentheses that follow the object name. Constructor s body passes the constructor s parameter name to member function setcoursename simply assigns the value of its parameter to data member coursename.

28 Initializing Objects with Constructor Creates and initializes a GradeBook object called gradebook1. the GradeBook constructor is called (implicitly by C++) with the argument "CS101 Introduction to C++ Programming" initialize gradebook1 s course name.

29 Initializing Objects with Constructor Any constructor that takes no arguments is called a default constructor. A class gets a default constructor in one of two ways: The compiler implicitly creates a default constructor in a class that does not define a constructor. Such a constructor does not initialize the class s data members, but does call the default constructor for each data member An uninitialized variable typically contains a garbage value. You explicitly define a constructor that takes no arguments. Such a default constructor will call the default constructor for each data member Perform additional initialization specified by you. If you define a constructor with arguments, C++ will not implicitly create a default constructor for that class.

30 Observations Data members can be initialized in a constructor. Their values may be set later after the object is created. Good software engineering practice An object is fully initialized before the client code invokes the object s member functions. We should not rely on client code to ensure that an object gets initialized properly.

31 Placing a Class in a Separate File for Reusability One of the benefits of creating class definitions classes can be reused by programmers. potentially worldwide. Programmers who wish to use our GradeBook class cannot simply include the file in another program. function main begins the execution of every program, every program must have exactly one main function.

32 Placing a Class in a Separate File for Reusability Previous examples consists of a single.cpp file, known as a source-code file, Contains a GradeBook class definition and a main function. In an object-oriented C++ program define reusable source code (such as a class) in a file that by convention has a.h filename extension known as a header file. Programs use #include preprocessor directives to include header files take advantage of reusable software components.

33 Placing a Class in a Separate File for Reusability Separates the code into two files GradeBook.h the header file contains only the GradeBook class definition, the appropriate header files and a using declaration. XXX.cpp The main function that uses class GradeBook is defined in the sourcecode file XXX.cpp For the larger programs in industry, we often use a separate source-code file containing function main to test our classes Known as a driver program.

34 Separate header file: GradeBook.h

35 Separate header file: GradeBook.h

36 Separate source code file: source.cpp

37 Placing a Class in a Separate File for Reusability A header file such as GradeBook.h cannot be used to begin program execution It does not contain a main function. To test class GradeBook Need a separate source-code file containing a main function that instantiates and uses objects of the class. To help the compiler understand how to use a class, explicitly provide the compiler with the class s definition For example, to use type string, a program must include the <string> header file. This enables the compiler to determine the amount of memory that it must reserve for each object of the class.

38 Placing a Class in a Separate File for Reusability The compiler creates only one copy of the class s member functions shares that copy among all the class s objects. Each object, of course, needs its own copy of the class s data members contents can vary among objects. The member-function code, however, is not modifiable, so it can be shared among all objects of the class. The size of an object depends on the amount of memory required to store the class s data members.

39 Placing a Class in a Separate File for Reusability Now that the class definition is in a header file (without a main function), we can include that header in any program that needs to reuse our GradeBook class.

40 Placing a Class in a Separate File for Reusability Notice that the name of the GradeBook.h header file in is enclosed in quotes (" ") rather than angle brackets (< >). Normally, a program s source-code files and user-defined header files are placed in the same directory. When the preprocessor encounters a header file name in quotes, attempts to locate the header file in the same directory as the file in which the #include directive appears. If the preprocessor cannot find the header file in that directory, it searches for it in the same location(s) as the C++ Standard Library header files. When the preprocessor encounters a header file name in angle brackets (e.g., <iostream>), it assumes that the header is part of the C++ Standard Library does not look in the directory of the program that is being preprocessed.

41 Separating Interface from Implementation Placing a class definition in a header file reveals the entire implementation of the class to the class s clients. Conventional software engineering wisdom says that to use an object of a class, the client code needs to know only what member functions to call, what arguments to provide to each member function, what return type to expect from each member function, client code does not need to know how those functions are implemented. If client code does know how a class is implemented, the client-code programmer might write client code based on the class s implementation details. Ideally, if that implementation changes, the class s clients should not have to change. Hiding the class s implementation details makes it easier to change the class s implementation while minimizing, and hopefully eliminating, changes to client code.

42 Separating Interface from Implementation Interfaces define and standardize the ways in which things such as people and systems interact with one another. The interface of a class describes what services a class s clients can use how to request those services, but not how the class carries out the services. A class s public interface consists of the class s public member functions (also known as the class s public services).

43 Separating Interface from Implementation In our prior examples, each class definition contained the complete definitions of the class s public member functions and the declarations of its private data members. It s better software engineering to define member functions outside the class definition, Their implementation details can be hidden from the client code. Ensures that you do not write client code that depends on the class s implementation details. Separates class GradeBook s interface from its implementation by splitting the class definition into two files the header file GradeBook.h in which class GradeBook is defined, the source-code file GradeBook.cpp in which GradeBook s member functions are defined.

44 Separating Interface from Implementation By convention, member-function definitions are placed in a source-code file of the same base name (e.g., GradeBook) as the class s header file but with a.cpp filename extension. This three-file program is composed from the perspectives of the GradeBook class programmer and the client-code programmer.

45 Separating Interface from Implementation Header file GradeBook.h is similar to the earlier one, Only the function definitions are replaced here with function prototypes describe the class s public interface without revealing the class s memberfunction implementations. A function prototype is a declaration of a function that tells the compiler the function s name, its return type and the types of its parameters. Include the header file GradeBook.h in the client code provides the compiler with the information it needs to ensure that the client code calls the member functions of class GradeBook correctly.

46 Interface of the class (GradeBook.h file)

47 Implementation of the class Source-code file GradeBook.cpp defines class GradeBook s member functions. Notice that each member-function name in the function headers is preceded by the class name and ::, which is known as the binary scope resolution operator. This ties each member function to the (now separate) GradeBook class definition, declares the class s member functions and data members.

48 Implementation of the class (GradeBook.cpp)

49 Implementation of the class

50 Separating Interface from Implementation To indicate that the member functions in GradeBook.cpp are part of class GradeBook, we must first include the GradeBook.h header file. This allows us to access the class name GradeBook in the GradeBook.cpp file. When compiling GradeBook.cpp, the compiler uses the information in GradeBook.h to ensure that the first line of each member function matches its prototype in the GradeBook.h file, each member function knows about the class s data members and other member functions

51 Implementation of the client code (main.cpp)

52 Separating Interface from Implementation Before executing this program, the source-code files must both be compiled, then linked together the member-function calls in the client code need to be tied to the implementations of the class s member functions a job performed by the linker. The diagram shows the compilation and linking process that results in an executable GradeBook application.

53 Separating Interface from Implementation

54 C++ Standard Library Header Files The C++ Standard Library is divided into many portions, each with its own header file. The header files contain the function prototypes for the related functions that form each portion of the library. The header files also contain definitions of various class types and functions, as well as constants needed by those functions. A header file instructs the compiler on how to interface with library and user-written components. List of some common C++ Standard Library header files.

55 Math Library Functions Sometimes functions are not members of a class. Called global functions. Function prototypes for global functions are placed in header files, the global functions can be reused in any program The <cmath> header file provides a collection of functions enable you to perform common mathematical calculations.

56 Math Library Functions

57 Math Library Functions

58 C++ Standard Library Header

59 C++ Standard Library Header

60 C++ Standard Library Header

61 C++ Standard Library Header

62 C++ Standard Library Header

63 Case Study: Random Number Generation The element of chance can be introduced into computer applications by using the C++ Standard Library function rand. The function rand generates an unsigned integer between 0 and RAND_MAX a symbolic constant defined in the <cstdlib> header file. The value of RAND_MAX must be at least the maximum positive value for a two-byte (16-bit) integer. For GNU C++, the value of RAND_MAX is Visual Studio, the value of RAND_MAX is If rand truly produces integers at random, every number between 0 and RAND_MAX has an equal chance (or probability) of being chosen each time rand is called.

64 Case Study: Random Number Generation The function prototype for the rand function is in <cstdlib>. To produce integers in the range 0 to 5, we use the modulus operator (%) with rand: rand() % 6 This is called scaling. The number 6 is called the scaling factor. Six values are produced. We can shift the range of numbers produced by adding a value.

65 Case Study: Random Number Generation

66 Output

67 Inline Functions C++ provides inline functions to help reduce function call overhead especially for small functions. Placing the qualifier inline before a function s return type in the function definition advises the compiler to generate a copy of the function s code in place (when appropriate) to avoid a function call. Trade-off Multiple copies of the function code are inserted in the program (often making the program larger) Rather than there being a single copy of the function to which control is passed each time the function is called. The complete function definition must appear before the code is inlined so that the compiler knows how to expand a function call into its inlined code.

68 Inline Function

69 Unary Scope Resolution Operator It s possible to declare local and global variables of the same name. C++ provides the unary scope resolution operator (::) to access a global variable when a local variable of the same name is in scope. Using the unary scope resolution operator (::) with a given variable name is optional when the only variable with that name is a global variable.

70 Example: Unary Scope Resolution Operator

71 Test # 1 Statistics Overall Highest 97 Section 1 Average: 77 (Highest 97) Section 2 Average: 73 (Highest 92) Section 3 Average: 73 (Highest 93) Section 4 Average: 74 (Highest 97) Section 5 Average: (Highest 92) Section 6 Average: 70 (Highest 97)

72 Constructors Constructor is a special member function which enables an object to initialize itself when it is created Name is same as the class name Invoked whenever an object of its associated class is created Constructs the values of the data members of the class Destructor is a special member function that destroys the objects when they are no longer required

73 Constructors (Cont.) class integer{ int m,n; public: integer (void); //constructor. }; integer :: integer(void){ //constructor defined m = 0; n = 0; } integer int1; // object int1 created

74 Constructors (Cont.) Not only creates the object int1 of type integer But also initializes its data members m and n to zero. No need to invoke the constructor function. A constructor that accepts no parameters is called a default constructor The default constructor for class integer is class integer :: integer(); If no such constructor is defined then compiler supplies a default constructor.

75 Parameterized Constructors class integer{ int m,n; public: integer (int x, int y); //parameterized constructor. }; integer :: integer(int x, int y){ //constructor defined m = x; n = y; } integer int1 (10, 100); //must pass the initial values when object int1 is declared; implicit call integer int1 = integer (10, 100); //explicit call

76 Multiple Constructors in a Class class integer{ int m, n; public: integer (); // No arguments integer (int, int); // with arguments integer (){ m = 0; n = 0;} //constructor 1 integer (int a; int b){ m = a; n = b;} //constructor 2 integer (integer & i){ m = i.m; n = i.n;} //constructor 3 }; integer I1; // object I1 created integer I2 (20, 40); // object I2 created integer I3 (I2); // object I3 created copies the value of I2 into I3 sets the value of every data element of I3 to value of corresponding data elements of I2. copy constructor

77 Copy Constructor A copy constructor is used to declare and initialize an object from another object integer I3 (I2) define object I3 and at the same time initialize it to the values of I2 Another form is: integer I3 = I2; This process of initializing through a copy constructor is known as copy initialization I3 = I2?? Will not invoke the copy constructor However I3 and I2 are objects; the statement is legal and simply assign the values of I2 to I3; member by member. This is the task of overloaded assignment operator ( = )

78 Destructors Used to destroy the objects that have been created by a constructor Like a constructor, the destructor is a member function whose name is the same name as the class name but is preceded by a tilde For example, the destructor for class integer ~integer(); Destructor never takes any argument nor does it return any values Invoked implicitly by the compiler upon exit from the program to clean up the storage Good practice to declare destructors in a program as it releases memory space for future use

79 Function Overloading C++ enables several functions of the same name to be defined, as long as they have different signatures. This is called function overloading. The C++ compiler selects the proper function to call examining the number, types and order of the arguments in the call. Overloaded functions are distinguished by their signatures. A signature is a combination of a function s name and its parameter types (in order). Function overloading is used to create several functions of the same name perform similar tasks, but on different data types.

80 Function Overloading

81 Example: Function Overloading

82 Initializing an Array in a Declaration with an Initializer List The elements of an array can be initialized in the array declaration by following the array name with an equals sign and a brace-delimited comma-separated list of initializers. An initializer list to initialize an integer array with 10 values. If there are fewer initializers than elements in the array the remaining array elements are initialized to zero. If the array size is omitted from a declaration with an initializer list, the compiler determines the number of elements in the array by counting the number of elements in the initializer list.

83 Initializer List

84 Why Function Templates? If the program logic and operations are identical for each data type overloading may be performed more compactly and conveniently by using function templates.

85 What is Function Template? All function template definitions begin with the template keyword followed by a template parameter list to the function template enclosed in angle brackets (< and >). Every parameter in the template parameter list is preceded by keyword typename or keyword class. The formal type parameters are placeholders for fundamental types or user-defined types. These placeholders are used to specify the types of the function s parameters, to specify the function s return type and to declare variables within the body of the function definition.

86 Example: Function Templates

87 Example: Function Templates

88 Example: Function Templates

89 C++ Standard Library Class Template vector C++ Standard Library class template vector represents a more robust type of array featuring many additional capabilities. C-style pointer-based arrays have great potential for errors and are not flexible A program can easily walk off either end of an array, because C++ does not check whether subscripts fall outside the range of an array. Two arrays cannot be meaningfully compared with equality operators or relational operators. When an array is passed to a general-purpose function designed to handle arrays of any size, the size of the array must be passed as an additional argument. One array cannot be assigned to another with the assignment operator(s). Class template vector allows you to create a more powerful and less error-prone alternative to arrays.

90 C++ Standard Library Class Template vector The mext program example demonstrates capabilities provided by class template vector. Those are not available for C-style pointer-based arrays. Standard class template vector is defined in header <vector> belongs to namespace std.

91 Example: Template Vector

92 Example: Template Vector

93 Example: Template Vector

94 Example: Template Vector

95 Example: Template Vector

96 Example: Template Vector

97 Example: Template Vector

98 Example: Template Vector

99 Example: Template Vector

100 C++ Standard Library Class Template vector By default, all the elements of a vector object are set to 0. vectors can be defined to store any data type. vector member function size obtain the number of elements in the vector. You can use square brackets, [], to access the elements in a vector. vector objects can be compared with one another using the equality operators. You can create a new vector object that is initialized with the contents of an existing vector by using its copy constructor.

101 C++ Standard Library Class Template vector You can use the assignment (=) operator with vector objects. As with C-style pointer-based arrays, C++ does not perform any bounds checking when vector elements are accessed with square brackets. Standard class template vector provides bounds checking in its member function at throws an exception (Exception Handling) if its argument is an invalid subscript.

A A B U n i v e r s i t y

A A B U n i v e r s i t y A A B U n i v e r s i t y Faculty of Computer Sciences O b j e c t O r i e n t e d P r o g r a m m i n g Week 4: Introduction to Classes and Objects Asst. Prof. Dr. M entor Hamiti mentor.hamiti@universitetiaab.com

More information

Object Oriented Design

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

Computer Programming C++ Classes and Objects 6 th Lecture

Computer Programming C++ Classes and Objects 6 th Lecture Computer Programming C++ Classes and Objects 6 th Lecture 엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University Copyrights 2015 Eom, Hyeonsang All Rights Reserved Outline

More information

How to engineer a class to separate its interface from its implementation and encourage reuse.

How to engineer a class to separate its interface from its implementation and encourage reuse. 1 3 Introduction to Classes and Objects 2 OBJECTIVES In this chapter you ll learn: What classes, objects, member functions and data members are. How to define a class and use it to create an object. How

More information

Object Oriented Design

Object Oriented Design Object Oriented Design Chapter 6 Example Activity Diagram 1 Outline Chapter 6 Topics 6.6 C++ Standard Library Header Files 6.14 Inline Functions 6.16 Default Arguments 6.17 Unary Scope Resolution Operator

More information

by Pearson Education, Inc. All Rights Reserved. 2

by Pearson Education, Inc. All Rights Reserved. 2 Suppose you want to drive a car and make it go faster by pressing down on its accelerator pedal. Before you can drive a car, someone has to design it and build it. A car typically begins as engineering

More information

Fundamentals of Programming Session 23

Fundamentals of Programming Session 23 Fundamentals of Programming Session 23 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2013 These slides have been created using Deitel s slides Sharif University of Technology Outlines

More information

Cpt S 122 Data Structures. Course Review Midterm Exam # 2

Cpt S 122 Data Structures. Course Review Midterm Exam # 2 Cpt S 122 Data Structures Course Review Midterm Exam # 2 Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Midterm Exam 2 When: Monday (11/05) 12:10 pm -1pm

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

Cpt S 122 Data Structures. Templates

Cpt S 122 Data Structures. Templates Cpt S 122 Data Structures Templates Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Introduction Function Template Function-template and function-template

More information

Functions and an Introduction to Recursion Pearson Education, Inc. All rights reserved.

Functions and an Introduction to Recursion Pearson Education, Inc. All rights reserved. 1 6 Functions and an Introduction to Recursion 2 Form ever follows function. Louis Henri Sullivan E pluribus unum. (One composed of many.) Virgil O! call back yesterday, bid time return. William Shakespeare

More information

Functions and Recursion

Functions 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

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

Introduction to C++ Systems Programming

Introduction to C++ Systems Programming Introduction to C++ Systems Programming Introduction to C++ Syntax differences between C and C++ A Simple C++ Example C++ Input/Output C++ Libraries C++ Header Files Another Simple C++ Example Inline Functions

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

C++ Programming. Arrays and Vectors. Chapter 6. Objectives. Chiou. This chapter introduces the important topic of data structures collections

C++ Programming. Arrays and Vectors. Chapter 6. Objectives. Chiou. This chapter introduces the important topic of data structures collections C++ Programming Chapter 6 Arrays and Vectors Yih-Peng Chiou Room 617, BL Building (02) 3366-3603 3603 ypchiou@cc.ee.ntu.edu.tw Photonic Modeling and Design Lab. Graduate Institute of Photonics and Optoelectronics

More information

C++ How to Program, 9/e by Pearson Education, Inc. All Rights Reserved.

C++ How to Program, 9/e by Pearson Education, Inc. All Rights Reserved. C++ How to Program, 9/e 1992-2014 by Pearson Education, Inc. Experience has shown that the best way to develop and maintain a large program is to construct it from small, simple pieces, or components.

More information

Chapter 10 Introduction to Classes

Chapter 10 Introduction to Classes C++ for Engineers and Scientists Third Edition Chapter 10 Introduction to Classes CSc 10200! Introduction to Computing Lecture 20-21 Edgardo Molina Fall 2013 City College of New York 2 Objectives In this

More information

Lecture 18 Tao Wang 1

Lecture 18 Tao Wang 1 Lecture 18 Tao Wang 1 Abstract Data Types in C++ (Classes) A procedural program consists of one or more algorithms that have been written in computerreadable language Input and display of program output

More information

Data Structures using OOP C++ Lecture 3

Data Structures using OOP C++ Lecture 3 References: th 1. E Balagurusamy, Object Oriented Programming with C++, 4 edition, McGraw-Hill 2008. 2. Robert L. Kruse and Alexander J. Ryba, Data Structures and Program Design in C++, Prentice-Hall 2000.

More information

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 10/e Education, Inc. All Rights Reserved. Each class you create becomes a new type that can be used to declare variables and create objects. You can declare new classes as needed;

More information

12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension.

12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension. Java How to Program, 9/e Education, Inc. All Rights Reserved. } Covered in this chapter Classes Objects Methods Parameters double primitive type } Create a new class (GradeBook) } Use it to create an object.

More information

Function Call Stack and Activation Records

Function Call Stack and Activation Records 71 Function Call Stack and Activation Records To understand how C performs function calls, we first need to consider a data structure (i.e., collection of related data items) known as a stack. Students

More information

Fundamentals of Programming Session 25

Fundamentals of Programming Session 25 Fundamentals of Programming Session 25 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2014 These slides have been created using Deitel s slides Sharif University of Technology Outlines

More information

Object-Oriented Programming

Object-Oriented Programming - oriented - iuliana@cs.ubbcluj.ro Babes-Bolyai University 2018 1 / 56 Overview - oriented 1 2 -oriented 3 4 5 6 7 8 Static and friend elements 9 Summary 2 / 56 I - oriented was initially created by Bjarne

More information

Functions and Recursion

Functions and Recursion Functions and Recursion 1 Storage Classes Scope Rules Functions with Empty Parameter Lists Inline Functions References and Reference Parameters Default Arguments Unary Scope Resolution Operator Function

More information

C Programming for Engineers Functions

C Programming for Engineers Functions C Programming for Engineers Functions ICEN 360 Spring 2017 Prof. Dola Saha 1 Introduction Real world problems are larger, more complex Top down approach Modularize divide and control Easier to track smaller

More information

Fast Introduction to Object Oriented Programming and C++

Fast Introduction to Object Oriented Programming and C++ Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming

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

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

Ch02. True/False Indicate whether the statement is true or false.

Ch02. True/False Indicate whether the statement is true or false. Ch02 True/False Indicate whether the statement is true or false. 1. The base class inherits all its properties from the derived class. 2. Inheritance is an is-a relationship. 3. In single inheritance,

More information

Object Oriented Design

Object Oriented Design Object Oriented Design Chapter 9 Initializing a non-static data member in the class definition is a syntax error 1 9.2 Time Class Case Study In Fig. 9.1, the class definition is enclosed in the following

More information

Programming for Engineers Functions

Programming for Engineers Functions Programming for Engineers Functions ICEN 200 Spring 2018 Prof. Dola Saha 1 Introduction Real world problems are larger, more complex Top down approach Modularize divide and control Easier to track smaller

More information

CS201 Latest Solved MCQs

CS201 Latest Solved MCQs Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability

More information

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty!

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty! Chapter 6 - Functions return type void or a valid data type ( int, double, char, etc) name parameter list void or a list of parameters separated by commas body return keyword required if function returns

More information

CS201 Some Important Definitions

CS201 Some Important Definitions CS201 Some Important Definitions For Viva Preparation 1. What is a program? A program is a precise sequence of steps to solve a particular problem. 2. What is a class? We write a C++ program using data

More information

AN OVERVIEW OF C++ 1

AN OVERVIEW OF C++ 1 AN OVERVIEW OF C++ 1 OBJECTIVES Introduction What is object-oriented programming? Two versions of C++ C++ console I/O C++ comments Classes: A first look Some differences between C and C++ Introducing function

More information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli (An approved by AICTE and Affiliated to Anna University)

JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli (An approved by AICTE and Affiliated to Anna University) Estd: 1994 JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli - 621014 (An approved by AICTE and Affiliated to Anna University) ISO 9001:2000 Certified Subject Code & Name : CS 1202

More information

by Pearson Education, Inc. All Rights Reserved. 2

by Pearson Education, Inc. All Rights Reserved. 2 Two ways to pass arguments to functions in many programming languages are pass-by-value and pass-by-reference. When an argument is passed by value, a copy of the argument s value is made and passed (on

More information

Chapter 6 Introduction to Defining Classes

Chapter 6 Introduction to Defining Classes Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of

More information

Basic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces

Basic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces Basic memory model Using functions Writing functions Basics Prototypes Parameters Return types Functions and memory Names and namespaces When a program runs it requires main memory (RAM) space for Program

More information

III. Classes (Chap. 3)

III. Classes (Chap. 3) III. Classes III-1 III. Classes (Chap. 3) As we have seen, C++ data types can be classified as: Fundamental (or simple or scalar): A data object of one of these types is a single object. int, double, char,

More information

PIC 10A Objects/Classes

PIC 10A Objects/Classes PIC 10A Objects/Classes Ernest Ryu UCLA Mathematics Last edited: November 13, 2017 User-defined types In C++, we can define our own custom types. Object is synonymous to variable, and class is synonymous

More information

Lecture 7: Classes and Objects CS2301

Lecture 7: Classes and Objects CS2301 Lecture 7: Classes and Objects NADA ALZAHRANI CS2301 1 What is OOP? Object-oriented programming (OOP) involves programming using objects. An object represents an entity in the real world that can be distinctly

More information

Department of Computer science and Engineering Sub. Name: Object oriented programming and data structures Sub. Code: EC6301 Sem/Class: III/II-ECE Staff name: M.Kavipriya Two Mark Questions UNIT-1 1. List

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University

(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University (5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University Key Concepts 2 Object-Oriented Design Object-Oriented Programming

More information

Chapter 3 - Functions

Chapter 3 - Functions Chapter 3 - Functions 1 Outline 3.1 Introduction 3.2 Program Components in C++ 3.3 Math Library Functions 3.4 Functions 3.5 Function Definitions 3.6 Function Prototypes 3.7 Header Files 3.8 Random Number

More information

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING 1. Object Oriented Programming Paradigms 2. Comparison of Programming Paradigms 3. Basic Object Oriented Programming

More information

SFU CMPT Topic: Classes

SFU CMPT Topic: Classes SFU CMPT-212 2008-1 1 Topic: Classes SFU CMPT-212 2008-1 Topic: Classes Ján Maňuch E-mail: jmanuch@sfu.ca Friday 15 th February, 2008 SFU CMPT-212 2008-1 2 Topic: Classes Encapsulation Using global variables

More information

CE221 Programming in C++ Part 1 Introduction

CE221 Programming in C++ Part 1 Introduction CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab

More information

엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University COPYRIGHTS 2017 EOM, HYEONSANG ALL RIGHTS RESERVED

엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University COPYRIGHTS 2017 EOM, HYEONSANG ALL RIGHTS RESERVED 엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University COPYRIGHTS 2017 EOM, HYEONSANG ALL RIGHTS RESERVED Outline - Function Definitions - Function Prototypes - Data

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

Jayaram college of Engineering and Technology, Pagalavadi. CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT

Jayaram college of Engineering and Technology, Pagalavadi. CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT Two Mark Questions UNIT - I 1. DEFINE ENCAPSULATION. Encapsulation is the process of combining data and functions

More information

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

QUIZ How do we implement run-time constants and. compile-time constants inside classes?

QUIZ How do we implement run-time constants and. compile-time constants inside classes? QUIZ How do we implement run-time constants and compile-time constants inside classes? Compile-time constants in classes The static keyword inside a class means there s only one instance, regardless of

More information

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Dr. Marenglen Biba Laboratory Session: Exercises on classes Analogy to help you understand classes and their contents. Suppose you want to drive a car and make it go faster by pressing down

More information

C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

More information

Object-Oriented Design (OOD) and C++

Object-Oriented Design (OOD) and C++ Chapter 2 Object-Oriented Design (OOD) and C++ At a Glance Instructor s Manual Table of Contents Chapter Overview Chapter Objectives Instructor Notes Quick Quizzes Discussion Questions Projects to Assign

More information

Chapter 2 Basic Elements of C++

Chapter 2 Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 2-1 Chapter 2 Basic Elements of C++ At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion

More information

Constructors and Destructors. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Constructors and Destructors. OOC 4 th Sem, B Div Prof. Mouna M. Naravani Constructors and Destructors OOC 4 th Sem, B Div 2016-17 Prof. Mouna M. Naravani A constructor guarantees that an object created by the class will be initialized automatically. Ex: create an object integer

More information

Chapter 15 - C++ As A "Better C"

Chapter 15 - C++ As A Better C Chapter 15 - C++ As A "Better C" Outline 15.1 Introduction 15.2 C++ 15.3 A Simple Program: Adding Two Integers 15.4 C++ Standard Library 15.5 Header Files 15.6 Inline Functions 15.7 References and Reference

More information

Data Structures (list, dictionary, tuples, sets, strings)

Data Structures (list, dictionary, tuples, sets, strings) Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in brackets: l = [1, 2, "a"] (access by index, is mutable sequence) Tuples are enclosed in parentheses: t = (1, 2, "a") (access

More information

Quiz Start Time: 09:34 PM Time Left 82 sec(s)

Quiz Start Time: 09:34 PM Time Left 82 sec(s) Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability

More information

Introduction Of Classes ( OOPS )

Introduction Of Classes ( OOPS ) Introduction Of Classes ( OOPS ) Classes (I) A class is an expanded concept of a data structure: instead of holding only data, it can hold both data and functions. An object is an instantiation of a class.

More information

CS304 Object Oriented Programming Final Term

CS304 Object Oriented Programming Final Term 1. Which of the following is the way to extract common behaviour and attributes from the given classes and make a separate class of those common behaviours and attributes? Generalization (pg 29) Sub-typing

More information

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 12: Classes and Data Abstraction

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 12: Classes and Data Abstraction C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 12: Classes and Data Abstraction Objectives In this chapter, you will: Learn about classes Learn about private, protected,

More information

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++

More information

Chapter 4 Defining Classes I

Chapter 4 Defining Classes I Chapter 4 Defining Classes I This chapter introduces the idea that students can create their own classes and therefore their own objects. Introduced is the idea of methods and instance variables as the

More information

Introduction to C++ Introduction to C++ 1

Introduction to C++ Introduction to C++ 1 1 What Is C++? (Mostly) an extension of C to include: Classes Templates Inheritance and Multiple Inheritance Function and Operator Overloading New (and better) Standard Library References and Reference

More information

Functions in C++ Problem-Solving Procedure With Modular Design C ++ Function Definition: a single

Functions in C++ Problem-Solving Procedure With Modular Design C ++ Function Definition: a single Functions in C++ Problem-Solving Procedure With Modular Design: Program development steps: Analyze the problem Develop a solution Code the solution Test/Debug the program C ++ Function Definition: A module

More information

Programming C++ Lecture 2. Howest, Fall 2014 Instructor: Dr. Jennifer B. Sartor

Programming C++ Lecture 2. Howest, Fall 2014 Instructor: Dr. Jennifer B. Sartor Programming C++ Lecture 2 Howest, Fall 2014 Instructor: Dr. Jennifer B. Sartor Jennifer.sartor@elis.ugent.be S Arrays and Pointers void myprint(const char *); int main() { char *phrasey = C++Fun ; myprint(phrasey);

More information

7.1 Optional Parameters

7.1 Optional Parameters Chapter 7: C++ Bells and Whistles A number of C++ features are introduced in this chapter: default parameters, const class members, and operator extensions. 7.1 Optional Parameters Purpose and Rules. Default

More information

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Fundamental Concepts and Definitions

Fundamental Concepts and Definitions Fundamental Concepts and Definitions Identifier / Symbol / Name These terms are synonymous: they refer to the name given to a programming component. Classes, variables, functions, and methods are the most

More information

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

KOM3191 Object Oriented Programming Dr Muharrem Mercimek OPERATOR OVERLOADING. KOM3191 Object-Oriented Programming

KOM3191 Object Oriented Programming Dr Muharrem Mercimek OPERATOR OVERLOADING. KOM3191 Object-Oriented Programming KOM3191 Object Oriented Programming Dr Muharrem Mercimek 1 OPERATOR OVERLOADING KOM3191 Object-Oriented Programming KOM3191 Object Oriented Programming Dr Muharrem Mercimek 2 Dynamic Memory Management

More information

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

More information

Introduction to Classes and Objects Pearson Education, Inc. All rights reserved.

Introduction to Classes and Objects Pearson Education, Inc. All rights reserved. 1 3 Introduction to Classes and Objects 2 You will see something new. Two things. And I call them Thing One and Thing Two. Dr. Theodor Seuss Geisel Nothing can have value without being an object of utility.

More information

Operator overloading

Operator overloading 1 Introduction 2 The copy constructor 3 Operator Overloading 4 Eg 1: Adding two vectors 5 The -> operator 6 The this pointer 7 Overloading = 8 Unary operators 9 Overloading for the matrix class 10 The

More information

C++ Programming Fundamentals

C++ Programming Fundamentals C++ Programming Fundamentals 269 Elvis C. Foster Lecture 11: Templates One of the contemporary sophistries of C++ programming is defining and manipulating templates. This lecture focuses on this topic.

More information

Introduction to Classes and Objects Pearson Education, Inc. All rights reserved.

Introduction to Classes and Objects Pearson Education, Inc. All rights reserved. 1 3 Introduction to Classes and Objects 2 You will see something new. Two things. And I call them Thing One and Thing Two. Dr. Theodor Seuss Geisel Nothing can have value without being an object of utility.

More information

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017 Overview of OOP Dr. Zhang COSC 1436 Summer, 2017 7/18/2017 Review Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in square brackets: l = [1, 2, "a"] (access by index, is mutable

More information

Lecture 7. Log into Linux New documents posted to course webpage

Lecture 7. Log into Linux New documents posted to course webpage Lecture 7 Log into Linux New documents posted to course webpage Coding style guideline; part of project grade is following this Homework 4, due on Monday; this is a written assignment Project 1, due next

More information

Objectives. In this chapter, you will:

Objectives. In this chapter, you will: Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about

More information

CHAPTER 4 FUNCTIONS. 4.1 Introduction

CHAPTER 4 FUNCTIONS. 4.1 Introduction CHAPTER 4 FUNCTIONS 4.1 Introduction Functions are the building blocks of C++ programs. Functions are also the executable segments in a program. The starting point for the execution of a program is main

More information

The SPL Programming Language Reference Manual

The SPL Programming Language Reference Manual The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming

More information

Abstract Data Types (ADTs) 1. Legal Values. Client Code for Rational ADT. ADT Design. CS 247: Software Engineering Principles

Abstract Data Types (ADTs) 1. Legal Values. Client Code for Rational ADT. ADT Design. CS 247: Software Engineering Principles Abstract Data Types (ADTs) CS 247: Software Engineering Principles ADT Design An abstract data type (ADT) is a user-defined type that bundles together: the range of values that variables of that type can

More information

An Introduction to C++

An Introduction to C++ An Introduction to C++ Introduction to C++ C++ classes C++ class details To create a complex type in C In the.h file Define structs to store data Declare function prototypes The.h file serves as the interface

More information

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE? 1. Describe History of C++? The C++ programming language has a history going back to 1979, when Bjarne Stroustrup was doing work for his Ph.D. thesis. One of the languages Stroustrup had the opportunity

More information

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity. OOPS Viva Questions 1. What is OOPS? OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.

More information

Introduction to Classes and Objects

Introduction to Classes and Objects 1 2 Introduction to Classes and Objects You will see something new. Two things. And I call them Thing One and Thing Two. Dr. Theodor Seuss Geisel Nothing can have value without being an object of utility.

More information

The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language

More information

QUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file?

QUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file? QUIZ on Ch.5 Why is it sometimes not a good idea to place the private part of the interface in a header file? Example projects where we don t want the implementation visible to the client programmer: The

More information

KOM3191 Object Oriented Programming Dr Muharrem Mercimek ARRAYS ~ VECTORS. KOM3191 Object-Oriented Computer Programming

KOM3191 Object Oriented Programming Dr Muharrem Mercimek ARRAYS ~ VECTORS. KOM3191 Object-Oriented Computer Programming KOM3191 Object Oriented Programming Dr Muharrem Mercimek 1 ARRAYS ~ VECTORS KOM3191 Object-Oriented Computer Programming KOM3191 Object Oriented Programming Dr Muharrem Mercimek 2 What is an array? Arrays

More information

STRUCTURING OF PROGRAM

STRUCTURING OF PROGRAM Unit III MULTIPLE CHOICE QUESTIONS 1. Which of the following is the functionality of Data Abstraction? (a) Reduce Complexity (c) Parallelism Unit III 3.1 (b) Binds together code and data (d) None of the

More information

Variables. Data Types.

Variables. Data Types. Variables. Data Types. The usefulness of the "Hello World" programs shown in the previous section is quite questionable. We had to write several lines of code, compile them, and then execute the resulting

More information

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value Paytm Programming Sample paper: 1) A copy constructor is called a. when an object is returned by value b. when an object is passed by value as an argument c. when compiler generates a temporary object

More information

CS 247: Software Engineering Principles. ADT Design

CS 247: Software Engineering Principles. ADT Design CS 247: Software Engineering Principles ADT Design Readings: Eckel, Vol. 1 Ch. 7 Function Overloading & Default Arguments Ch. 12 Operator Overloading U Waterloo CS247 (Spring 2017) p.1/17 Abstract Data

More information