Ch 6. Structures and Classes

Size: px
Start display at page:

Download "Ch 6. Structures and Classes"

Transcription

1 Ch 6. Structures and Classes September 1, 2013 Advanced Networking Technology Lab. (YU-ANTL) Dept. of Information & Comm. Eng, Graduate School, Yeungnam University, KOREA (Tel : ; Fax : ytkim@yu.ac.kr)

2 Struct ( 구조체 ) Outline Classes Defining, member functions Public and private members Accessor (i.e., get_xx()) and mutator (i.e., set_xx())functions Structures vs. classes ch 6-2

3 Structures ( 구조체 ) 2 nd aggregate data type: struct Recall: aggregate meaning "grouping" Recall array: collection of values of same type Structure: collection of values of different types Treated as a single item, like arrays Major difference: Must first "define" struct Prior to declaring any variables ch 6-3

4 Structure Types Define struct globally (typically) No memory is allocated Just a "placeholder" for what our struct will "look like" Definition: typedef struct MyCmplx { // Name of new struct "type" double real; // member names double imagin; } Cmplx; double mag; // magnitude ch 6-4

5 Declare Structure Variable With structure type defined, now declare variables of this new type: Cmplx c1, c2; Just like declaring simple types Variable c1 and c2 are now of type Cmplx They contain "member values real, imagin, and mag Each of the struct "parts" ch 6-5

6 Accessing Structure Members Dot Operator to access members Cmplx c1; c1.real = 2.0; c1.imagin = 3.0; c1.mag = sqrt(pow(c1.real, 2.0) + pow(c1.imagin, 2.0) ); Called "member variables" The "parts (attribute) of the structure variable Different structs can have same name member variables No conflicts struct Student { int st_id; char name[20]; Date birthdate; }; struct Employ { int emp_id; char name[20]; Date birthdate; }; ch 6-6

7 typedef struct MyCmplx { double real; double imagin; double mag; } Cmplx; void printcmplx(cmplx c) { char sign; Structure Example } sign = (c.imagin < 0)? '-' : '+'; cout << setw(8) << c.real <<" " << sign << " j" << fabs(c.imagin) ; cout << " (magnitude " << c.mag << ")" << endl; Cmplx cmplxadd(cmplx c1, Cmplx c2) { Cmplx res; res.real = c1.real + c2.real; res.imagin = c1.imagin + c2.imagin; res.mag = sqrt(res.real*res.real + res.imagin*res.imagin); return res; } ch 6-7

8 Cmplx cmplxsub(cmplx c1, Cmplx c2) { Cmplx res; res.real = c1.real - c2.real; res.imagin = c1.imagin - c2.imagin; res.mag = sqrt(res.real*res.real + res.imagin*res.imagin); return res; } Cmplx cmplxmultiply(cmplx c1, Cmplx c2) { Cmplx res; res.real = (c1.real * c2.real) - (c1.imagin * c2.imagin); res.imagin = (c1.real * c2.imagin) + (c1.imagin * c2.real); res.mag = sqrt(res.real*res.real + res.imagin*res.imagin); return res; } Cmplx cmplxdivide(cmplx c1, Cmplx c2) { Cmplx res; double denom; denom = c2.real*c2.real + c2.imagin*c2.imagin; res.real = ((c1.real * c2.real) + (c1.imagin * c2.imagin)) / denom; res.imagin = ((c2.real * c1.imagin) - (c1.real * c2.imagin)) / denom; res.mag = sqrt(res.real*res.real + res.imagin*res.imagin); return res; } ch 6-8

9 1. int main() 2. { 3. Cmplx cmplxs[7]; 4. cout << "Input two complex numbers : c1.real, c1.imagin, 5. cout << c2.real, c2.imagin"<<endl; 6. cout << "c1.real : "; 7. cin >> cmplxs[0].real; 8. cout << "c1.imagin : "; 9. cin >> cmplxs[0].imagin; 10. cmplxs[0].mag = sqrt((cmplxs[0].real*cmplxs[0].real) (cmplxs[0].imagin * cmplxs[0].imagin)); 12. cout << "c2.real : "; 13. cin >> cmplxs[1].real; 14. cout << "c2.imagin : "; 15. cin >> cmplxs[1].imagin; 16. cmplxs[1].mag = sqrt((cmplxs[1].real*cmplxs[1].real) (cmplxs[1].imagin * cmplxs[1].imagin)); ch 6-9

10 18. cmplxs[2] = cmplxadd(cmplxs[0], cmplxs[1]); 19. cmplxs[3] = cmplxsub(cmplxs[0], cmplxs[1]); 20. cmplxs[4] = cmplxmultiply(cmplxs[0], cmplxs[1]); 21. cmplxs[5] = cmplxdivide(cmplxs[0], cmplxs[1]); 22. cmplxs[6] = cmplxs[0]; 23. for (int i=0; i<7; i++) { 24. cout << "cmplxs[" << i << "]: "; 25. printcmplx(cmplxs[i]); 26. } 27. return 0; 28.} ch 6-10

11 Structure Assignments Given structure named Cmplx Declare two structure variables: Cmplx c1, c2; Both are variables of "struct type Cmplx" Simple assignments are legal: c2 = c1; Simply copies each member variable from c1 into member variables of c2 ch 6-11

12 Structures as Function Arguments Passed like any simple data type Pass-by-value Pass-by-reference Or combination Can also be returned by function Return-type is structure type Return statement in function definition sends structure variable back to caller ch 6-12

13 Initializing Structures Can initialize at declaration Example: struct Planet { }; char name[10]; double relativemass; double distance; struct Planet earth = { Earth, 1.0, 150}; Declaration provides initial data to all three member variables ch 6-13

14 Array of Structure Struct data elements can be organized in array Example) struct Planet solarsystem[solar_planets] = { {"Mercury", , 57.9}, {"Venus", 0.815, 108}, {"Earth",1.0, 150}, {"Mars", 0.107, 228}, {"Jupiter", 318, 778}, {"Saturn", 95.1, 1430}, {"Uranus", 14.5, 2870}, {"Neptune", 17.2, 4500}, {"Pluto", 0.11, 5900} }; ch 6-14

15 Handling attributes of each element of struct array void printplanets(struct Planet solarplanets[], int num_planet) 1. { 2. cout.setf(ios::fixed); 3. cout.setf(ios::showpoint); 4. for (int i=0; i<num_planet; i++) { 5. cout << setw(2) << i; 6. cout << " Name: "; 7. cout << setiosflags(ios::left) <<setw(8) << solarplanets[i].name; 8. cout << resetiosflags(ios::left); 9. cout << " Rel Mass: "; 10. cout << setw(7) << setprecision(3) <<solarplanets[i].relativemass; 11. cout << " Dist from Sun: "; 12. cout << setw(6) << setprecision(1) << solarplanets[i].distance ; 13. cout << endl; 14. } // end for 15.} ch 6-15

16 Sorting Array of Structure Sorting elements in array of structure (1) void sortplanetsbyrelmass(struct Planet solarplanets[], int num_planet) 1. { 2. struct Planet temp; 3. int i, j, m; 4. double min_relmass; 5. for (i=0; i<num_planet-1; i++) { 6. m = i; 7. min_relmass = solarplanets[i].relativemass; 8. for (j=i+1; j<num_planet; j++) { 9. if (min_relmass > solarplanets[j].relativemass) { 10. m = j; 11. min_relmass = solarplanets[j].relativemass; 12. } 13. } // end inner for 14. if (m!= i) { // if new minimum found, swap 15. temp = solarplanets[i]; 16. solarplanets[i] = solarplanets[m]; 17. solarplanets[m] = temp; 18. } 19. } // end outer for 20. } ch 6-16

17 Sorting elements in array of structure (2) void sortplanetsbyname(struct Planet solarplanets[], int num_planet) { 1. struct Planet temp; 2. int i, j, m; 3. char min_name[10] = {0}; 4. for (i=0; i<num_planet-1; i++) { 5. m = i; 6. strcpy(min_name, solarplanets[i].name); 7. for (j=i+1; j<num_planet; j++) { 8. if (strcmp(min_name, solarplanets[j].name) > 0) { 9. m = j; 10. strcpy(min_name, solarplanets[j].name); 11. } 12. } // end inner for 13. if (m!= i) { // if new minimum found, swap 14. temp = solarplanets[i]; 15. solarplanets[i] = solarplanets[m]; 16. solarplanets[m] = temp; 17. } 18. } // end outer for 19.} ch 6-17

18 1. int main() { 2. struct Planet solarsystem[solar_planets] = 3. {{"Mercury", , 57.9}, {"Venus", 0.815, 108}, {"Earth",1.0, 150}, 4. {"Mars", 0.107, 228}, {"Jupiter", 318, 778}, {"Saturn", 95.1, 1430}, 5. {"Uranus", 14.5, 2870}, {"Neptune", 17.2, 4500}, {"Pluto", 0.11, 5900} }; 6. cout << "Initial state" << endl; 7. printplanets(solarsystem, SOLAR_PLANETS); 8. sortplanetsbyrelmass(solarsystem, SOLAR_PLANETS); 9. cout << "\ nafter sorting by relative mass:" << endl; 10. printplanets(solarsystem, SOLAR_PLANETS); 11. sortplanetsbydist(solarsystem, SOLAR_PLANETS); 12. cout << "\ nafter sorting by distance from sun:" << endl; 13. printplanets(solarsystem, SOLAR_PLANETS); 14. sortplanetsbyname(solarsystem, SOLAR_PLANETS); 15. cout << "\ nafter sorting by name using strcmp and strcpy:" << endl; 16. printplanets(solarsystem, SOLAR_PLANETS); 17. cout << "\ n\ n"; return 0; 20.} ch 6-18

19 result of execution ch 6-19

20 Example of struct typedef struct MyDayOfYear { int year; int month; int day; }DayOfYear; DayOfYear dy1, dy2; dy1.year = 2013; dy1.month = 9; dy1.day = 2; Struct DayOfYear dy2.year = -999; // no compilation error; but is this logically correct? dy2.month = 500; // no compilation error; but is this logically correct? dy2.day = -45; // no compilation error; but is this logically correct? ch 6-20

21 Limitations of struct the data members in a struct variable can be accessed by any function if the address of the struct variable is known no member function that checks the correctness (validness) of the data ch 6-21

22 Similar to structures Classes Not only, just member data But also, adds member functions Integral to object-oriented programming Focus on objects Object: Contains data and operations Class: mold ( 주형형틀, 거푸집 ) or blue print to instantiate an object In C++, variables of class type are objects ch 6-22

23 Class Definitions Defined similar to structures Example: class DayOfYear name of new class type { public: access specifier! void output(); member function! int month; int day; }; Notice only member function s prototype Function s implementation is elsewhere ch 6-23

24 Declaring Objects Declared same as all variables Predefined types, structure types Example: DayOfYear today, birthday; Declares two objects of class type DayOfYear Objects include: Data Members: month, day Operations (member functions) output() ch 6-24

25 Class Member Access Members accessed same as structures Example: today.month today.day And to access member function: today.output(); Invokes member function ch 6-25

26 Class Member Functions Must define or "implement" class member functions Like other function definitions Can be after main() definition Must specify class: void DayOfYear::output() { } :: is scope resolution operator Instructs compiler "what class" member is from Item before :: called type qualifier ch 6-26

27 Class Member Functions Definition Notice output() member function s definition (in next example) Refers to member data of class No qualifiers Function used for all objects of the class Will refer to "that object s" data when invoked Example: today.output(); Displays "today" object s data ch 6-27

28 Complete Class Example: Display 6.3 Class With a Member Function (1 of 4) ch 6-28

29 Display 6.3 Class With a Member Function (2 of 4) ch 6-29

30 Display 6.3 Class With a Member Function (3 of 4) ch 6-30

31 Display 6.3 Class With a Member Function (4 of 4) ch 6-31

32 Dot and Scope Resolution Operator Used to specify "of what thing" they are members Dot operator: Specifies member of particular object Scope resolution operator (::) Specifies what class the function definition comes from ch 6-32

33 A Class s Place Class is full-fledged type! Just like data types int, double, etc. Can have variables of a class type We simply call them "objects" Can have parameters of a class type Pass-by-value Pass-by-reference Can use class type like any other type! ch 6-33

34 Encapsulation Any data type includes Data (range of data) Operations (that can be performed on data) Example: int data type has: Data: ~ Operations: +,-,*,/,%, logical, etc. Same with classes But WE specify data, and the operations to be allowed on our data! ch 6-34

35 Abstract Data Type (ADT) "Abstract" Programmers don t know details Abbreviated "ADT" Collection of data values together with set of basic operations defined for the values ADT s often "language-independent" We implement ADT s in C++ with classes C++ class "defines" the ADT Other languages implement ADT s as well ch 6-35

36 Encapsulation Encapsulation Means "bringing together as one" Declare a class get an object Object is "encapsulation" of Data values Operations on the data (member functions) ch 6-36

37 Information Hiding Principles of OOP Details of its implementations and its operations work not known to "user" of the class enhances the adaptability of new technology Data Abstraction Details of how data is manipulated within ADT/class not known to user Encapsulation Bring together data and operations, but keep "details" hidden ch 6-37

38 Encapsulation in Object Encapsulation and protection of private data Object outside program interface to outside Friend Functions - cin >> // standard input - cout << // standard output Public Member Functions - get() // read with validity check - set() // write with validity check Private Member Functions - house keeping Private Data Members ch 6-38

39 Public and Private Members Data in class almost always designated private in definition! Upholds principles of OOP Hide data from user Allow manipulation only via operations Which are member functions Public items (usually member functions) are "user-accessible" ch 6-39

40 Public and Private Example Modify previous example: class DayOfYear { public: void input(); void output(); private: int month; int day; }; Data now private Objects have no direct access ch 6-40

41 Public and Private Example 2 Given previous example Declare object: DayOfYear today; Object today can ONLY access public members cin >> today.month; // NOT ALLOWED! cout << today.day; // NOT ALLOWED! Must instead call public operations: today.input(); today.output(); ch 6-41

42 Public and Private Style Can mix & match public & private More typically place public first Allows easy viewing of portions that can be USED by programmers using the class Private data is "hidden", so irrelevant to users Outside of class definition, cannot change (or even access) private data ch 6-42

43 Accessor and Mutator Functions Object needs to "do something" with its data Call accessor member functions Allow object to read data Also called "get member functions" Simple retrieval of member data Mutator member functions Allow object to change data Manipulated based on application Set member functions ch 6-43

44 // Display 6.4 Class with Private Members #include <iostream> #include <cstdlib> using namespace std; class DayOfYear { public: void input( ); void output( ); void set(int newmonth, int newday); //Precondition: newmonth and newday form a possible date. void set(int newmonth); //Precondition: 1 <= newmonth <= 12 //Postcondition: The date is set to the first day of the given month. int getmonthnumber( ); //Returns 1 for January, 2 for February, etc. int getday( ); private: int month; int day; }; ch 6-44

45 int main( ) { DayOfYear today, bachbirthday; cout << "Enter today's date:\ n"; today.input( ); cout << "Today's date is "; today.output( ); cout << endl; bachbirthday.set(3, 21); cout << "J. S. Bach's birthday is "; bachbirthday.output( ); cout << endl; if ( today.getmonthnumber( ) == bachbirthday.getmonthnumber( ) && today.getday( ) == bachbirthday.getday( ) ) cout << "Happy Birthday Johann Sebastian!\ n"; else cout << "Happy Unbirthday Johann Sebastian!\ n"; } return 0; ch 6-45

46 //Uses iostream and cstdlib: void DayOfYear::set(int newmonth, int newday) { if ((newmonth >= 1) && (newmonth <= 12)) month = newmonth; else { cout << "Illegal month value! Program aborted.\ n"; exit(1); } if ((newday >= 1) && (newday <= 31)) day = newday; else { cout << "Illegal day value! Program aborted.\ n"; } } exit(1); //Uses iostream and cstdlib: void DayOfYear::set(int newmonth) { if ((newmonth >= 1) && (newmonth <= 12)) month = newmonth; else { cout << "Illegal month value! Program aborted.\ n"; } exit(1); } day = 1; ch 6-46

47 int DayOfYear::getMonthNumber( ) { return month; } int DayOfYear::getDay( ) { return day; } //Uses iostream and cstdlib: void DayOfYear::input( ) { cout << "Enter the month as a number: "; cin >> month; cout << "Enter the day of the month: "; cin >> day; if ((month < 1) (month > 12) (day < 1) (day > 31)) { cout << "Illegal date! Program aborted.\ n"; exit(1); } } ch 6-47

48 void DayOfYear::output( ) { switch (month) { case 1: cout << "January "; break; case 2: cout << "February "; break; case 3: cout << "March "; break; case 4: cout << "April "; break; case 5: cout << "May "; break; case 6: cout << "June "; break; case 7: cout << "July "; break; case 8: cout << "August "; break; case 9: cout << "September "; break; case 10: cout << "October "; break; case 11: cout << "November "; break; case 12: cout << "December "; break; default: cout << "Error in DayOfYear::output. Contact software vendor."; } // end switch } cout << day; ch 6-48

49 Separation of Interface and Implementation User of class need not see details of how class is implemented Principle of OOP encapsulation User only needs "rules" Called "interface" for the class In C++ public member functions and associated comments Implementation of class is hidden Member function definitions elsewhere User need not see them ch 6-49

50 Structures vs. Classes Structures Typically all members public No member functions Classes Typically all data members private Interface member functions public Technically, same Perceptionally, very different mechanisms ch 6-50

51 Thinking Objects Focus for programming changes Before algorithms center stage Object-Oriented Programming (OOP) data is focus Algorithms still exist They simply focus on their data Are "made" to "fit" the data Designing software solution Define variety of objects and how they interact ch 6-51

52 Summary 6-1 Structure is collection of different types Class used to combine data and functions into single unit -> object Member variables and member functions Can be public accessed outside class Can be private accessed only in a member function s definition Class and structure types can be formal parameters to functions ch 6-52

53 Summary 6-2 C++ class definition Should separate two key parts Interface: what user needs Implementation: details of how class works ch 6-53

54 6.1 Key ideas Homework 6 (1) C++ Object-Oriented programming 에서 encapsulation 이란무슨의미인가? Encapsulation 을함으로써어떤장점이있는가? (2) C++ Object-Oriented programming 에서 information hiding 이란무슨의미인가? 무엇을누구에게숨기는것인가? 6.2 Programming project 6-5. (class Fraction) 6.3 Programming project 6-8. (class Money) 6.4 Programming project (class Temperature) ch 6-54

Ch 6-1. Structures. March 30, Prof. Young-Tak Kim

Ch 6-1. Structures. March 30, Prof. Young-Tak Kim 2014-1 Ch 6-1. Structures March 30, 2014 Advanced Networking Technology Lab. (YU-ANTL) Dept. of Information & Comm. Eng, Graduate School, Yeungnam University, KOREA (Tel : +82-53-810-2497; Fax : +82-53-810-4742

More information

Chapter 6 Structures and Classes. GEDB030 Computer Programming for Engineers Fall 2017 Euiseong Seo

Chapter 6 Structures and Classes. GEDB030 Computer Programming for Engineers Fall 2017 Euiseong Seo Chapter 6 Structures and Classes 1 Learning Objectives Structures Structure types Structures as function arguments Initializing structures Classes Defining, member functions Public and private members

More information

Dot and Scope Resolution Operator

Dot and Scope Resolution Operator Dot and Scope Resolution Operator Used to specify "of what thing" they are members Dot operator: Specifies member of particular object Scope resolution operator: Specifies what class the function definition

More information

Structures and Classes CS 16: Solving Problems with Computers I Lecture #15

Structures and Classes CS 16: Solving Problems with Computers I Lecture #15 Structures and Classes CS 16: Solving Problems with Computers I Lecture #15 Ziad Matni Dept. of Computer Science, UCSB WHAT THE NEXT 3 WEEKS LOOK LIKE MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY 20- Nov 21-

More information

Ch 8. Operator Overloading, Friends, and References

Ch 8. Operator Overloading, Friends, and References 2014-1 Ch 8. Operator Overloading, Friends, and References May 28, 2014 Advanced Networking Technology Lab. (YU-ANTL) Dept. of Information & Comm. Eng, Graduate School, Yeungnam University, KOREA (Tel

More information

Chapter 10 Defining Classes

Chapter 10 Defining Classes Chapter 10 Defining Classes What Is a Class? A class is a data type whose variables are objects Some pre-defined data types you have used are int char You can define your own classes define your own types

More information

Programming & Abstraction

Programming & Abstraction Classes CMSC 202 Programming & Abstraction All programming languages provide some form of abstraction. Also called information hiding Separates code use from code implementation Procedural Programming

More information

Starting Savitch Chapter 10. A class is a data type whose variables are objects. Some pre-defined classes in C++ include int,

Starting Savitch Chapter 10. A class is a data type whose variables are objects. Some pre-defined classes in C++ include int, Classes Starting Savitch Chapter 10 l l A class is a data type whose variables are objects Some pre-defined classes in C++ include int, char, ifstream Of course, you can define your own classes too A class

More information

Classes and Data Abstraction. Topic 5

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

CIS 190: C/C++ Programming. Classes in C++

CIS 190: C/C++ Programming. Classes in C++ CIS 190: C/C++ Programming Classes in C++ Outline Header Protection Functions in C++ Procedural Programming vs OOP Classes Access Constructors Headers in C++ done same way as in C including user.h files:

More information

Abstract Data Types. Different Views of Data:

Abstract Data Types. Different Views of Data: Abstract Data Types Representing information is fundamental to computer science. The primary purpose of most computer programs is not to perform calculations, but to store and efficiently retrieve information.

More information

PIC 10A. Lecture 15: User Defined Classes

PIC 10A. Lecture 15: User Defined Classes PIC 10A Lecture 15: User Defined Classes Intro to classes We have already had some practice with classes. Employee Time Point Line Recall that a class is like a souped up variable that can store data,

More information

Ch 7. Constructors and Other Tools

Ch 7. Constructors and Other Tools 2013-2 Ch 7. Constructors and Other Tools September 3, 2013 Advanced Networking Technology Lab. (YU-ANTL) Dept. of Information & Comm. Eng, Graduate School, Yeungnam University, KOREA (Tel : +82-53-810-2497;

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

Ch 5-2. Arrays Part 2

Ch 5-2. Arrays Part 2 2014-1 Ch 5-2. Arrays Part 2 March 29, 2014 Advanced Networking Technology Lab. (YU-ANTL) Dept. of Information & Comm. Eng, Graduate School, Yeungnam University, KOREA (Tel : +82-53-810-2497; Fax : +82-53-810-4742

More information

Software Design and Analysis for Engineers

Software Design and Analysis for Engineers Software Design and Analysis for Engineers by Dr. Lesley Shannon Email: lshannon@ensc.sfu.ca Course Website: http://www.ensc.sfu.ca/~lshannon/courses/ensc251 Simon Fraser University Slide Set: 1 Date:

More information

CS 115 Exam 3, Spring 2011

CS 115 Exam 3, Spring 2011 CS 115 Exam 3, Spring 2011 Your name: Rules You may use one handwritten 8.5 x 11 cheat sheet (front and back). This is the only resource you may consult during this exam. Explain/show work if you want

More information

Function Call Example

Function Call Example Function Call Example A Function Call Example (1) ch 3-25 A Function Call Example (2) ch 3-26 Alternative Function Declaration Recall: Function declaration is "information for compiler Compiler only needs

More information

Ch 6-8. C-Strings. April 30, Prof. Young-Tak Kim

Ch 6-8. C-Strings. April 30, Prof. Young-Tak Kim 2014-1 Ch 6-8. C-Strings April 30, 2014 Advanced Networking Technology Lab. (YU-ANTL) Dept. of Information & Comm. Eng, Graduate School, Yeungnam University, KOREA (Tel : +82-53-810-2497; Fax : +82-53-810-4742

More information

Computer Programming

Computer Programming Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering Session: Parameter Passing in Function Calls Dr. Deepak B. Phatak & Dr. Supratik Chakraborty,

More information

Ch 6-2. File Input / Output

Ch 6-2. File Input / Output 2014-1 Ch 6-2. File Input / Output March 30, 2014 Advanced Networking Technology Lab. (YU-ANTL) Dept. of Information & Comm. Eng, Graduate School, Yeungnam University, KOREA (Tel : +82-53-810-2497; Fax

More information

Simplest version of DayOfYear

Simplest version of DayOfYear Reminder from last week: Simplest version of DayOfYear class DayOfYear { public: void output(); int month; int day; }; Like a struct with an added method All parts public Clients access month, day directly

More information

Friends and Overloaded Operators

Friends and Overloaded Operators Friend Function Friends and Overloaded Operators Class operations are typically implemented as member functions Some operations are better implemented as ordinary (nonmember) functions CSC 330 OO Software

More information

Ch 4. Parameters and Function Overloading

Ch 4. Parameters and Function Overloading 2014-1 Ch 4. Parameters and Function Overloading March 19, 2014 Advanced Networking Technology Lab. (YU-ANTL) Dept. of Information & Comm. Eng, Graduate School, Yeungnam University, KOREA (Tel : +82-53-810-2497;

More information

Classes and Data Abstraction. Topic 5

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

Friends and Overloaded Operators

Friends and Overloaded Operators Friends and Overloaded Operators Friend Function Class operations are typically implemented as member functions Some operations are better implemented as ordinary (nonmember) functions CSC 330 OO Software

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

1 Pointer Concepts. 1.1 Pointer Examples

1 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

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

Lab Instructor : Jean Lai

Lab Instructor : Jean Lai Lab Instructor : Jean Lai Group related statements to perform a specific task. Structure the program (No duplicate codes!) Must be declared before used. Can be invoked (called) as any number of times.

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

Object Oriented Programming COP3330 / CGS5409

Object Oriented Programming COP3330 / CGS5409 Object Oriented Programming COP3330 / CGS5409 Classes & Objects DDU Design Constructors Member Functions & Data Friends and member functions Const modifier Destructors Object -- an encapsulation of data

More information

Implementing an ADT with a Class

Implementing an ADT with a Class Implementing an ADT with a Class the header file contains the class definition the source code file normally contains the class s method definitions when using Visual C++ 2012, the source code and the

More information

Fundamentals of Programming Session 24

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

Fundamentals of Programming. Lecture 19 Hamed Rasifard

Fundamentals of Programming. Lecture 19 Hamed Rasifard Fundamentals of Programming Lecture 19 Hamed Rasifard 1 Outline C++ Object-Oriented Programming Class 2 C++ C++ began as an expanded version of C. C++ improves on many of C s features and provides object-oriented-programming

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

File Input / Output Streams in C++ CS 16: Solving Problems with Computers I Lecture #9

File Input / Output Streams in C++ CS 16: Solving Problems with Computers I Lecture #9 File Input / Output Streams in C++ CS 16: Solving Problems with Computers I Lecture #9 Ziad Matni Dept. of Computer Science, UCSB Midterm Exam grades out! Announcements If you want to see your exams, visit

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

Ch 1. Algorithms and Basic C++ Programming

Ch 1. Algorithms and Basic C++ Programming 2013-2 Ch 1. Algorithms and Basic C++ Programming July 1, 2013 Dept. of Information & Communication Engineering College of Engineering Yeungnam University, KOREA (Tel : +82-53-810-2497; Fax : +82-53-810-4742

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

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

Lab 2: Pointers. //declare a pointer variable ptr1 pointing to x. //change the value of x to 10 through ptr1

Lab 2: Pointers. //declare a pointer variable ptr1 pointing to x. //change the value of x to 10 through ptr1 Lab 2: Pointers 1. Goals Further understanding of pointer variables Passing parameters to functions by address (pointers) and by references Creating and using dynamic arrays Combing pointers, structures

More information

Sample Code: OUTPUT Daily Highs & Lows

Sample Code: OUTPUT Daily Highs & Lows Name1: Name2: Class Day / Time: Due Date: Sample Code: OUTPUT Daily Highs & Lows This program will obtain from the user 3 sets of data including a date, the high temperature and a low temperature for that

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

Consider the following statements. string str1 = "ABCDEFGHIJKLM"; string str2; After the statement str2 = str1.substr(1,4); executes, the value of str2 is " ". Given the function prototype: float test(int,

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

Chapter 13. Recursion. Copyright 2016 Pearson, Inc. All rights reserved.

Chapter 13. Recursion. Copyright 2016 Pearson, Inc. All rights reserved. Chapter 13 Recursion Copyright 2016 Pearson, Inc. All rights reserved. Learning Objectives Recursive void Functions Tracing recursive calls Infinite recursion, overflows Recursive Functions that Return

More information

Chapter 2 Data Design and Implementation

Chapter 2 Data Design and Implementation Chapter 2 Data Design and Implementation Data The representation of information in a manner suitable for communication or analysis by humans or machines Data are the nouns of the programming world: The

More information

Exceptions, Case Study-Exception handling in C++.

Exceptions, Case Study-Exception handling in C++. PART III: Structuring of Computations- Structuring the computation, Expressions and statements, Conditional execution and iteration, Routines, Style issues: side effects and aliasing, Exceptions, Case

More information

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures The main body and cout Agenda 1 Fundamental data types Declarations and definitions Control structures References, pass-by-value vs pass-by-references The main body and cout 2 C++ IS AN OO EXTENSION OF

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

PIC 10A. Final Review: Part I

PIC 10A. Final Review: Part I PIC 10A Final Review: Part I Final exam The final exam is worth 30% of your grade, same weight as 2 midterms. Could be 50% if grading option 2 turns out better for you. Length is also roughly 2 midterms

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

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage:

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage: Discussion 1H Notes (Week 3, April 14) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 More on Arithmetic Expressions The following two are equivalent:! x = x + 5;

More information

Classes. C++ Object Oriented Programming Pei-yih Ting NTOU CS

Classes. C++ Object Oriented Programming Pei-yih Ting NTOU CS Classes C++ Object Oriented Programming Pei-yih Ting NTOU CS 1 Encapsulation Access Specifiers Default Access Private Data Public vs. Private Functions Object State Scope Inline Member Functions Constant

More information

Chapter 6: User-Defined Functions. Objectives (cont d.) Objectives. Introduction. Predefined Functions 12/2/2016

Chapter 6: User-Defined Functions. Objectives (cont d.) Objectives. Introduction. Predefined Functions 12/2/2016 Chapter 6: User-Defined Functions Objectives In this chapter, you will: Learn about standard (predefined) functions Learn about user-defined functions Examine value-returning functions Construct and use

More information

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible) Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

More information

CMPT 117: Tutorial 1. Craig Thompson. 12 January 2009

CMPT 117: Tutorial 1. Craig Thompson. 12 January 2009 CMPT 117: Tutorial 1 Craig Thompson 12 January 2009 Administrivia Coding habits OOP Header Files Function Overloading Class info Tutorials Review of course material additional examples Q&A Labs Work on

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

CS24 Week 3 Lecture 1

CS24 Week 3 Lecture 1 CS24 Week 3 Lecture 1 Kyle Dewey Overview Some minor C++ points ADT Review Object-oriented Programming C++ Classes Constructors Destructors More minor Points (if time) Key Minor Points const Motivation

More information

Lab 12 Object Oriented Programming Dr. John Abraham

Lab 12 Object Oriented Programming Dr. John Abraham Lab 12 Object Oriented Programming Dr. John Abraham We humans are very good recognizing and working with objects, such as a pen, a dog, or a human being. We learned to categorize them in such a way that

More information

Review. Outline. Array Pointer Object-Oriented Programming. Fall 2013 CISC2200 Yanjun Li 1. Fall 2013 CISC2200 Yanjun Li 2

Review. Outline. Array Pointer Object-Oriented Programming. Fall 2013 CISC2200 Yanjun Li 1. Fall 2013 CISC2200 Yanjun Li 2 Review Fall 2013 CISC2200 Yanjun Li 1 Outline Array Pointer Object-Oriented Programming Fall 2013 CISC2200 Yanjun Li 2 1 Array Arrays are data structures containing related data items of same type. An

More information

Review. Outline. Array Pointer Object-Oriented Programming. Fall 2017 CISC2200 Yanjun Li 1. Fall 2017 CISC2200 Yanjun Li 2

Review. Outline. Array Pointer Object-Oriented Programming. Fall 2017 CISC2200 Yanjun Li 1. Fall 2017 CISC2200 Yanjun Li 2 Review Fall 2017 CISC2200 Yanjun Li 1 Outline Array Pointer Object-Oriented Programming Fall 2017 CISC2200 Yanjun Li 2 1 Computer Fall 2017 CISC2200 Yanjun Li 3 Array Arrays are data structures containing

More information

COMP322 - Introduction to C++ Lecture 02 - Basics of C++

COMP322 - Introduction to C++ Lecture 02 - Basics of C++ COMP322 - Introduction to C++ Lecture 02 - Basics of C++ School of Computer Science 16 January 2012 C++ basics - Arithmetic operators Where possible, C++ will automatically convert among the basic types.

More information

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts Introduction to C++ 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 information

typedef int Array[10]; String name; Array ages;

typedef int Array[10]; String name; Array ages; Morteza Noferesti The C language provides a facility called typedef for creating synonyms for previously defined data type names. For example, the declaration: typedef int Length; Length a, b, len ; Length

More information

Reference Parameters A reference parameter is an alias for its corresponding argument in the function call. Use the ampersand (&) to indicate that

Reference Parameters A reference parameter is an alias for its corresponding argument in the function call. Use the ampersand (&) to indicate that Reference Parameters There are two ways to pass arguments to functions: pass-by-value and pass-by-reference. pass-by-value A copy of the argument s value is made and passed to the called function. Changes

More information

Do not turn to the next page until the start of the exam.

Do not turn to the next page until the start of the exam. Introduction to Programming, PIC10A E. Ryu Fall 2017 Midterm Exam Friday, November 3, 2017 50 minutes, 11 questions, 100 points, 8 pages While we don t expect you will need more space than provided, you

More information

Course "Data Processing" Name: Master-1: Nuclear Energy Session /2018 Examen - Part A Page 1

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

More Flow Control Functions in C++ CS 16: Solving Problems with Computers I Lecture #4

More Flow Control Functions in C++ CS 16: Solving Problems with Computers I Lecture #4 More Flow Control Functions in C++ CS 16: Solving Problems with Computers I Lecture #4 Ziad Matni Dept. of Computer Science, UCSB Administrative CHANGED T.A. OFFICE/OPEN LAB HOURS! Thursday, 10 AM 12 PM

More information

Functions. Lecture 6 COP 3014 Spring February 11, 2018

Functions. Lecture 6 COP 3014 Spring February 11, 2018 Functions Lecture 6 COP 3014 Spring 2018 February 11, 2018 Functions A function is a reusable portion of a program, sometimes called a procedure or subroutine. Like a mini-program (or subprogram) in its

More information

Lab 14 SERACHI G Dr. John P. Abraham

Lab 14 SERACHI G Dr. John P. Abraham Lab 14 SERACHI G Dr. John P. Abraham We can only do a linear search on an unsorted array, but on a sorted array we can do a binary search. In this chapter we will study two different algorithms for searching,

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

C++ For Science and Engineering Lecture 12

C++ For Science and Engineering Lecture 12 C++ For Science and Engineering Lecture 12 John Chrispell Tulane University Monday September 20, 2010 Comparing C-Style strings Note the following listing dosn t do what you probably think it does (assuming

More information

Note 12/1/ Review of Inheritance Practice: Please write down 10 most important facts you know about inheritance...

Note 12/1/ Review of Inheritance Practice: Please write down 10 most important facts you know about inheritance... CISC 2000 Computer Science II Fall, 2014 Note 12/1/2014 1 Review of Inheritance Practice: Please write down 10 most important facts you know about inheritance... (a) What s the purpose of inheritance?

More information

CSC 172 Intermediate Progamming

CSC 172 Intermediate Progamming CSC 172 Intermediate Progamming Lecture 2 A Review of Programming With Classes What Is A Class? A class is similar to a data type, except that the data items that it contains, the data types of which they

More information

Tutorial 8 (Array I)

Tutorial 8 (Array I) Tutorial 8 (Array I) 1. Indicate true or false for the following statements. a. Every element in an array has the same type. b. The array size is fixed after it is created. c. The array size used to declare

More information

OBJECT-ORIENTED PROGRAMMING CONCEPTS-CLASSES II

OBJECT-ORIENTED PROGRAMMING CONCEPTS-CLASSES II KOM3191 Object Oriented Programming Dr Muharrem Mercimek 1 OBJECT-ORIENTED PROGRAMMING CONCEPTS-CLASSES II KOM3191 Object-Oriented Programming KOM3191 Object Oriented Programming Dr Muharrem Mercimek 2

More information

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004 GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004 Functions and Program Structure Today we will be learning about functions. You should already have an idea of their uses. Cout

More information

Review of Important Topics in CS1600. Functions Arrays C-strings

Review of Important Topics in CS1600. Functions Arrays C-strings Review of Important Topics in CS1600 Functions Arrays C-strings Array Basics Arrays An array is used to process a collection of data of the same type Examples: A list of names A list of temperatures Why

More information

Sequential Search (Searching Supplement: 1-2)

Sequential Search (Searching Supplement: 1-2) (Searching Supplement: 1-2) A sequential search simply involves looking at each item in an array in turn until either the value being searched for is found or it can be determined that the value is not

More information

CSE 333. Lecture 10 - references, const, classes. Hal Perkins Paul G. Allen School of Computer Science & Engineering University of Washington

CSE 333. Lecture 10 - references, const, classes. Hal Perkins Paul G. Allen School of Computer Science & Engineering University of Washington CSE 333 Lecture 10 - references, const, classes Hal Perkins Paul G. Allen School of Computer Science & Engineering University of Washington Administrivia New C++ exercise out today, due Friday morning

More information

Chapter 6. I/O Streams as an Introduction to Objects and Classes. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Chapter 6. I/O Streams as an Introduction to Objects and Classes. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 I/O Streams as an Introduction to Objects and Classes Overview 6.1 Streams and Basic File I/O 6.2 Tools for Stream I/O 6.3 Character I/O Slide 6-3 6.1 Streams and Basic File I/O I/O Streams I/O

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

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

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

More information

Chapter 3 Function Basics

Chapter 3 Function Basics Chapter 3 Function Basics Learning Objectives Predefined Functions Those that return a value and those that don t Programmer-defined Functions Defining, Declaring, Calling Recursive Functions Scope Rules

More information

Programming Assignment #2

Programming Assignment #2 Programming Assignment #2 Due: 11:59pm, Wednesday, Feb. 13th Objective: This assignment will provide further practice with classes and objects, and deepen the understanding of basic OO programming. Task:

More information

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible) Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

More information

Character Functions & Manipulators Arrays in C++ CS 16: Solving Problems with Computers I Lecture #10

Character Functions & Manipulators Arrays in C++ CS 16: Solving Problems with Computers I Lecture #10 Character Functions & Manipulators Arrays in C++ CS 16: Solving Problems with Computers I Lecture #10 Ziad Matni Dept. of Computer Science, UCSB Lecture Outline Useful character manipulators & functions

More information

Unit 6. Thinking with Functions

Unit 6. Thinking with Functions 1 Unit 6 Thinking with Functions Function Decomposition 2 Functions Overview Functions (aka procedures, subroutines, or methods) are the unit of code decomposition and abstraction Map Service ValidateInputs()

More information

Ch 2 ADTs and C++ Classes

Ch 2 ADTs and C++ Classes Ch 2 ADTs and C++ Classes Object Oriented Programming & Design Constructing Objects Hiding the Implementation Objects as Arguments and Return Values Operator Overloading 1 Object-Oriented Programming &

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

A SHORT COURSE ON C++

A SHORT COURSE ON C++ Introduction to A SHORT COURSE ON School of Mathematics Semester 1 2008 Introduction to OUTLINE 1 INTRODUCTION TO 2 FLOW CONTROL AND FUNCTIONS If Else Looping Functions Cmath Library Prototyping Introduction

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

Defining Classes and Methods

Defining Classes and Methods Defining Classes and Methods Chapter 5 Modified by James O Reilly Class and Method Definitions OOP- Object Oriented Programming Big Ideas: Group data and related functions (methods) into Objects (Encapsulation)

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

CS 31 Discussion 1A, Week 8. Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50 a.m.

CS 31 Discussion 1A, Week 8. Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50 a.m. CS 31 Discussion 1A, Week 8 Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50 a.m. Today s focus Pointer Structure Clarifications Pointer A pointer is the memory address of a variable.

More information

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved. 1

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

What we will learn about this week: Declaring and referencing arrays. arrays as function arguments. Arrays

What we will learn about this week: Declaring and referencing arrays. arrays as function arguments. Arrays What we will learn about this week: Declaring and referencing arrays Arrays in memory Initializing arrays indexed variables arrays as function arguments Arrays a way of expressing many of the same variable

More information