SlideShare ist ein Scribd-Unternehmen logo
1 von 11
CSE240 – Introduction to
Programming Languages
Lecture 12:
Programming with C++ | Getting Started
Javier Gonzalez-Sanchez
javiergs@asu.edu
javiergs.engineering.asu.edu
Office Hours: By appointment
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 2
Outline
1. Getting Started
‱ namespace,
‱ classes,
‱ scope(public, protected and private),
‱ input and output,
‱ scope resolution operator
2. Memory management
‱ static,
‱ constructor and destructor,
‱ delete
3. Inheritance and polymorphism
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 3
Anatomy of a Program
class FooBar {
int variable;
void method() {
}
};
int x;
int main(){
FooBar anObject;
}
§ Data and the operations,
that manipulate data, are
encapsulated in classes.
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 4
Anatomy of a Program
class FooBar {
private:
char a;
int variable;
protected:
int anotherVariable;
public:
void method1() { }
void method2() { }
};
int x;
int main(){
FooBar anObject;
}
§ Data and the operations,
that manipulate data, are
encapsulated in classes.
§ You can defined public,
private, and protected
components. And,
encapsulated data can
only be accessed (from
outside the class)
through their interface
(operations defined as
public)
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 5
Anatomy of a Program
class Shape {
};
class Rectangle: public Shape {
private:
FooBar a;
};
class FooBar {
};
int main(){
FooBar anObject;
}
§ Data and the operations,
that manipulate data, are
encapsulated in classes.
§ You can defined public,
private, and protected
components. And,
encapsulated data can
only be accessed (from
outside the class)
through their interface
(operations defined as
public)
§ Classes are organized in
hierarchies: use and
inherit.
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 6
Inside each C++ class, it is similar to C program
C++
Java
C
Level of Abstraction
In Java,
attributes and methods are always in
one file.
Java have all related information in
one place.
In C++,
implementations of member functions
can be in the same file than the
class definition (for short
functions) or outside of the class
definition.
C++ argument: structurally clearer
to separate implementation from
definition
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 7
Example in One File: queue.cpp
1. #include <iostream>
2. using namespace std;
3. class Queue {
4. private:
5. int queue_size;
6. protected:
7. int *buffer;
8. int front;
9. int rear;
10. public:
11. Queue(int v) {
12. cout<<"constructorn";
13. }
14. void enqueue(int v) {
15. cout<<"enqueuen";
16. }
17. int dequeue(void){
18. cout<<"dequeuen"; return 5;
19. }
20. };
21. int main(){
22. Queue q1(5);
23. Queue *q2 = new Queue(5);
24.
25. // Access Object
26. q1.enqueue(2);
27. q1.enqueue(8);
28.
29. // Access Object Pointer
30. q2->enqueue(25);
31. int x = q2->dequeue();
32. return 0;
33. }
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 8
Example in Two Files: time.h
1. class Time {
2. public:
3. Time(); // constructor
4. void setTime( int, int ); // set hour, minute
5. void printMilitary(); // print military time format
6. void printStandard(); // print standard time format
7.
8. private:
9. int hour; // 0 - 23
10. int minute; // 0 - 59
11. };
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 9
Example in Two Files: time.cpp
1. #include <iostream>
2. #include "time.h”
3. using namespace std;
4. Time::Time() { // constructor
5. hour = minute = 0;
6. }
7. void Time::setTime( int h, int m) { // Set a new mil Time
8. hour = ( h >= 0 && h < 24 ) ? h : 0;
9. minute = ( m >= 0 && m < 60 ) ? m : 0;
10. }
11. void Time::printMilitary() { // Print time in military format
12. cout << ( hour < 10 ? "0" : "" ) << hour << ":"
13. << ( minute < 10 ? "0" : "" ) << minute; // add "0"
14. }
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 10
Example in Two Files: time.cpp
15. void Time::printStandard() { // Print in standard format
16. cout << ( ( hour == 0 || hour == 12 ) ? 12 : hour % 12 )
17. << ":" << ( minute < 10 ? "0" : "" ) << minute
18. << ( hour < 12 ? " AM" : " PM" ) << endl; //endl is equal to “n”
19. }
20.
21. int main() {
22. Time t; // new is not mandatory - instantiate object t of class Time
23. cout << "The initial military time is ";
24. t.printMilitary();
25. cout << "nThe initial standard time is ";
26. t.printStandard();
27. t.setTime(15, 27);
28. cout << "nnMilitary time after setTime is ";
29. t.printMilitary();
30. cout << "nStandard time after setTime is ";
31. t.printStandard();
32. return 0;
33. }
CSE240 – Introduction to Programming Languages
Javier Gonzalez-Sanchez
javiergs@asu.edu
Fall 2017
Disclaimer. These slides can only be used as study material for the class CSE240 at ASU. They cannot be distributed or used for another purpose.

Weitere Àhnliche Inhalte

Was ist angesagt?

Timur Shemsedinov "Пошу ĐœĐ° ĐșĐŸĐ»Đ±Đ”Đșах, Đ° Ń‡Ń‚ĐŸ... (ĐŃĐžĐœŃ…Ń€ĐŸĐœĐœĐŸĐ” ĐżŃ€ĐŸĐłŃ€Đ°ĐŒĐŒĐžŃ€ĐŸĐČĐ°ĐœĐžĐ”)"
Timur Shemsedinov "Пошу ĐœĐ° ĐșĐŸĐ»Đ±Đ”Đșах, Đ° Ń‡Ń‚ĐŸ... (ĐŃĐžĐœŃ…Ń€ĐŸĐœĐœĐŸĐ” ĐżŃ€ĐŸĐłŃ€Đ°ĐŒĐŒĐžŃ€ĐŸĐČĐ°ĐœĐžĐ”)"Timur Shemsedinov "Пошу ĐœĐ° ĐșĐŸĐ»Đ±Đ”Đșах, Đ° Ń‡Ń‚ĐŸ... (ĐŃĐžĐœŃ…Ń€ĐŸĐœĐœĐŸĐ” ĐżŃ€ĐŸĐłŃ€Đ°ĐŒĐŒĐžŃ€ĐŸĐČĐ°ĐœĐžĐ”)"
Timur Shemsedinov "Пошу ĐœĐ° ĐșĐŸĐ»Đ±Đ”Đșах, Đ° Ń‡Ń‚ĐŸ... (ĐŃĐžĐœŃ…Ń€ĐŸĐœĐœĐŸĐ” ĐżŃ€ĐŸĐłŃ€Đ°ĐŒĐŒĐžŃ€ĐŸĐČĐ°ĐœĐžĐ”)"OdessaJS Conf
 
Richard Salter: Using the Titanium OpenGL Module
Richard Salter: Using the Titanium OpenGL ModuleRichard Salter: Using the Titanium OpenGL Module
Richard Salter: Using the Titanium OpenGL ModuleAxway Appcelerator
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++pratikbakane
 
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"OdessaJS Conf
 
Travel management
Travel managementTravel management
Travel management1Parimal2
 
Kapacitor Alert Topic handlers
Kapacitor Alert Topic handlersKapacitor Alert Topic handlers
Kapacitor Alert Topic handlersInfluxData
 
Doubly linklist
Doubly linklistDoubly linklist
Doubly linklistilsamaryum
 
All you need to know about Callbacks, Promises, Generators
All you need to know about Callbacks, Promises, GeneratorsAll you need to know about Callbacks, Promises, Generators
All you need to know about Callbacks, Promises, GeneratorsBrainhub
 
Ns tutorial
Ns tutorialNs tutorial
Ns tutorialSAMMMATHEW
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CSteffen Wenz
 
Do while loop
Do while loopDo while loop
Do while loopBU
 
C++ assignment
C++ assignmentC++ assignment
C++ assignmentZohaib Ahmed
 
Oop lab report
Oop lab reportOop lab report
Oop lab reportkhasmanjalali
 
RxJS Evolved
RxJS EvolvedRxJS Evolved
RxJS Evolvedtrxcllnt
 
Libtcc and gwan
Libtcc and gwanLibtcc and gwan
Libtcc and gwanDaeMyung Kang
 

Was ist angesagt? (20)

Roslyn: el futuro de C#
Roslyn: el futuro de C#Roslyn: el futuro de C#
Roslyn: el futuro de C#
 
Timur Shemsedinov "Пошу ĐœĐ° ĐșĐŸĐ»Đ±Đ”Đșах, Đ° Ń‡Ń‚ĐŸ... (ĐŃĐžĐœŃ…Ń€ĐŸĐœĐœĐŸĐ” ĐżŃ€ĐŸĐłŃ€Đ°ĐŒĐŒĐžŃ€ĐŸĐČĐ°ĐœĐžĐ”)"
Timur Shemsedinov "Пошу ĐœĐ° ĐșĐŸĐ»Đ±Đ”Đșах, Đ° Ń‡Ń‚ĐŸ... (ĐŃĐžĐœŃ…Ń€ĐŸĐœĐœĐŸĐ” ĐżŃ€ĐŸĐłŃ€Đ°ĐŒĐŒĐžŃ€ĐŸĐČĐ°ĐœĐžĐ”)"Timur Shemsedinov "Пошу ĐœĐ° ĐșĐŸĐ»Đ±Đ”Đșах, Đ° Ń‡Ń‚ĐŸ... (ĐŃĐžĐœŃ…Ń€ĐŸĐœĐœĐŸĐ” ĐżŃ€ĐŸĐłŃ€Đ°ĐŒĐŒĐžŃ€ĐŸĐČĐ°ĐœĐžĐ”)"
Timur Shemsedinov "Пошу ĐœĐ° ĐșĐŸĐ»Đ±Đ”Đșах, Đ° Ń‡Ń‚ĐŸ... (ĐŃĐžĐœŃ…Ń€ĐŸĐœĐœĐŸĐ” ĐżŃ€ĐŸĐłŃ€Đ°ĐŒĐŒĐžŃ€ĐŸĐČĐ°ĐœĐžĐ”)"
 
Richard Salter: Using the Titanium OpenGL Module
Richard Salter: Using the Titanium OpenGL ModuleRichard Salter: Using the Titanium OpenGL Module
Richard Salter: Using the Titanium OpenGL Module
 
201801 CSE240 Lecture 15
201801 CSE240 Lecture 15201801 CSE240 Lecture 15
201801 CSE240 Lecture 15
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
 
Travel management
Travel managementTravel management
Travel management
 
C++ file
C++ fileC++ file
C++ file
 
Kapacitor Alert Topic handlers
Kapacitor Alert Topic handlersKapacitor Alert Topic handlers
Kapacitor Alert Topic handlers
 
Doubly linklist
Doubly linklistDoubly linklist
Doubly linklist
 
All you need to know about Callbacks, Promises, Generators
All you need to know about Callbacks, Promises, GeneratorsAll you need to know about Callbacks, Promises, Generators
All you need to know about Callbacks, Promises, Generators
 
Ns tutorial
Ns tutorialNs tutorial
Ns tutorial
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
 
1
11
1
 
Do while loop
Do while loopDo while loop
Do while loop
 
C++ assignment
C++ assignmentC++ assignment
C++ assignment
 
Oop lab report
Oop lab reportOop lab report
Oop lab report
 
Ruby haskell extension
Ruby haskell extensionRuby haskell extension
Ruby haskell extension
 
RxJS Evolved
RxJS EvolvedRxJS Evolved
RxJS Evolved
 
Libtcc and gwan
Libtcc and gwanLibtcc and gwan
Libtcc and gwan
 

Ähnlich wie 201801 CSE240 Lecture 12

What's new in Python 3.11
What's new in Python 3.11What's new in Python 3.11
What's new in Python 3.11Henry Schreiner
 
Compiler Case Study - Design Patterns in C#
Compiler Case Study - Design Patterns in C#Compiler Case Study - Design Patterns in C#
Compiler Case Study - Design Patterns in C#CodeOps Technologies LLP
 
Classes and data abstraction
Classes and data abstractionClasses and data abstraction
Classes and data abstractionHoang Nguyen
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesGanesh Samarthyam
 
friends functionToshu
friends functionToshufriends functionToshu
friends functionToshuSidd Singh
 
Computer Science Sample Paper 2
Computer Science Sample Paper 2Computer Science Sample Paper 2
Computer Science Sample Paper 2kvs
 
Computerscience 12th
Computerscience 12thComputerscience 12th
Computerscience 12thJUSTJOINUS
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksMongoDB
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiMuhammed Thanveer M
 
Operating System Lab Manual
Operating System Lab ManualOperating System Lab Manual
Operating System Lab ManualBilal Mirza
 
CS Sample Paper 1
CS Sample Paper 1CS Sample Paper 1
CS Sample Paper 1kvs
 
Novidades do c# 7 e 8
Novidades do c# 7 e 8Novidades do c# 7 e 8
Novidades do c# 7 e 8Giovanni Bassi
 
Functions in C++
Functions in C++Functions in C++
Functions in C++Nikhil Pandit
 
Programming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for AndroidProgramming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for AndroidEmanuele Di Saverio
 
Final DAA_prints.pdf
Final DAA_prints.pdfFinal DAA_prints.pdf
Final DAA_prints.pdfYashpatel821746
 

Ähnlich wie 201801 CSE240 Lecture 12 (20)

201801 CSE240 Lecture 14
201801 CSE240 Lecture 14201801 CSE240 Lecture 14
201801 CSE240 Lecture 14
 
What's new in Python 3.11
What's new in Python 3.11What's new in Python 3.11
What's new in Python 3.11
 
Compiler Case Study - Design Patterns in C#
Compiler Case Study - Design Patterns in C#Compiler Case Study - Design Patterns in C#
Compiler Case Study - Design Patterns in C#
 
Classes and data abstraction
Classes and data abstractionClasses and data abstraction
Classes and data abstraction
 
C chap16
C chap16C chap16
C chap16
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on Examples
 
friends functionToshu
friends functionToshufriends functionToshu
friends functionToshu
 
Computer Science Sample Paper 2
Computer Science Sample Paper 2Computer Science Sample Paper 2
Computer Science Sample Paper 2
 
Computerscience 12th
Computerscience 12thComputerscience 12th
Computerscience 12th
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New Tricks
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer Melayi
 
Python basics
Python basicsPython basics
Python basics
 
Operating System Lab Manual
Operating System Lab ManualOperating System Lab Manual
Operating System Lab Manual
 
CS Sample Paper 1
CS Sample Paper 1CS Sample Paper 1
CS Sample Paper 1
 
Novidades do c# 7 e 8
Novidades do c# 7 e 8Novidades do c# 7 e 8
Novidades do c# 7 e 8
 
Gradle plugins 101
Gradle plugins 101Gradle plugins 101
Gradle plugins 101
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
201801 CSE240 Lecture 11
201801 CSE240 Lecture 11201801 CSE240 Lecture 11
201801 CSE240 Lecture 11
 
Programming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for AndroidProgramming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for Android
 
Final DAA_prints.pdf
Final DAA_prints.pdfFinal DAA_prints.pdf
Final DAA_prints.pdf
 

Mehr von Javier Gonzalez-Sanchez

Mehr von Javier Gonzalez-Sanchez (20)

201804 SER332 Lecture 01
201804 SER332 Lecture 01201804 SER332 Lecture 01
201804 SER332 Lecture 01
 
201801 SER332 Lecture 03
201801 SER332 Lecture 03201801 SER332 Lecture 03
201801 SER332 Lecture 03
 
201801 SER332 Lecture 04
201801 SER332 Lecture 04201801 SER332 Lecture 04
201801 SER332 Lecture 04
 
201801 SER332 Lecture 02
201801 SER332 Lecture 02201801 SER332 Lecture 02
201801 SER332 Lecture 02
 
201801 CSE240 Lecture 26
201801 CSE240 Lecture 26201801 CSE240 Lecture 26
201801 CSE240 Lecture 26
 
201801 CSE240 Lecture 25
201801 CSE240 Lecture 25201801 CSE240 Lecture 25
201801 CSE240 Lecture 25
 
201801 CSE240 Lecture 24
201801 CSE240 Lecture 24201801 CSE240 Lecture 24
201801 CSE240 Lecture 24
 
201801 CSE240 Lecture 23
201801 CSE240 Lecture 23201801 CSE240 Lecture 23
201801 CSE240 Lecture 23
 
201801 CSE240 Lecture 22
201801 CSE240 Lecture 22201801 CSE240 Lecture 22
201801 CSE240 Lecture 22
 
201801 CSE240 Lecture 21
201801 CSE240 Lecture 21201801 CSE240 Lecture 21
201801 CSE240 Lecture 21
 
201801 CSE240 Lecture 20
201801 CSE240 Lecture 20201801 CSE240 Lecture 20
201801 CSE240 Lecture 20
 
201801 CSE240 Lecture 19
201801 CSE240 Lecture 19201801 CSE240 Lecture 19
201801 CSE240 Lecture 19
 
201801 CSE240 Lecture 18
201801 CSE240 Lecture 18201801 CSE240 Lecture 18
201801 CSE240 Lecture 18
 
201801 CSE240 Lecture 17
201801 CSE240 Lecture 17201801 CSE240 Lecture 17
201801 CSE240 Lecture 17
 
201801 CSE240 Lecture 16
201801 CSE240 Lecture 16201801 CSE240 Lecture 16
201801 CSE240 Lecture 16
 
201801 CSE240 Lecture 10
201801 CSE240 Lecture 10201801 CSE240 Lecture 10
201801 CSE240 Lecture 10
 
201801 CSE240 Lecture 09
201801 CSE240 Lecture 09201801 CSE240 Lecture 09
201801 CSE240 Lecture 09
 
201801 CSE240 Lecture 08
201801 CSE240 Lecture 08201801 CSE240 Lecture 08
201801 CSE240 Lecture 08
 
201801 CSE240 Lecture 07
201801 CSE240 Lecture 07201801 CSE240 Lecture 07
201801 CSE240 Lecture 07
 
201801 CSE240 Lecture 06
201801 CSE240 Lecture 06201801 CSE240 Lecture 06
201801 CSE240 Lecture 06
 

KĂŒrzlich hochgeladen

call girls in Vaishali (Ghaziabad) 🔝 >àŒ’8448380779 🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïž
call girls in Vaishali (Ghaziabad) 🔝 >àŒ’8448380779 🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïžcall girls in Vaishali (Ghaziabad) 🔝 >àŒ’8448380779 🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïž
call girls in Vaishali (Ghaziabad) 🔝 >àŒ’8448380779 🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïžDelhi Call girls
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfWilly Marroquin (WillyDevNET)
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
CALL ON ➄8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂
CALL ON ➄8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂CALL ON ➄8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂
CALL ON ➄8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂anilsa9823
 

KĂŒrzlich hochgeladen (20)

call girls in Vaishali (Ghaziabad) 🔝 >àŒ’8448380779 🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïž
call girls in Vaishali (Ghaziabad) 🔝 >àŒ’8448380779 🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïžcall girls in Vaishali (Ghaziabad) 🔝 >àŒ’8448380779 🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïž
call girls in Vaishali (Ghaziabad) 🔝 >àŒ’8448380779 🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïž
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
CALL ON ➄8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂
CALL ON ➄8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂CALL ON ➄8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂
CALL ON ➄8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂
 

201801 CSE240 Lecture 12

  • 1. CSE240 – Introduction to Programming Languages Lecture 12: Programming with C++ | Getting Started Javier Gonzalez-Sanchez javiergs@asu.edu javiergs.engineering.asu.edu Office Hours: By appointment
  • 2. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 2 Outline 1. Getting Started ‱ namespace, ‱ classes, ‱ scope(public, protected and private), ‱ input and output, ‱ scope resolution operator 2. Memory management ‱ static, ‱ constructor and destructor, ‱ delete 3. Inheritance and polymorphism
  • 3. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 3 Anatomy of a Program class FooBar { int variable; void method() { } }; int x; int main(){ FooBar anObject; } § Data and the operations, that manipulate data, are encapsulated in classes.
  • 4. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 4 Anatomy of a Program class FooBar { private: char a; int variable; protected: int anotherVariable; public: void method1() { } void method2() { } }; int x; int main(){ FooBar anObject; } § Data and the operations, that manipulate data, are encapsulated in classes. § You can defined public, private, and protected components. And, encapsulated data can only be accessed (from outside the class) through their interface (operations defined as public)
  • 5. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 5 Anatomy of a Program class Shape { }; class Rectangle: public Shape { private: FooBar a; }; class FooBar { }; int main(){ FooBar anObject; } § Data and the operations, that manipulate data, are encapsulated in classes. § You can defined public, private, and protected components. And, encapsulated data can only be accessed (from outside the class) through their interface (operations defined as public) § Classes are organized in hierarchies: use and inherit.
  • 6. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 6 Inside each C++ class, it is similar to C program C++ Java C Level of Abstraction In Java, attributes and methods are always in one file. Java have all related information in one place. In C++, implementations of member functions can be in the same file than the class definition (for short functions) or outside of the class definition. C++ argument: structurally clearer to separate implementation from definition
  • 7. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 7 Example in One File: queue.cpp 1. #include <iostream> 2. using namespace std; 3. class Queue { 4. private: 5. int queue_size; 6. protected: 7. int *buffer; 8. int front; 9. int rear; 10. public: 11. Queue(int v) { 12. cout<<"constructorn"; 13. } 14. void enqueue(int v) { 15. cout<<"enqueuen"; 16. } 17. int dequeue(void){ 18. cout<<"dequeuen"; return 5; 19. } 20. }; 21. int main(){ 22. Queue q1(5); 23. Queue *q2 = new Queue(5); 24. 25. // Access Object 26. q1.enqueue(2); 27. q1.enqueue(8); 28. 29. // Access Object Pointer 30. q2->enqueue(25); 31. int x = q2->dequeue(); 32. return 0; 33. }
  • 8. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 8 Example in Two Files: time.h 1. class Time { 2. public: 3. Time(); // constructor 4. void setTime( int, int ); // set hour, minute 5. void printMilitary(); // print military time format 6. void printStandard(); // print standard time format 7. 8. private: 9. int hour; // 0 - 23 10. int minute; // 0 - 59 11. };
  • 9. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 9 Example in Two Files: time.cpp 1. #include <iostream> 2. #include "time.h” 3. using namespace std; 4. Time::Time() { // constructor 5. hour = minute = 0; 6. } 7. void Time::setTime( int h, int m) { // Set a new mil Time 8. hour = ( h >= 0 && h < 24 ) ? h : 0; 9. minute = ( m >= 0 && m < 60 ) ? m : 0; 10. } 11. void Time::printMilitary() { // Print time in military format 12. cout << ( hour < 10 ? "0" : "" ) << hour << ":" 13. << ( minute < 10 ? "0" : "" ) << minute; // add "0" 14. }
  • 10. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 10 Example in Two Files: time.cpp 15. void Time::printStandard() { // Print in standard format 16. cout << ( ( hour == 0 || hour == 12 ) ? 12 : hour % 12 ) 17. << ":" << ( minute < 10 ? "0" : "" ) << minute 18. << ( hour < 12 ? " AM" : " PM" ) << endl; //endl is equal to “n” 19. } 20. 21. int main() { 22. Time t; // new is not mandatory - instantiate object t of class Time 23. cout << "The initial military time is "; 24. t.printMilitary(); 25. cout << "nThe initial standard time is "; 26. t.printStandard(); 27. t.setTime(15, 27); 28. cout << "nnMilitary time after setTime is "; 29. t.printMilitary(); 30. cout << "nStandard time after setTime is "; 31. t.printStandard(); 32. return 0; 33. }
  • 11. CSE240 – Introduction to Programming Languages Javier Gonzalez-Sanchez javiergs@asu.edu Fall 2017 Disclaimer. These slides can only be used as study material for the class CSE240 at ASU. They cannot be distributed or used for another purpose.