G52CPP C++ Programming: DR Jason Atkin E-Mail: Jaa@cs - Nott.ac - Uk
G52CPP C++ Programming: DR Jason Atkin E-Mail: Jaa@cs - Nott.ac - Uk
G52CPP C++ Programming: DR Jason Atkin E-Mail: Jaa@cs - Nott.ac - Uk
C++ Programming
Lecture 1
Dr Jason Atkin
E-Mail: jaa@cs.nott.ac.uk
1
This Lecture
• Course web page
• Why learn C/C++ ?
• History of C and C++
• What this module covers
• Suggested course texts
• Assessment methods
• My view of C/C++ vs Java
• ‘C++ Hello World’ (vs ‘C Hello World’)
2
Information
• Lecture slides, sample code and lab notes
will be on the module web page:
– http://www.cs.nott.ac.uk/~jaa/cpp/g52cpp.html
• Or google me
(Jason Atkin)
• And scroll
down to the
buttons on
my homepage
3
Information
• Web page contents:
– Lecture slides
– Labs information (close to the lab time)
– Coursework information (later on)
– Exam revision information (nearer the exams)
• WARNING: If lecture attendance is low I
will start to remove parts of the slides on
the web – so that you have to fill them in
• Any questions?
– Easiest way is to ask at the lab session
– Or email me: jaa@cs.nott.ac.uk 4
Five reasons to learn C & C++?
1. (Still) utilised in industry
– Why so popular? (after so long)
2. Choose the appropriate tool for the task
– Understand the Java/C# vs C/C++ differences
3. More programming practice
– Much is common across languages
4. Much is VERY similar to Java and C#
– Easier to learn: much will be familiar to you
5. Useful for other modules
– And for 3rd year projects 5
www.langpop.com, normalised, 2011
6
The aims of C and C++
• C still even more popular than C++ and Java
– Especially for operating systems and device drivers
– Where layout in memory matters – control needed
• C came first : with specific design aims
– Ability to write low-level code (e.g. O/S)
– Speed and efficiency
– Ease for programmers, rather than non-programmers
• Cross-platform compilation
– Compared with Assembly code
– Not as much as Java
• Why is C still so popular (over C++ and Java)?
– Control
– Anything you can do in C++ can be done in C
– But may need more code
7
The history of C/C++
In Bell Labs, ‘B’ language created, based on BCPL
1971-1973 : Dennis Ritchie extended ‘B’ to create ‘C’
Main features of C developed over this time
1973-1980 : New features were added
C needed to be standardised!
1979 : Bjarne Stroustrup (Bell labs) extended C to make ‘C with classes’
1982 : ‘K&R’ (Kernighan and Ritchie) unofficial C ‘standard’
1983 : ‘C with classes’ renamed C++, features still being added
1989 : ANSI standard C (started in 1983!) (=> ISO standard in 1990)
Differs in some ways from K&R ‘C’ and is often named ‘C89’
Together with Amendment 1, forms ‘C’ element of ‘C++’
1990s : C++ took centre stage (Standardisation progressing)
1994 : Standard Template Library makes it into the ISO standard C++
(Some template implementation arguments ongoing as late as 2003)
1995 : Java released by Sun
1998 : ISO standard C++ ratified (C++98)
1999 : New version of C standard (C99) (Differs from C++)
8
We will consider C++, G51PRG covered parts of C89
So why C++ rather than C?
• Since everything in C++ could be done in C, why learn
C++?
Understand what is
happening
inside/underneath C++
14
• We will also ignore object oriented theory (‘how’ not ‘why’)
Organisation
• 2 ‘new material’ lectures per week
– 4pm on Monday and Thursday
– Introducing C and C++ concepts
• 1 demo lecture – in a lecture room/slot
– 10am Tuesday
– Demonstrations and more practical
– Usually writing code, no slides
– Introduces the labs and coursework
• 2-hour lab session
– 11am Tuesday – after the demo lecture 15
How to learn C/C++
• Attend the lectures
• Read books & online web sites about C/C++
• But, you also need practice
– Try the samples from lectures
– Try sample programs of your own
• From books or online
– Change existing code
• Observe the effects
16
Exam Questions
• I will assume the following are valid for
exam questions:
– Things covered in the lectures
• Even if not on the lecture slides!
– Things in the samples or lab notes
• Especially the informal coursework
– The basic C/C++ language constructs
• You were introduced to many of these in G51CPP
• Operators, loops, conditionals, etc
– The common C library functions (part of C++)
• e.g. input/output functions, string functions
17
Feedback
• How do you know how well you are doing?
18
Feedback
• How do you know how well you are doing?
20
Recommended Course Text
• The Complete Reference: C++, Fourth Edition
by Herbert Schildt
http://site.ebrary.com/lib/uon/docDe
tail.action?docID=10176700
21
Library:
22
Other Texts (1)
23
Other Texts (2)
24
Assessment
25
Course Assessment
• Course assessment is by
coursework (40%)
and exam (60%)
27
My view of C/C++ vs Java
• C++:
– Power and control: What to do? How to do it?
• Java:
– “Do it my way and I’ll do more of the work for you”
– But it may be less efficient than doing it yourself
– Some things cannot be done in Java alone (JNI)
• Java hides many things from you
– And decides how you will do things
• Java prevents you doing some things and
checks others
– C++ trusts that you know what you are doing
– If you do not, then you can REALLY break things
• Do you want/need the power/control of C++?
28
What is C++?
Procedural C Classes
Global Functions - Grouping of related data together
File-specific functions - With associated methods (functions)
Structs ‘new’ for object creation
Pointers (addresses) ‘delete’ for object destruction
Low-level memory access Constructors, Destructors
C Preprocessor Operator Overloading
Assignment operators
Variables Conversion operators
Arrays Inheritance (sub-classing)
Loops Virtual functions & polymorphism
Conditionals Access control (private/public/protected)
41