# 1. Objectives. Objectives. 13.Visual Studio Projects. C/C++ The array is an Aggregate!

Size: px
Start display at page:

Download "# 1. Objectives. Objectives. 13.Visual Studio Projects. C/C++ The array is an Aggregate!"

Transcription

1 1 2 Objectives 1. Agregates 2. Structs 3. Introduction To Classes 4. Constructor 5. Destructor 6. Function Overloading 7. Default Arguments 8. Accessors & Mutators 9. ADT Abstract Data Types 10. Operator Overloads >, >=, <, <=,!=, ==, = 11. Partition Class -.hpp &.cpp 12. Indigenous Data & Exogenous Data 3 3 Objectives 13.Visual Studio Projects Execute Binary Outside Visual Studio Net Environment Redirecting Output To A Text File Other Files In The Debug Folder 4 4 Aggregate A Collection Of Objects Stored As One Unit! FirstName[15], LastName[20]; No[21]; float Data[10]; C/C++ The array is an Aggregate! C/C++ A array is an Aggregate in which the objects have to be of the same type! # 1

2 Aggregate A Collection Of Objects Stored As One Unit! struct FirstName[15], LastName[20]; ; One of the advantages of an aggregate is that you can pass a single argument, that represents many components, to a function. C/C++ A struct is an Aggregate in which the objects do not have to be of the same type! If you have not written a sample program which contains John; a struct, you should do so. You are responsible for it! John.No = 20; strcpy(john.firstname, John ); strcpy(john.lastname, Smith ); Set(&John, "John", "Smith", 20); 7 7 void Set ( * This, NewFirst[], NewLast, NewNo) This->No = New strcpy(this->firstname, NewFirst); void Display ( This); strcpy(this->lastname, NewLast); 8 # include <stdio.h> # include <string.h> struct ; FirstName[15], LastName[20]; Complete C/C++ Program Using A Struc void Set1 ( * This, NewFirst[], NewLast[], NewNo); void Set2 ( * This, NewFirst[], NewLast[], NewNo); void Display ( This); main() John; John.No = 20; strcpy(john.firstname, "John"); strcpy(john.lastname, "Smith"); Set1(&John, "John", "Smith", 20); Display(John); Set2(&John, "John", "Doe", 21); Display(John); return (0); void Set1 ( * This, NewFirst[], NewLast[], NewNo) This->No = New strcpy(this->firstname, NewFirst); strcpy(this->lastname, NewLast); Output No = 20 First = John Second = Smith No = 21 First = John Second = Doe void Set2 ( * This, * NewFirst, * NewLast, NewNo) (*This).No = New strcpy((*this).firstname, NewFirst); strcpy((*this).lastname, NewLast); void Display ( This) prf ("No = %d\n", This.No); prf ("First = %s\n", This.FirstName); prf ("Second = %s\n\n", This.LastName); C/C++ The struct is an Aggregate! Aggregate A Collection Of Objects Stored As One Unit! class (void); void Set ( NewNo, NewFirst[], NewLast[]); FirstName[15], LastName[20]; ; void ::Set( NewNo, NewFirst[], NewLast[]) No = New strcpy(firstname, NewFirst); strcpy(lastname, NewLast); C++ A Class is an Aggregate in which the objects do not have to be of the same type! John; John.Set(20,"John","Doe"); # 2

3 About Classes class (void); ~ (void); void Set ( NewName[], long NewNo, bool NewSex); void Display( Message[]); Name [26]; # define MALE false # define FEMALE true bool Sex; ; Class bundles both data and methods [ encapsulation] ; not so with structs. Class functions are called Methods or Member Functions [Constructor, Destructor, Set, Display]. Class data are called Data Members [ Name, No, Sex]. Each class has a public portion containing Methods & Data available to all that utilize the class. Each class has a private portion containing Methods & Data available to all that utilize the class Special Method - Constructor class (void); ~ (void); void Set ( NewName[], long NewNo, bool NewSex); void Display( Message[]); Constructor - Does all that is necessary To Create The Object void ::(void) strcpy (Name, ""); No = 0; Sex = FEMALE; Constructor Automatically called each time an object is created. main() John; John.Set("John",22,MALE); Inefficient - Assigns Data Members twice! Once in Constructor and once in Set! Multiple Constructors class Scope Operator => :: (void); ( NewName[], long NewNo, bool NewSex); ~ (void); void Set ( NewName[], long NewNo, bool NewSex); void Display( Message[]); Constructor - Does all that is necessary To Create The Object void ::(void) strcpy (Name, ""); No = 0; Sex = FEMALE; void ::( NewName[], long NewNo, bool NewSex) strcpy (Name, NewName); No = New Sex = NewSex; main() John, Sarah("Sarah", 111, FEMALE); "Function Overloading when a function will accept more than one signature. 17 Overloaded Functions - functions which will accept more than one calling signature - function overloading extends the ways in which it can be called! John, Signature => void/nothing/- "Function Overloading" Sarah("Sarah", 111, FEMALE); Signature => string,,bool Any function can be overloaded again and again as long as each variation has a unique signature. Function overloading is pretty unique to C++; it is not supported in standard C or most other languages. void Set ( NewName[], long NewNo, bool NewSex); (s,l,b) void Set ( NewName[], bool NewSex, long NewNo); (s,b,l) void Set (long NewNo, bool NewSex, NewName[]); (l,b,s) void Set (long NewNo, NewName[], bool NewSex); (l,s,b) void Set (bool NewSex, NewName[], long NewNo); (b,s,l) void Set (bool NewSex, long NewNo, NewName[]); (b,l,s) void Set ( NewName[], long NewNo); (s,l) void Set ( NewName[], bool NewSex); (s,b) void Set (long NewNo, bool NewSex); (l,b) void Set (long NewNo, NewName[]); (l,s) void Set (bool NewSex, NewName[]); (b,s) void Set (bool NewSex, long NewNo); (b,l) void Set ( NewName[]); (s) void Set (long NewNo); (l) void Set (bool NewSex); (b) 18 void Set (); # 3

4 Default Arguments can also be used to achieve function overloading. Default arguments must be in a continuous sequence from right to left! void ( NewName[] = "", long NewNo = 0, bool NewSex = FEMALE); Constructor 1 Accepts the following signatures: (s,l,b) (s,l) (b) () s1("jane", 11, FEMALE), s2("amy", 22), s3("sarah"), s4; Default Arguments Also Facilitate "Function Overloading" void Set (long NewNo, bool NewSex = FEMALE, NewName[] = ""]); Constructor 2 Accepts the following signatures: (l,b,s) (l,b) (l) s5(55, FEMALE, "Rhonda"), s6(66, MALE), s7("becky"); Note That Default Arguments are in Prototype Only! 20 Destructors class Destructor Automatically called each time an object goes out of scope. (void); ( NewName[], long NewNo, bool NewSex); ~ (void); void Set ( NewName[], long NewNo, bool NewSex); void Display( Message[]); Destructor - Does all that is necessary Destroy The Object void :: ~ (void) // puts ( Evoking Destructor ~() ); Destructor - Not Required for class, but must coded it if prototyped in class definition. "2 Objects Created Here" main() John, Sarah("Sarah", 111, FEMALE);... "2 Objects Destoyed Here" 22 When Are Destructors Really Needed? class Stack Destructor Required to prevent "Memory Leak" Stack (unsigned long NewMax = 10); ~Stack (void);... Note That Default Arguments are in Prototype Only! * Array; long Max, Top; // Initialize to -1 for Empty void Stack::Stack(unsigned long NewMax) Max = NewMax; Memory Dynamically Allocated - new Top = -1; Array = new [Max + 1]; void Stack:: ~Stack(void) Memory Dynamically De-Allocated - Returned To OS Memory Manager - delete [] Array; delete 23 When Are Destructors Really Needed? 1. Constructor allocates memory, destructor must deallocate memory 2. Constructor opens file(s), destructor might close it/them 3. Constructor uses AtoD card to turn on power to a sound system, destructor might turn it off 4. Constructor reads starting data from file, destructor might write ending data to that file 5. etc. // Application Dependent! All C++ compilers will define a default destructor, which does nothing, in the absence of a prototyped destructor. 24 T # 4

5 Mutators - Set class (void); ( NewName[], long NewNo, bool NewSex); ~ (void); void Set ( NewName[], long NewNo, bool NewSex); void Display( Message[]); Mutator- A method that changes the state of an object. void ::Set ( NewName[ ], long NewNo, bool NewSex) strcpy (Name, NewName); No = New Sex = NewSex; main() Sarah; Sarah.Set("Sarah", 111, FEMALE); Accessors - Display class (void); ( NewName[], long NewNo, bool NewSex); ~ (void); void Set ( NewName[], long NewNo, bool NewSex); void Display( Message[]); Accessor - A method that examines, but not change the state of an object void ::Display ( Message[ ]) puts (Message); prf( Name: %s\n, Name); prf( No : %ld\n, No); if (Sex = MALE) prf( Sex : Male\n ); else prf( Sex : Female\n ); main() Sarah ("Sarah", 111, FEMALE); Sarah.Display( InfoAbout Sarah ); ADT Abstract Data Type - A unique data type that is defined by the programmer! Think Abstraction! class Stack Stack(void); bool Push (InfoType NewInfo); bool Pop (InfoType & TopInfo); bool Empty (void); InfoType Array[100]; Top; ; # 5

6 // I have decided that Name is to be the Primary Character Key for this record type. bool operator == (const Key[]); bool operator > (const Key[]); bool operator >= (const Key[]); bool operator < (const Key[]); bool operator <= (const Key[]); bool operator!= (const Key[]); void operator = (const Key[]); Operators Are Overloaded In Order To Enable The Programmer To Compare A Class With a String, Numeric, or an other Object. Used For Searching & Sorting/Ordering. // I have decided that No is to be the Primary Long Integer Key for this record type. bool operator == (const long Key); bool operator > (const long Key); bool operator >= (const long Key); bool operator < (const long Key); bool operator <= (const long Key); bool operator!= (const long Key); void operator = (const long Key); // I have decided that Name is to be the Primary Key for this record type. bool operator == (const & S); bool operator > (const & S); bool operator >= (const & S); bool operator < (const & S); bool operator <= (const & S); bool operator!= (const & S); void operator = (const & S); ( NewName[] = "", long NewNo = 0, bool NewSex = FEMALE); (long NewNo, NewName[] = "", bool NewSex = FEMALE); ~ (void); void Set ( NewName[] = "", long NewNo = 0, bool NewSex = FEMALE); Name [26]; bool ex; 32 ; // operator Overloads // // operators in such a way // Purpose : Overload the that the Name becomes the // primary acter key for the Class. // // : Dr. Thomas E. Hicks Environment // Written By : Windows NT // Date : 10/25/00 Compiler : Visual C++ // bool ::operator == (const Key[]) if (strcmp(name, Key) == 0) return (true); else return (false); // operator Overloads // // operators in such a way // Purpose : Overload the that the No becomes the // primary eger key for the Class. // // : Dr. Thomas E. Hicks Environment // Written By : Windows NT // Date : 10/25/00 Compiler : Visual C++ // bool ::operator == (const long Key) if (No == Key) return (true); else return (false); John ("John", 111, MALE), Sarah ("Sarah", 222, FEMALE); if (Sarah == "Sarah") John ("John", 111, MALE), Sarah ("Sarah", 222, FEMALE); if (John == 222) // operator Overloads // // the operators in such a way that // Purpose : Overload the Name becomes the // primary key for the Class. // // : Dr. Thomas E. Hicks Environment // Written By : Windows NT // Date : 10/25/00 Compiler : Visual C++ // bool ::operator == (const & S) if (strcmp(name, S.Name) == 0) return (true); else return (false); Often Overload =, >, >=,!=, <, <=, == John ("John", 111, MALE), Sarah ("Sarah", 222, FEMALE); if (John == Sarah) # 6

7 Can Overload Other Things >>, <<, +, -, etc. // Overload << Operator // // acters that represent // Purpose : Display the 50 this datatype. // Written By : Dr. Thomas E. Hicks Environment : Windows NT // // Date : 10/25/00 Compiler : Visual C++ // ostream & operator << (ostream & OutputStream, S) OutputStream << setw(32) << P.Name; OutputStream << " " << setw(8) << S.No << " "; if (S.Sex == FEMALE) OutputStream << "Female"; else OutputStream << "Male "; return (OutputStream); # ifndef STUDENT_CLASS //========================================================= # ifndef STUDENT_CLASS //========================================================= // Includes # include <stdio.h> # include <iostream.h> # include <string.h> 1.hpp # define STUDENT_CLASS Why should each.hpp file should begin the compiler directive # ifndef [if not defined] // Defines # define STUDENT_CLASS # define MALE false # define FEMALE true and end with compiler directive # endif [end if]? # endif //STUDENT_CLASS //======================================================= // Class // class ( NewName[] = "", long NewNo = 0, bool NewSex = FEMALE); Prevent multiple redefinitions of constants, functions, etc. Several other classes may use/include (long NewNo, NewName[] = "", bool NewSex = FEMALE); ~ (void); void Set ( NewName[] = "", long NewNo = 0, bool NewSex = FEMALE); Stack <> Class(10); bool void Display( Message[] = ""); Name [26]; Sex; Interface - lists the class and its members -.h or.hpp LinkedList <> CSCI2320(25); BinaryTree <> CSCI4320(45); # define MALE false # define FEMALE true ; # endif //STUDENT_CLASS //======================================================= 39 # endif //STUDENT_CLASS //======================================================= 40 What is in the.h or.hpp erface? 1] All includes essential to the class 2] All defines essential to the class 3] All struct and class definitions 4] Prototypes for all Functions/Procedures 5] All Template Functions/Procedures/Methods # 7

8 What is in the.c or.cpp file? 1] Include the erface file 2] All non-template Functions/Procedures/Methods Why Partition Classes Into.hpp &.cpp Files? When a program is erfaced properly o.hpp and.cpp files: 1] Compilation Is Faster good compilers only compile those components that have been altered since the last compilation 2] Easier To Partition A Project For Teams 3] Reuse Opportunities Reduces Project Time/Cost - reuse opportunities increase when one develops and tests the class so well so general/generic that it can used in other projects 4] Assists In Better Design it is difficult, if not impossible, to keep all of the details of a large system in mind at one time by creating one self contained student class erface that has all of the functionality necessary for students, one can more easily abstract the object class Name Name ( NewFirst[]="", NewLast[]=""); *First, *Last; long ; Indigenous Data - Data that is completely contained by the structure. (i.e. No) Exogenous Data - Data that is not part of the structure, but accessed through poers that are in the structure. (i.e. First & Last) # 8

9 DirectAccessFiles.zip Open The Application Folder! Decompress Folder DirectAccessFiles.zip [From Schedule] Open The Debug Folder! Should Be Empty! Into Folder C:\Temp It Should Compile! 51 Compile The Program! Revisit The Debug Folder! Combined Binary Executable How Can We Execute It? ] Windows Mouse Double-Click 54 # 9

10 2.1] Hold Down Start Menu Select Run 2.2] Enter CMD 2.3] Set Debug Directory As The Default 2.4] Enter Main While We Are Here, How Does One Send The Output To A Text File, Called Output.txt? 2.4] Enter Main > Output.txt Open The Application Folder! Can Open Output.txt With Visual Studio Open The Debug Folder! Should Be Empty! More Extensive Listing Of Compile & Link Process # 10

11 Auto.obj is Re-compiled When Auto.hpp or Auto.cpp is altered or Rebuild All! Linker Links the Obj files to form Executable! Compile Successful Compilation Of Auto.hpp & Auto.cpp Creates Auto.obj Other files are non-readable system files that assist in the Automated Make Process! # include "Utilities.hpp" # include ".hpp" # include "Auto.hpp" # include "Part.hpp" There will be one obj file for each hpp/cpp set and one for Main Matrix - Two dimensional array X [5][2]; x [NoRows] [NoCols]; STL - Standard Template Library - Has Libraries For String, Vector, Stacks, etc # 11

12 67 67 # 12

RECOMMENDATION. Don't Write Entire Programs Unless You Want To Spend 3-10 Times As Long Doing Labs! Write 1 Function - Test That Function!

RECOMMENDATION. Don't Write Entire Programs Unless You Want To Spend 3-10 Times As Long Doing Labs! Write 1 Function - Test That Function! 1 2 RECOMMENDATION Don't Write Entire Programs Unless You Want To Spend 3-10 Times As Long Doing Labs! Write 1 Function - Test That Function! 2 Function Overloading C++ provides the capability of Using

More information

RECOMMENDATION. Don't Write Entire Programs Unless You Want To Spend 3-10 Times As Long Doing Labs! Write 1 Function - Test That Function!

RECOMMENDATION. Don't Write Entire Programs Unless You Want To Spend 3-10 Times As Long Doing Labs! Write 1 Function - Test That Function! 1 RECOMMENDATION Don't Write Entire Programs Unless You Want To Spend 3-10 Times As Long Doing Labs! Write 1 Function - Test That Function! 2 3 Copy Project Folder There will be a number of times when

More information

OOP- 4 Templates & Memory Management Print Only Pages 1-5 Individual Assignment Answers To Questions 10 Points - Program 15 Points

OOP- 4 Templates & Memory Management Print Only Pages 1-5 Individual Assignment Answers To Questions 10 Points - Program 15 Points OOP-4-Templates-Memory-Management-HW.docx CSCI 2320 Initials P a g e 1 If this lab is an Individual assignment, you must do all coded programs on your own. You may ask others for help on the language syntax,

More information

# 1. Objectives. Dangling Pointers FirstName & LastName - Pointers Reference Memory Incorrect Memory! Not A Good Constructor!

# 1. Objectives. Dangling Pointers FirstName & LastName - Pointers Reference Memory Incorrect Memory! Not A Good Constructor! Objectives. Dynamic Memory. Shallow Copy. Deep Copy. LIFO & FIFO. Array Implementation Of A Stack 6. Dynamic Stack 7. Templates 8. Template Stack 9. Primitive Operations Push, Pop, Empty Full, Resize,

More information

2 2

2 2 1 2 2 3 3 C:\Temp\Templates 4 5 Use This Main Program 6 # include "Utilities.hpp" # include "Student.hpp" Copy/Paste Main void MySwap (int Value1, int Value2); int main(int argc, char * argv[]) { int A

More information

Call The Project Dynamic-Memory

Call The Project Dynamic-Memory 1 2 2 Call The Project Dynamic-Memory 4 4 Copy-Paste Main # include "Utilities.hpp" int main(int argc, char * argv[]) { short int *PtrNo; (*PtrNo) = 5; printf ("(*PtrNo) = %d\n", (*PtrNo)); } getchar();

More information

C:\Temp\Templates. Download This PDF From The Web Site

C:\Temp\Templates. Download This PDF From The Web Site 11 2 2 2 3 3 3 C:\Temp\Templates Download This PDF From The Web Site 4 5 Use This Main Program Copy-Paste Code From The Next Slide? Compile Program 6 Copy/Paste Main # include "Utilities.hpp" # include

More information

Functions & Memory Maps Review C Programming Language

Functions & Memory Maps Review C Programming Language Functions & Memory Maps Review C Programming Language Data Abstractions CSCI-2320 Dr. Tom Hicks Computer Science Department Constants c 2 What Is A Constant? Constant a Value that cannot be altered by

More information

OOP- 5 Stacks Individual Assignment 35 Points

OOP- 5 Stacks Individual Assignment 35 Points OOP-5-Stacks-HW.docx CSCI 2320 Initials P a g e 1 If this lab is an Individual assignment, you must do all coded programs on your own. You may ask others for help on the language syntax, but you must organize

More information

Lab 2: ADT Design & Implementation

Lab 2: ADT Design & Implementation Lab 2: ADT Design & Implementation By Dr. Yingwu Zhu, Seattle University 1. Goals In this lab, you are required to use a dynamic array to design and implement an ADT SortedList that maintains a sorted

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

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

C++ Review. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

C++ Review. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University C++ Review CptS 223 Advanced Data Structures Larry Holder School of Electrical Engineering and Computer Science Washington State University 1 Purpose of Review Review some basic C++ Familiarize us with

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

Lecture 5. Function Pointers

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

Makefiles Makefiles should begin with a comment section of the following form and with the following information filled in:

Makefiles Makefiles should begin with a comment section of the following form and with the following information filled in: CS 215 Fundamentals of Programming II C++ Programming Style Guideline Most of a programmer's efforts are aimed at the development of correct and efficient programs. But the readability of programs is also

More information

Chapter 13: Introduction to Classes Procedural and Object-Oriented Programming

Chapter 13: Introduction to Classes Procedural and Object-Oriented Programming Chapter 13: Introduction to Classes 1 13.1 Procedural and Object-Oriented Programming 2 Procedural and Object-Oriented Programming Procedural programming focuses on the process/actions that occur in a

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

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 02: Using Objects MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Using Objects 2 Introduction to Object Oriented Programming Paradigm Objects and References Memory Management

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

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

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

Abstract Data Types (ADT) and C++ Classes

Abstract Data Types (ADT) and C++ Classes Abstract Data Types (ADT) and C++ Classes 1-15-2013 Abstract Data Types (ADT) & UML C++ Class definition & implementation constructors, accessors & modifiers overloading operators friend functions HW#1

More information

Chapter 19: Program Design. Chapter 19. Program Design. Copyright 2008 W. W. Norton & Company. All rights reserved.

Chapter 19: Program Design. Chapter 19. Program Design. Copyright 2008 W. W. Norton & Company. All rights reserved. Chapter 19 Program Design 1 Introduction Most full-featured programs are at least 100,000 lines long. Although C wasn t designed for writing large programs, many large programs have been written in C.

More information

Exception Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011

Exception Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011 More C++ David Chisnall March 17, 2011 Exceptions A more fashionable goto Provides a second way of sending an error condition up the stack until it can be handled Lets intervening stack frames ignore errors

More information

C/C++ Text File Functions

C/C++ Text File Functions 1 2 3 C/C++ Text File Functions fopen opens a text file. fclose closes a text file. feof detects end-of-file marker in a file. fscanf reads formatted input from a file. fprintf prints formatted output

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

Review: C++ Basic Concepts. Dr. Yingwu Zhu

Review: C++ Basic Concepts. Dr. Yingwu Zhu Review: C++ Basic Concepts Dr. Yingwu Zhu Outline C++ class declaration Constructor Overloading functions Overloading operators Destructor Redundant declaration A Real-World Example Question #1: How to

More information

Purpose of Review. Review some basic C++ Familiarize us with Weiss s style Introduce specific constructs useful for implementing data structures

Purpose of Review. Review some basic C++ Familiarize us with Weiss s style Introduce specific constructs useful for implementing data structures C++ Review 1 Purpose of Review Review some basic C++ Familiarize us with Weiss s style Introduce specific constructs useful for implementing data structures 2 Class The Class defines the data structure

More information

Midterm Review. PIC 10B Spring 2018

Midterm Review. PIC 10B Spring 2018 Midterm Review PIC 10B Spring 2018 Q1 What is size t and when should it be used? A1 size t is an unsigned integer type used for indexing containers and holding the size of a container. It is guarenteed

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

Distributed Real-Time Control Systems. Lecture 17 C++ Programming Intro to C++ Objects and Classes

Distributed Real-Time Control Systems. Lecture 17 C++ Programming Intro to C++ Objects and Classes Distributed Real-Time Control Systems Lecture 17 C++ Programming Intro to C++ Objects and Classes 1 Bibliography Classical References Covers C++ 11 2 What is C++? A computer language with object oriented

More information

Final CSE 131B Spring 2004

Final CSE 131B Spring 2004 Login name Signature Name Student ID Final CSE 131B Spring 2004 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 (25 points) (24 points) (32 points) (24 points) (28 points) (26 points) (22 points)

More information

Lecture #1. Introduction to Classes and Objects

Lecture #1. Introduction to Classes and Objects Lecture #1 Introduction to Classes and Objects Topics 1. Abstract Data Types 2. Object-Oriented Programming 3. Introduction to Classes 4. Introduction to Objects 5. Defining Member Functions 6. Constructors

More information

CSCE 110 PROGRAMMING FUNDAMENTALS

CSCE 110 PROGRAMMING FUNDAMENTALS CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class Prof. amr Goneid, AUC 1 Dictionaries(1): A Key Table Class Prof. Amr Goneid, AUC 2 A Key Table

More information

Introduction to Classes

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

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

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

More information

pointers & references

pointers & references pointers & references 1-22-2013 Inline Functions References & Pointers Arrays & Vectors HW#1 posted due: today Quiz Thursday, 1/24 // point.h #ifndef POINT_H_ #define POINT_H_ #include using

More information

G52CPP C++ Programming Lecture 9

G52CPP C++ Programming Lecture 9 G52CPP C++ Programming Lecture 9 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last lecture const Constants, including pointers The C pre-processor And macros Compiling and linking And

More information

Topics. Topics (Continued) 7.1 Abstract Data Types. Abstraction and Data Types. 7.2 Object-Oriented Programming

Topics. Topics (Continued) 7.1 Abstract Data Types. Abstraction and Data Types. 7.2 Object-Oriented Programming Chapter 7: Introduction to Classes and Objects Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Topics 7.1 Abstract Data Types 7.2 Object-Oriented Programming

More information

G52CPP C++ Programming Lecture 6. Dr Jason Atkin

G52CPP C++ Programming Lecture 6. Dr Jason Atkin G52CPP C++ Programming Lecture 6 Dr Jason Atkin 1 Last lecture The Stack Lifetime of local variables Global variables Static local variables const (briefly) 2 Visibility is different from lifetime Just

More information

LECTURE 03 LINKED LIST

LECTURE 03 LINKED LIST DATA STRUCTURES AND ALGORITHMS LECTURE 03 LINKED LIST IMRAN IHSAN ASSISTANT PROFESSOR AIR UNIVERSITY, ISLAMABAD LINKED LISTS DEFINITION A linked list is a data structure where each object is stored in

More information

COMP6771 Advanced C++ Programming

COMP6771 Advanced C++ Programming 1. COMP6771 Advanced C++ Programming Week 4 Part One: (continued) and 2016 www.cse.unsw.edu.au/ cs6771 2. Inline Constructors, Accessors and Mutators Question (from 2015): In the week 3 examples, constructors

More information

Come and join us at WebLyceum

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

Chapter 17: Linked Lists

Chapter 17: Linked Lists Chapter 17: Linked Lists 17.1 Introduction to the Linked List ADT Introduction to the Linked List ADT Linked list: set of data structures (nodes) that contain references to other data structures list head

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

JTSK Programming in C II C-Lab II. Lecture 3 & 4

JTSK Programming in C II C-Lab II. Lecture 3 & 4 JTSK-320112 Programming in C II C-Lab II Lecture 3 & 4 Xu (Owen) He Spring 2018 Slides modified from Dr. Kinga Lipskoch Planned Syllabus The C Preprocessor Bit Operations Pointers and Arrays (Dynamically

More information

ADTs & Classes. An introduction

ADTs & Classes. An introduction ADTs & Classes An introduction Quick review of OOP Object: combination of: data structures (describe object attributes) functions (describe object behaviors) Class: C++ mechanism used to represent an object

More information

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive) Final Exam Exercises Chapters 1-7 + 11 Write C++ code to: l Determine if a number is odd or even CS 2308 Fall 2016 Jill Seaman l Determine if a number/character is in a range - 1 to 10 (inclusive) - between

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

EECE.3220: Data Structures Spring 2017

EECE.3220: Data Structures Spring 2017 EECE.3220: Data Structures Spring 2017 Lecture 14: Key Questions February 24, 2017 1. Describe the characteristics of an ADT to store a list. 2. What data members would be necessary for a static array-based

More information

Programming Abstractions

Programming Abstractions Programming Abstractions C S 1 0 6 B Cynthia Lee Topics du Jour: Make your own classes! Needed for Boggle assignment! We are starting to see a little bit in MarbleBoard assignment as well 2 Classes in

More information

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

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

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

More information

Programming, numerics and optimization

Programming, numerics and optimization Programming, numerics and optimization Lecture A-4: Object-oriented programming Łukasz Jankowski ljank@ippt.pan.pl Institute of Fundamental Technological Research Room 4.32, Phone +22.8261281 ext. 428

More information

Problem Solving with C++

Problem Solving with C++ GLOBAL EDITION Problem Solving with C++ NINTH EDITION Walter Savitch Kendrick Mock Ninth Edition PROBLEM SOLVING with C++ Problem Solving with C++, Global Edition Cover Title Copyright Contents Chapter

More information

OOP-8-DLList-1-HW.docx CSCI 2320 Initials Page 1

OOP-8-DLList-1-HW.docx CSCI 2320 Initials Page 1 OOP-8-DLList-1-HW.docx CSCI 2320 Initials Page 1 If this lab is an Individual assignment, you must do all coded programs on your own. You may ask others for help on the language syntax, but you must organize

More information

UNIVERSITY OF SWAZILAND

UNIVERSITY OF SWAZILAND UNIVERSITY OF SWAZILAND DEPARTMENT OF COMPUTER SCIENCE CSC242 - OBJECT ORIENTED PROGRAMMING FINAL EXAMINATION MAY 2017 Instructions 1. The time allowed is THREE (3) H0URS. 2. Read all the questions in

More information

Tutorial 1: Introduction to C Computer Architecture and Systems Programming ( )

Tutorial 1: Introduction to C Computer Architecture and Systems Programming ( ) Systems Group Department of Computer Science ETH Zürich Tutorial 1: Introduction to C Computer Architecture and Systems Programming (252-0061-00) Herbstsemester 2012 Goal Quick introduction to C Enough

More information

Chapter 17: Linked Lists

Chapter 17: Linked Lists Chapter 17: Linked Lists Copyright 2009 Pearson Education, Inc. Copyright Publishing as Pearson 2009 Pearson Addison-Wesley Education, Inc. Publishing as Pearson Addison-Wesley 17.1 Introduction to the

More information

PROFESSOR: DR.JALILI BY: MAHDI ESHAGHI

PROFESSOR: DR.JALILI BY: MAHDI ESHAGHI PROFESSOR: DR.JALILI BY: MAHDI ESHAGHI 1 2 Overview Distributed OZ Java RMI CORBA IDL IDL VS C++ CORBA VS RMI 3 Distributed OZ Oz Language Multi paradigm language, strong support for compositionality and

More information

C++: Const Function Overloading Constructors and Destructors Enumerations Assertions

C++: Const Function Overloading Constructors and Destructors Enumerations Assertions C++: Const Function Overloading Constructors and Destructors Enumerations Assertions Const const float pi=3.14159; const int* pheight; // defines pointer to // constant int value cannot be changed // pointer

More information

[CS302-Data Structures] Homework 2: Stacks

[CS302-Data Structures] Homework 2: Stacks [CS302-Data Structures] Homework 2: Stacks Instructor: Kostas Alexis Teaching Assistants: Shehryar Khattak, Mustafa Solmaz, Bishal Sainju Fall 2018 Semester Section 1. Stack ADT Overview wrt Provided Code

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 Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p.

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p. Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p. 9 Self-Test Exercises p. 11 History Note p. 12 Programming and

More information

the gamedesigninitiative at cornell university Lecture 7 C++ Overview

the gamedesigninitiative at cornell university Lecture 7 C++ Overview Lecture 7 Lecture 7 So You Think You Know C++ Most of you are experienced Java programmers Both in 2110 and several upper-level courses If you saw C++, was likely in a systems course Java was based on

More information

Pointers, Dynamic Data, and Reference Types

Pointers, Dynamic Data, and Reference Types Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation The new operator The delete operator Dynamic Memory Allocation for Arrays 1 C++ Data Types simple

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

ADT: Design & Implementation

ADT: Design & Implementation CPSC 250 Data Structures ADT: Design & Implementation Dr. Yingwu Zhu Abstract Data Type (ADT) ADT = data items + operations on the data Design of ADT Determine data members & operations Implementation

More information

POINTERS - Pointer is a variable that holds a memory address of another variable of same type. - It supports dynamic allocation routines. - It can improve the efficiency of certain routines. C++ Memory

More information

Chapter 11. Abstract Data Types and Encapsulation Concepts

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

More information

Install Visual Studio Community Version 2017

Install Visual Studio Community Version 2017 Dr. Tom Hicks Install Visual Studio Community Version 2017 1 P a g e Install Visual Studio Community Version 2017 1] Navigate your browser to https://www.visualstudio.com/ 2] Hold down the Download Visual

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

CSCE 110 PROGRAMMING FUNDAMENTALS

CSCE 110 PROGRAMMING FUNDAMENTALS CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 16. Linked Lists Prof. amr Goneid, AUC 1 Linked Lists Prof. amr Goneid, AUC 2 Linked Lists The Linked List Structure Some Linked List

More information

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

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

C++ For Science and Engineering Lecture 27

C++ For Science and Engineering Lecture 27 C++ For Science and Engineering Lecture 27 John Chrispell Tulane University Monday November 1, 2010 Classes and the This pointer Every C++ object has a curious pointer called this. If we want to extend

More information

Come and join us at WebLyceum

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

Object Oriented Programming COP3330 / CGS5409

Object Oriented Programming COP3330 / CGS5409 Object Oriented Programming COP3330 / CGS5409 Intro to Data Structures Vectors Linked Lists Queues Stacks C++ has some built-in methods of storing compound data in useful ways, like arrays and structs.

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

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination University of Illinois at Urbana-Champaign Department of Computer Science First Examination CS 225 Data Structures and Software Principles Spring 2007 7p-9p, Thursday, March 1 Name: NetID: Lab Section

More information

Kurt Schmidt. October 30, 2018

Kurt Schmidt. October 30, 2018 to Structs Dept. of Computer Science, Drexel University October 30, 2018 Array Objectives to Structs Intended audience: Student who has working knowledge of Python To gain some experience with a statically-typed

More information

2 ADT Programming User-defined abstract data types

2 ADT Programming User-defined abstract data types Preview 2 ADT Programming User-defined abstract data types user-defined data types in C++: classes constructors and destructors const accessor functions, and inline functions special initialization construct

More information

Object Oriented Programming in C#

Object Oriented Programming in C# Introduction to Object Oriented Programming in C# Class and Object 1 You will be able to: Objectives 1. Write a simple class definition in C#. 2. Control access to the methods and data in a class. 3. Create

More information

Object-Oriented Programming in C++

Object-Oriented Programming in C++ Object-Oriented Programming in C++ Pre-Lecture 9: Advanced topics Prof Niels Walet (Niels.Walet@manchester.ac.uk) Room 7.07, Schuster Building March 24, 2015 Prelecture 9 Outline This prelecture largely

More information

TREX Set-Up Guide: Creating a TREX Executable File for Windows

TREX Set-Up Guide: Creating a TREX Executable File for Windows TREX Set-Up Guide: Creating a TREX Executable File for Windows Prepared By: HDR 1 International Boulevard, 10 th Floor, Suite 1000 Mahwah, NJ 07495 May 13, 2013 Creating a TREX Executable File for Windows

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

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

Arizona s First University. More ways to show off--controlling your Creation: IP and OO ECE 373

Arizona s First University. More ways to show off--controlling your Creation: IP and OO ECE 373 Arizona s First University. More ways to show off--controlling your Creation: IP and OO ECE 373 Overview Object Creation Control Distribution Possibilities Impact of design decisions on IP control 2 Good

More information

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination University of Illinois at Urbana-Champaign Department of Computer Science First Examination CS 225 Data Structures and Software Principles Spring 2007 7p-9p, Thursday, March 1 Name: NetID: Lab Section

More information

CS 211 Programming Practicum Fall 2018

CS 211 Programming Practicum Fall 2018 Due: Wednesday, 11/7/18 at 11:59 pm Infix Expression Evaluator Programming Project 5 For this lab, write a C++ program that will evaluate an infix expression. The algorithm REQUIRED for this program will

More information

MaanavaN.Com CS1203 OBJECT ORIENTED PROGRAMMING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MaanavaN.Com CS1203 OBJECT ORIENTED PROGRAMMING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING SUB CODE / SUBJECT: CS1203 / Object oriented programming YEAR / SEM: II / III QUESTION BANK UNIT I FUNDAMENTALS PART-A (2 MARKS) 1. What is Object Oriented

More information

C++ PROGRAMMING LANGUAGE: CLASSES. CAAM 519, CHAPTER 13

C++ PROGRAMMING LANGUAGE: CLASSES. CAAM 519, CHAPTER 13 C++ PROGRAMMING LANGUAGE: CLASSES. CAAM 519, CHAPTER 13 This chapter focuses on introducing the notion of classes in the C++ programming language. We describe how to create class and use an object of a

More 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

Programming in C/C Lecture 3

Programming in C/C Lecture 3 Programming in C/C++ 2005- Lecture 3 http://few.vu.nl/~nsilvis/c++/ Natalia Silvis-Cividjian e-mail: nsilvis@few.vu.nl vrije Universiteit amsterdam Object Oriented Programming in C++ about object oriented

More information

COEN244: Class & function templates

COEN244: Class & function templates COEN244: Class & function templates Aishy Amer Electrical & Computer Engineering Templates Function Templates Class Templates Outline Templates and inheritance Introduction to C++ Standard Template Library

More information

Object-> Programming();

Object-> Programming(); Object-> Programming(); 2 c SM 2007 1 More C++ 1.1 Introduction This book provides a succinct overview of C++ programming topics, and is designed assuming that the reader has completed an introductory

More information

Abstract Data Types and Encapsulation Concepts

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

More information

1 Short Answer (7 Points Each)

1 Short Answer (7 Points Each) 1 Short Answer (7 Points Each) 1. Given the following function, what operations will need to be overloaded in the class T for this code to compile? template T square(t n) { return n * n; } The

More information

Motivation was to facilitate development of systems software, especially OS development.

Motivation was to facilitate development of systems software, especially OS development. A History Lesson C Basics 1 Development of language by Dennis Ritchie at Bell Labs culminated in the C language in 1972. Motivation was to facilitate development of systems software, especially OS development.

More information