OBJECT-ORIENTED PROGRAMMING CONCEPTS-CLASSES II
|
|
- Lucas Palmer
- 5 years ago
- Views:
Transcription
1 KOM3191 Object Oriented Programming Dr Muharrem Mercimek 1 OBJECT-ORIENTED PROGRAMMING CONCEPTS-CLASSES II KOM3191 Object-Oriented Programming
2 KOM3191 Object Oriented Programming Dr Muharrem Mercimek 2 Function Pointers A pointer to a function contains the address of the function in memory The name of an array is actually the address in memory of the first element of the array The name of a function is actually the starting address in memory of the code that performs the function's task Pointers to functions can be passed to functions, returned from functions, stored in arrays and assigned to other function pointers. Array names are pointers Function names are function pointers int (*operationptr)(int,int); operationptr is a function pointer variable and can point out the starting address of a function code.
3 KOM3191 Object Oriented Programming Dr Muharrem Mercimek 3 Arrays of Function Pointers int addition (int a, int b) { return (a+b); } int subtraction (int a, int b) { return (a-b); } int operation (int x, int y, int (*functionptr)(int,int)) { int g = (*functionptr)(x,y); return (g); } int main () { int m,n; int (*operationptr)(int,int); operationptr= addition; cout<< (*operationptr)(7,5)<<endl; //12 cout<< (*addition)(7,5)<<endl; //12 cout<< addition(7,5)<<endl; //12 m = operation (7, 5, operationptr); cout << m <<endl; //12 operationptr= subtraction; cout<< (*operationptr)(7,5)<<endl; //2 n = operation (7, 5, operationptr); cout << n <<endl; //2 return 0; }
4 KOM3191 Object Oriented Programming Dr Muharrem Mercimek 4 Arrays of Function Pointers int function0 (int a, int b) { return (a+b); } int function1 (int a, int b) { return (a-b); } int main () { int m,n; int (* operationptr[2])(int,int)={function0, function1} } for (int i=0; i<2; i++) cout<< (*operationptr[i])(7,5)<<endl; return 0;
5 KOM3191 Object Oriented Programming Dr Muharrem Mercimek 5 Pointer-Based String Processing char color[] = "blue"; const char *colorptr = "blue"; The first declaration creates a five-element array color containing the characters 'b', 'l', 'u', 'e' and '\0'. The second declaration creates pointer variable colorptr that points to the letter b in the string "blue" (which ends in '\0') somewhere in memory. When declaring a character array to contain a string, the array must be large enough to store the string and its terminating null character. The preceding declaration determines the size of the array, based on the number of initializers provided in the initializer list. Not allocating sufficient space in a character array to store the null character that terminates a string is an error. C++ allows strings of any length to be stored. If a string is longer than the character array in which it is to be stored, characters beyond the end of the array will overwrite data in memory following the array, leading to logic errors.
6 KOM3191 Object Oriented Programming Dr Muharrem Mercimek 6 String-manipulation functions char name[ 8 ]; cin>> name; //super_man cout<<name<<endl; //*** stack smashing detected ***: char name[ 8 ]; cin>>setw(8)>>name; cout<<name<<endl; //super_man //output is super_m char name[ 8 ]; cin.getline(name, 8, '\n' ); cout<<name<<endl; // super_man // output is super_m The function stops reading characters when the delimiter character '\n' is encountered, when the endof-file indicator is entered or when the number of characters read so far is one less than the length specified in the second argument. cin.getline( sentence, 8 ); same as cin.getline(name, 8, '\n' );
7 KOM3191 Object Oriented Programming Dr Muharrem Mercimek 7 String-manipulation functions String-manipulation functions of the string-handling library. <cstring> header file char *strcpy( char *s1, const char *s2 ); char *strncpy( char *s1, const char *s2, size_t n ); char *strcat( char *s1, const char *s2 ); char *strncat( char *s1, const char *s2, size_t n ); int strcmp( const char *s1, const char *s2 ); int strncmp( const char *s1, const char *s2, size_t n ); char *strtok( char *s1, const char *s2 ); size_t strlen( const char *s );
8 KOM3191 Object Oriented Programming Dr Muharrem Mercimek 8 OBJECT-ORIENTED PROGRAMMING CONCEPTS-CLASSES II
9 KOM3191 Object Oriented Programming Dr Muharrem Mercimek 9 A class example Data members of a class cannot be initialized where they are declared Static data members are known as class variables classname::static_data_member "preprocessor wrapper If the header has not been included previously in a file, the name TIME_H is defined by the #define directive and the header file statements are included.
10 KOM3191 Object Oriented Programming Dr Muharrem Mercimek 10 A class example There can be several overloaded constructors, initialization of the data members through constructors are highly recommended When setting the values of the data members there should be a validation. A consistent value should used. fixed, setprecision( ), setfill( ) : sticky settings setw( ), left, right only effects the next value.
11 KOM3191 Object Oriented Programming Dr Muharrem Mercimek 11 A class example Standard Time 11:59 pm 23:59 12:00 am (midnight) 00:00 12:01 am 00:01 01:00 am 01:00 02:00 am 02:00 10:00 am 10:00 11:00 am 11:00 11:59 am 11:59 12:00 pm (noon) 12:00 12:01 pm 12:01 01:00 pm 13:00 02:00 pm 14:00 10:00 pm 22:00 11:00 pm 23:00
12 KOM3191 Object Oriented Programming Dr Muharrem Mercimek 12 A class example Possible ways to instantiate a Class An object Time sunset; A reference to an object Time &dinnertime=sunset; An array of objects Time arrayoftimes[5]; A pointer to an object Time *timeptr=&sunset;
13 KOM3191 Object Oriented Programming Dr Muharrem Mercimek 13 Member functions vs Global functions void Time::printUniversal(){...} void Time::printStandard() {...} printuniversal and printstandard member functions take no arguments. The member functions of a class implicitly know that they are to use data members of the particular class object for which they are invoked. This can make member function calls more concise than conventional function calls in procedural programming. Member functions are usually shorter than functions in non-object-oriented programs, because the data stored in data members have ideally been validated by a constructor or by member functions that store new data. Because the data is already in the object, the member-function calls often have no arguments or at least have fewer arguments than typical function calls in non-objectoriented languages. Thus, the calls are shorter, the function definitions are shorter and the function prototypes are shorter. This facilitates many aspects of program development.
14 KOM3191 Object Oriented Programming Dr Muharrem Mercimek 14 Class Scope Member functions declared in a class definition are within the class s scope. Member functions are tied to the class scope via scope resolution operator :: Member function defined in the body of a class definition C++ compiler attempts to inline calls to the member function. Only the simplest and most stable member functions (i.e., whose implementations are unlikely to change) should be defined in the class header. Data members: Variables declared in the class definition. Member functions: Functions declared in the class definition. are in the class scope Non-member functions are defined at file scope. Local variables declared within each member function have block scope Hiding a class-scope variable can be prevented with use of ::
15 KOM3191 Object Oriented Programming Dr Muharrem Mercimek 15 Class Scope Within a class s scope Class members can be used by all member functions. Outside a class s scope public class members are referenced through a handle: An object name A reference to an object A pointer to an object. Dot member selection operator (.) Used with an object s name or with a reference to an object. Arrow member selection operator (->) Accesses the object s members. Time sunset; sunset.printuniversal(); Time *timeptr=&sunset; timeptr printuniversal();
16 KOM3191 Object Oriented Programming Dr Muharrem Mercimek 16 size of an object Objects contain only data, so objects are much smaller than if they also contained member functions. Applying operator sizeof to a class name or to an object of that class will report only the size of the class s data members. The compiler creates one copy (only) of the member functions separate from all objects of the class. All objects of the class share this one copy. Each object, of course, needs its own copy of the class s data, because the data can vary among the objects. The function code is non-modifiable and, hence, can be shared among all objects of one class.
17 KOM3191 Object Oriented Programming Dr Muharrem Mercimek 17 Access and utility functions of a class Access functions read or display data test the truth or falsity of conditions. e.g isempty function Utility functions (also called helper functions) private member functions that support the operation of the class s public member functions. Not part of a class s public interface Not intended to be used by clients of a class.
18 KOM3191 Object Oriented Programming Dr Muharrem Mercimek 18 Access and utility functions of a class
19 KOM3191 Object Oriented Programming Dr Muharrem Mercimek 19 Access and utility functions of a class
20 KOM3191 Object Oriented Programming Dr Muharrem Mercimek 20 Constructor with default arguments //Time.h Time( int = 0, int = 0, int = 0 ); // default constructor //Time.cpp Time::Time( int hr, int min, int sec ) { settime( hr, min, sec ); // validate and set time } //test_time.cpp int main() { Time t1; // all arguments defaulted Time t2( 2 ); // hour specified; minute and second defaulted Time t3( 21, 34 ); // hour and minute specified; second defaulted Time t4( 12, 25, 42 ); // hour, minute and second specified Time t5( 27, 74, 99 ); // all bad values specified... }
Chapter 9 Classes : A Deeper Look, Part 1
Chapter 9 Classes : A Deeper Look, Part 1 C++, How to Program Deitel & Deitel Fall 2016 CISC1600 Yanjun Li 1 Time Class Case Study Time Class Definition: private data members: int hour; int minute; int
More informationMore C++ Classes. Systems Programming
More C++ Classes Systems Programming C++ Classes Preprocessor Wrapper Time Class Case Study Class Scope and Assessing Class Members Using handles to access class members Access and Utility Functions Destructors
More informationClasses: A Deeper Look
Classes: A Deeper Look 1 Introduction Implementing a Time Abstract Data Type with a class Class Scope and Accessing Class Members Separating Interface from Implementation Controlling Access to Members
More informationIntroduction to Programming session 24
Introduction to Programming session 24 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2010 These slides are created using Deitel sslides Sharif Universityof Technology Outlines Introduction
More informationIS 0020 Program Design and Software Tools
1 IS 0020 Program Design and Software Tools Introduction to C++ Programming Lecture 5: Classes September 14, 2004 Structure Definitions 2 Structures Aggregate data types built using elements of other types
More informationKOM3191 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 informationComputer Programming with C++ (21)
Computer Programming with C++ (21) Zhang, Xinyu Department of Computer Science and Engineering, Ewha Womans University, Seoul, Korea zhangxy@ewha.ac.kr Classes (III) Chapter 9.7 Chapter 10 Outline Destructors
More informationObject 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 informationPreview 9/20/2017. Object Oriented Programing with C++ Object Oriented Programing with C++ Object Oriented Programing with C++
Preview Object Oriented Programming with C++ Class Members Inline Functions vs. Regular Functions Constructors & Destructors Initializing class Objects with Constructors C++ Programming Language C Programming
More informationFundamentals of Programming Session 24
Fundamentals of Programming Session 24 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 informationA Deeper Look at Classes
A Deeper Look at Classes Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++, by
More information1 // Fig. 6.13: time2.cpp 2 // Member-function definitions for class Time. 3 #include <iostream> Outline. 4 5 using std::cout; 6 7 #include <iomanip>
CISC11 Introduction to Computer Science Dr. McCoy Lecture 20 November, 2009. Using Default Arguments with Constructors Constructors Can specify default arguments Default constructors Defaults all arguments
More informationOBJECT-ORIENTED PROGRAMMING CONCEPTS-CLASSES IV
KOM3191 Object Oriented Programming Dr Muharrem Mercimek 1 OBJECT-ORIENTED PROGRAMMING CONCEPTS-CLASSES IV KOM3191 Object-Oriented Programming KOM3191 Object Oriented Programming Dr Muharrem Mercimek 2
More informationIS 0020 Program Design and Software Tools
1 IS 0020 Program Design and Software Tools Introduction to C++ Programming Lecture 3: Classes May 24, 2004 2 Classes Structure Definitions 3 Structures Aggregate data types built using elements of other
More informationPointer Assignments. CISC181 Introduction to Computer Science. Dr. McCoy. Lecture 18 October 29, The new Operator
CISC11 Introduction to Computer Science Dr. McCoy Lecture 1 October 29, 2009 Pointer Assignments Pointer variables can be "assigned": int *p1, *p2; p2 = p1; Assigns one pointer to another "Make p2 point
More informationClasses: A Deeper Look. Systems Programming
Classes: A Deeper Look Systems Programming Deeper into C++ Classes const objects and const member functions Composition Friendship this pointer Dynamic memory management new and delete operators static
More informationIS 0020 Program Design and Software Tools
1 IS 0020 Program Design and Software Tools Introduction to C++ Programming Lecture 3 Jan 20, 2004 Quiz 1 2 Average: about 3.8 More than half obtained: 4 + Highest is 8 Need more work/practice! Quiz 1
More informationStrings in C++ Dr. Ferdin Joe John Joseph Kamnoetvidya Science Academy
Strings in C++ Dr. Ferdin Joe John Joseph Kamnoetvidya Science Academy Using Strings in C++ Programs String library or provides functions to: - manipulate strings - compare strings -
More informationClasses and Data Abstraction
6 Classes and Data Abstraction Objectives To understand the software engineering concepts of encapsulation and data hiding. To understand the notions of data abstraction and abstract data types (ADTs).
More informationW8.1 Continuing Classes friend Functions and friend Classes Using the this Pointer Cascading Function Calls
1 W8.1 Continuing Classes friend Functions and friend Classes Using the this Pointer Cascading Function Calls 2 7.4 friend Functions and friend Classes friend function and friend classes Can access private
More information9.1 Introduction. Integrated Time class case study Preprocessor wrapper Three types of handles on an object. Class functions
1 9 Classes: A Deeper Look, Part 1 OBJECTIVES In this chapter you ll learn: How to use a preprocessor p wrapper to prevent multiple definition errors caused by including more than one copy of a header
More informationChapter 6: Classes and Data Abstraction
Chapter 6: Classes and Data Abstraction 1 6.1 Introduction 6.2 Structure Definitions 6.3 Accessing Structure Members 6.4 Implementing a User-Defined Type Time with a struct 6.5 Implementing a Time Abstract
More informationClasses and Data Abstraction. Topic 5
Classes and Data Abstraction Topic 5 Classes Class User Defined Data Type Object Variable Data Value Operations Member Functions Object Variable Data Value Operations Member Functions Object Variable Data
More informationC++ Programming Chapter 7 Pointers
C++ Programming Chapter 7 Pointers Yih-Peng Chiou Room 617, BL Building (02) 3366-3603 ypchiou@cc.ee.ntu.edu.tw Photonic Modeling and Design Lab. Graduate Institute of Photonics and Optoelectronics & Department
More informationC How to Program, 6/e by Pearson Education, Inc. All Rights Reserved. 1
C How to Program, 6/e 1 Structures : Aggregate data types are built using elements of other types struct Time { int hour; int minute; Members of the same structure must have unique names. Two different
More informationKOM3191 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 informationComputer Programming Class Members 9 th Lecture
Computer Programming Class Members 9 th Lecture 엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University Copyrights 2015 Eom, Hyeonsang All Rights Reserved Outline Class
More information! Data is stored in variables. - Perhaps using arrays and structs. ! Program is a collection of functions that perform
Ch 13: Introduction to Classes 13.1 Procedural Programming! Data is stored in variables CS 2308 Fall 2012 Jill Seaman - Perhaps using arrays and structs.! Program is a collection of functions that perform
More informationPreview 11/1/2017. Constant Objects and Member Functions. Constant Objects and Member Functions. Constant Objects and Member Functions
Preview Constant Objects and Constant Functions Composition: Objects as Members of a Class Friend functions The use of Friend Functions Some objects need to be modifiable and some do not. A programmer
More information57:017, Computers in Engineering C++ Classes
57:017, Computers in Engineering C++ Classes Copyright 1992 2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Introduction Object-oriented programming (OOP) Encapsulates
More informationl A class in C++ is similar to a structure. - It allows you to define a new (composite) data type. l A class contains the following: - variables AND
Introduction to Classes 13.2 The Class Unit 4 Chapter 13 CS 2308 Fall 2016 Jill Seaman 1 l A class in C++ is similar to a structure. - It allows you to define a new (composite) data type. l A class contains
More informationChapter 5 - Pointers and Strings
Chapter 5 - Pointers and Strings 1 5.1 Introduction 5.2 Pointer Variable Declarations and Initialization 5.3 Pointer Operators 5.4 Calling Functions by Reference 5.5 Using const with Pointers 5.6 Bubble
More information! Data is stored in variables. - Perhaps using arrays and structs. ! Program is a collection of functions that perform
Ch 13: Introduction to Classes 13.1 Procedural Programming! Data is stored in variables CS 2308 Spring 2013 Jill Seaman - Perhaps using arrays and structs.! Program is a collection of functions that perform
More information! Data is stored in variables. - Perhaps using arrays and structs. ! Program is a collection of functions that perform
Ch 13: Introduction to Classes 13.1 Procedural Programming! Data is stored in variables CS 2308 Spring 2015 Jill Seaman - Perhaps using arrays and structs.! Program is a collection of functions that perform
More informationC: Arrays, and strings. Department of Computer Science College of Engineering Boise State University. September 11, /16
Department of Computer Science College of Engineering Boise State University September 11, 2017 1/16 1-dimensional Arrays Arrays can be statically declared in C, such as: int A [100]; The space for this
More informationChapter 5 - Pointers and Strings
Chapter 5 - Pointers and Strings 1 5.1 Introduction 2 5.1 Introduction 5.2 Pointer Variable Declarations and Initialization 5.3 Pointer Operators 5. Calling Functions by Reference 5.5 Using const with
More informationby Pearson Education, Inc. All Rights Reserved.
The string-handling library () provides many useful functions for manipulating string data (copying strings and concatenating strings), comparing strings, searching strings for characters and
More informationOBJECT-ORIENTED PROGRAMMING CONCEPTS-CLASSES III
KOM3191 Object Oriented Programming Dr Muharrem Mercimek 1 OBJECT-ORIENTED PROGRAMMING CONCEPTS-CLASSES III KOM3191 Object-Oriented Programming KOM3191 Object Oriented Programming Dr Muharrem Mercimek
More informationBITG 1113: Array (Part 2) LECTURE 9
BITG 1113: Array (Part 2) LECTURE 9 1 LEARNING OUTCOMES At the end of this lecture, you should be able to: 1. Describe the fundamentals of C-strings (character arrays) 2. Use C-string functions 3. Use
More informationIS 0020 Program Design and Software Tools
1 Program Components in C++ 2 IS 0020 Program Design and Software Tools Introduction to C++ Programming Lecture 2 Functions and Arrays Jan 13, 200 Modules: functionsand classes Programs use new and prepackaged
More information1 Pointer Concepts. 1.1 Pointer Examples
1 1 Pointer Concepts What are pointers? How are they used? Point to a memory location. Call by reference is based on pointers. Operators: & Address operator * Dereferencing operator Machine/compiler dependencies
More information! Data is stored in variables. - Perhaps using arrays and structs. ! Program is a collection of functions that perform
Ch 13: Introduction to Classes 13.1 Procedural Programming Data is stored in variables CS 2308 Spring 2014 Jill Seaman - Perhaps using arrays and structs. Program is a collection of functions that perform
More information! Data is stored in variables. - Perhaps using arrays and structs. ! Program is a collection of functions that perform
Ch 13: Introduction to Classes 13.1 Procedural Programming! Data is stored in variables CS 2308 Fall 2013 Jill Seaman - Perhaps using arrays and structs.! Program is a collection of functions that perform
More informationFig. 7.1 Fig. 7.2 Fig. 7.3 Fig. 7.4 Fig. 7.5 Fig. 7.6 Fig. 7.7 Fig. 7.8 Fig. 7.9 Fig. 7.10
CHAPTER 7 CLASSES: PART II 1 Illustrations List (Main Page) Fig. 7.1 Fig. 7.2 Fig. 7.3 Fig. 7.4 Fig. 7.5 Fig. 7.6 Fig. 7.7 Fig. 7.8 Fig. 7.9 Fig. 7.10 Using a Time class with const objects and const member
More informationShort 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 informationObject Oriented Design
Object Oriented Design Lecture 3: Introduction to C++ (Continue) Examples using declarations that eliminate the need to repeat the std:: prefix 1 Examples using namespace std; enables a program to use
More informationCS201 - 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 informationC++ Arrays. Arrays: The Basics. Areas for Discussion. Arrays: The Basics Strings and Arrays of Characters Array Parameters
C++ Arrays Areas for Discussion Strings and Joseph Spring/Bob Dickerson School of Computer Science Operating Systems and Computer Networks Lecture Arrays 1 Lecture Arrays 2 To declare an array: follow
More informationChapter 16: Classes and Data Abstraction
Chapter 16: Classes and Data Abstraction 16.1 Introduction 16.2 Implementing a Time Abstract Data Type with a Class 16.3 Class Scope and Accessing Class Members 16.4 Separating Interface from Implementation
More informationLecture 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 informationCourse "Data Processing" Name: Master-1: Nuclear Energy Session /2018 Examen - Part A Page 1
Examen - Part A Page 1 1. mydir directory contains three files: filea.txt fileb.txt filec.txt. How many files will be in the directory after performing the following operations: $ ls filea.txt fileb.txt
More informationl A class in C++ is similar to a structure. - It allows you to define a new (composite) data type. l A class contains the following: - variables AND
Introduction to Classes 13.2 The Class Unit 4 Chapter 13 CS 2308 Spring 2017 Jill Seaman 1 l A class in C++ is similar to a structure. - It allows you to define a new (composite) data type. l A class contains
More informationBuilt-in Functions for NTCAs.
Built-in Functions for NTCAs strlen char array[10] = Hello ; int length = strlen(array); cout
More informationFast 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 informationl A class in C++ is similar to a structure. l A class contains members: - variables AND - public: accessible outside the class.
Classes and Objects Week 5 Gaddis:.2-.12 14.3-14.4 CS 5301 Spring 2018 Jill Seaman The Class l A class in C++ is similar to a structure. l A class contains members: - variables AND - functions (often called
More informationStrings and Streams. Professor Hugh C. Lauer CS-2303, System Programming Concepts
Strings and Streams Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++, by Walter
More informationChapter 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 informationG205 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 informationC: Pointers, Arrays, and strings. Department of Computer Science College of Engineering Boise State University. August 25, /36
Department of Computer Science College of Engineering Boise State University August 25, 2017 1/36 Pointers and Arrays A pointer is a variable that stores the address of another variable. Pointers are similar
More informationChapter 17 - C++ Classes: Part II
Chapter 17 - C++ Classes: Part II 17.1 Introduction 17.2 const (Constant) Objects and const Member Functions 17.3 Composition: Objects as Members of Classes 17.4 friend Functions and friend Classes 17.5
More informationJava 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 informationLecture 5. Function Pointers
Lecture 5 Pointers to functions Complicated declarations Allocating and deallocating memory Classes const member functions Constructors and destructor this pointer static members Templates Lec 5 Programming
More informationClasses: A Deeper Look, Part 2
10 But what, to serve our private ends, Forbids the cheating of our friends? Charles Churchill Instead of this absurd division into sexes they ought to class people as static and dynamic. Evelyn Waugh
More informationClasses and Objects. Types and Classes. Example. Object Oriented Programming
Classes and Objects Types and Classes Chapter 6 Object Oriented program development. Read this Chapter 7 Classes Read this Chapter 8 More About Classes Some sections will be assigned later Chapter 9 Inheritance.
More informationC-String Library Functions
Strings Class 34 C-String Library Functions there are several useful functions in the cstring library strlen: the number of characters before the \0 strncat: concatenate two strings together strncpy: overwrite
More informationObject Oriented Programming COP3330 / CGS5409
Object Oriented Programming COP3330 / CGS5409 Dynamic Allocation in Classes Review of CStrings Allocate dynamic space with operator new, which returns address of the allocated item. Store in a pointer:
More informationAngela Chih-Wei Tang Visual Communications Lab Department of Communication Engineering National Central University JhongLi, Taiwan.
C++ Classes: Part II Angela Chih-Wei Tang Visual Communications Lab Department of Communication Engineering National Central University JhongLi, Taiwan 2009 Fall Outline 17.2 const (Constant) Objects and
More information! A class in C++ is similar to a structure. ! A class contains members: - variables AND. - public: accessible outside the class.
Classes and Objects Week 5 Gaddis:.2-.12 14.3-14.4 CS 5301 Fall 2016 Jill Seaman The Class! A class in C++ is similar to a structure.! A class contains members: - variables AND - functions (often called
More informationIII. 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 informationEE 355 Lab 4 - Party Like A Char Star
1 Introduction In this lab you will implement a "hangman" game where the user is shown blanks representing letter of a word and then tries to guess and fill in the letters with a limited number of guesses
More informationThe Class. Classes and Objects. Example class: Time class declaration with functions defined inline. Using Time class in a driver.
Classes and Objects Week 5 Gaddis:.2-.12 14.3-14.4 CS 5301 Fall 2014 Jill Seaman The Class A class in C++ is similar to a structure. A class contains members: - variables AND - functions (often called
More informationDeitel Dive-Into Series: Dive-Into Cygwin and GNU C++
1 Deitel Dive-Into Series: Dive-Into Cygwin and GNU C++ Objectives To be able to use Cygwin, a UNIX simulator. To be able to use a text editor to create C++ source files To be able to use GCC to compile
More informationclarity. In the first form, the access specifier public : is needed to {
Structure Time CSC 211 Intermediate Programming Classes in C++ // Create a structure, set its members, and print it. struct Time // structure definition int hour; // 0-23 int minute; // 0-59 int second;
More informationIntroduction to Classes
Introduction to Classes Procedural and Object-Oriented Programming Procedural and Object-Oriented Programming Procedural programming focuses on the process/actions that occur in a program Object-Oriented
More informationCS201 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 informationOBJECT ORIENTED PROGRAMMING USING C++
OBJECT ORIENTED PROGRAMMING USING C++ Chapter 17 - C++ Classes: Part II 17.1 Introduction 17.2 const (Constant) Objects and const Member Functions 17.3 Composition: Objects as Members of Classes 17.4 friend
More informationSYSC 2006 C Winter String Processing in C. D.L. Bailey, Systems and Computer Engineering, Carleton University
SYSC 2006 C Winter 2012 String Processing in C D.L. Bailey, Systems and Computer Engineering, Carleton University References Hanly & Koffman, Chapter 9 Some examples adapted from code in The C Programming
More information! A class in C++ is similar to a structure. ! A class contains members: - variables AND. - public: accessible outside the class.
Classes and Objects Week 5 Gaddis:.2-.12 14.3-14.4 CS 5301 Spring 2015 Jill Seaman The Class! A class in C++ is similar to a structure.! A class contains members: - variables AND - functions (often called
More information+2 Volume II OBJECT TECHNOLOGY OBJECTIVE QUESTIONS R.Sreenivasan SanThome HSS, Chennai-4. Chapter -1
Chapter -1 1. Object Oriented programming is a way of problem solving by combining data and operation 2.The group of data and operation are termed as object. 3.An object is a group of related function
More informationAbstraction in Software Development
Abstract Data Types Programmer-created data types that specify values that can be stored (type of data) operations that can be done on the values The user of an abstract data type (ADT) does not need to
More informationCome and join us at WebLyceum
Come and join us at WebLyceum For Past Papers, Quiz, Assignments, GDBs, Video Lectures etc Go to http://www.weblyceum.com and click Register In Case of any Problem Contact Administrators Rana Muhammad
More informationCharacters, c-strings, and the string Class. CS 1: Problem Solving & Program Design Using C++
Characters, c-strings, and the string Class CS 1: Problem Solving & Program Design Using C++ Objectives Perform character checks and conversions Knock down the C-string fundamentals Point at pointers and
More informationB.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University
Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are
More informationcalling 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 informationClass. SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong
Class Prof. Jinkyu Jeong (Jinkyu@skku.edu) TA -- Minwoo Ahn (minwoo.ahn@csl.skku.edu) TA -- Donghyun Kim (donghyun.kim@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu
More informationClasses and Data Abstraction. Topic 5
Classes and Data Abstraction Topic 5 Introduction Object-oriented programming (OOP) Encapsulates data (attributes) and functions (behavior) into packages called classes The data and functions of a class
More informationChapter 8 - Characters and Strings
1 Chapter 8 - Characters and Strings Outline 8.1 Introduction 8.2 Fundamentals of Strings and Characters 8.3 Character Handling Library 8.4 String Conversion Functions 8.5 Standard Input/Output Library
More informationCome and join us at WebLyceum
Come and join us at WebLyceum For Past Papers, Quiz, Assignments, GDBs, Video Lectures etc Go to http://www.weblyceum.com and click Register In Case of any Problem Contact Administrators Rana Muhammad
More information3. Functions. Modular programming is the dividing of the entire problem into small sub problems that can be solved by writing separate programs.
1 3. Functions 1. What are the merits and demerits of modular programming? Modular programming is the dividing of the entire problem into small sub problems that can be solved by writing separate programs.
More informationIntroduction & Review
CPSC 250 Data Structures Introduction & Review Dr. Yingwu Zhu What to learn? ADT design & implementation using C++ class Algorithm efficiency analysis Big-O ADTs: Binary search trees, AVL trees, Heaps,
More informationEngineering Problem Solving with C++, 3e Chapter 2 Test Bank
1. Match each of the following data types with literal constants of that data type. A data type can be used more than once. A. integer B 1.427E3 B. double D "Oct" C. character B -63.29 D. string F #Hashtag
More informationQuiz 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! Mon, May 5, 2:00PM to 4:30PM. ! Closed book, closed notes, clean desk. ! Comprehensive (covers entire course) ! 30% of your final grade
Final Exam Review Final Exam Mon, May 5, 2:00PM to 4:30PM CS 2308 Spring 2014 Jill Seaman Closed book, closed notes, clean desk Comprehensive (covers entire course) 30% of your final grade I recommend
More informationCS3157: Advanced Programming. Outline
CS3157: Advanced Programming Lecture #12 Apr 3 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline Intro CPP Boring stuff: Language basics: identifiers, data types, operators, type conversions, branching
More informationClasses: Member functions // classes example #include <iostream> using namespace std; Objects : Reminder. Member functions: Methods.
Classes: Methods, Constructors, Destructors and Assignment For : COP 3330. Object oriented Programming (Using C++) http://www.compgeom.com/~piyush/teach/3330 Piyush Kumar Classes: Member functions // classes
More informationCpt S 122 Data Structures. Introduction to C++ Part II
Cpt S 122 Data Structures Introduction to C++ Part II Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Objectives Defining class with a member function
More informationPage. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team
Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team Question No: 1 ( Marks: 2 ) Write a declaration statement for an array of 10
More informationCSCI 6610: Intermediate Programming / C Chapter 12 Strings
... 1/26 CSCI 6610: Intermediate Programming / C Chapter 12 Alice E. Fischer February 10, 2016 ... 2/26 Outline The C String Library String Processing in C Compare and Search in C C++ String Functions
More informationScientific Programming in C V. Strings
Scientific Programming in C V. Strings Susi Lehtola 1 November 2012 C strings As mentioned before, strings are handled as character arrays in C. String constants are handled as constant arrays. const char
More informationInterview 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