Top Banner
Software Development Michael Heron
23

CPP01 - Introduction to C++

Dec 22, 2014

Download

Software

Michael Heron

This is an introductory lecture on C++, suitable for first year computing students or those doing a conversion masters degree at postgraduate level.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CPP01 - Introduction to C++

Software DevelopmentMichael Heron

Page 2: CPP01 - Introduction to C++

Introduction• Welcome to the module!• I hope you enjoy it.

• In this module we are going to be talking about how to build programs using the C++ programming language.• This serves as preparatory work for you moving onto more

advanced coding next semester.• Programming is a lot of fun (honest), but it’s also a difficult

topic to learn.• It’s really important that you stick with it!

Page 3: CPP01 - Introduction to C++

Introduction• Programming is about more than just learning some technical

skills.• There’s a state of mind that goes with it as well.

• Part of the fun of programming lies in looking at it like a kind of logical puzzle.• It’s on this basis that many people code recreationally.

• Mostly, programming is about pattern recognition.• This is an extremely transferable skill.

Page 4: CPP01 - Introduction to C++

Structure of the Module• There are three lectures for this module every week:

TIMES

• There is also a two hour lab every week.

TIMES

Page 5: CPP01 - Introduction to C++

Structure of the Module• In the first two lectures, we’ll talk about programming topics.• In the third, we’ll do some collaborative class-work .• Programming is often best done away from a computer.

• In the lab, we’ll alternate between courseworks and class exercises.

Page 6: CPP01 - Introduction to C++

Structure of the Module• The module has three sets of assignments.• The first is a portfolio of projects developed through the

weeks.• Four small programs.• This counts for 20% of your grade.

• The second is a larger project that you decide upon yourself.• With guidance/approval from me• This counts for 20% of your grade

• The third part is an exam.• This counts for 60% of your grade

Page 7: CPP01 - Introduction to C++

Programming• Programming is one of the most unique things anyone ever

learns to do.• I have never encountered anything quite like programming in

terms of the blend of skills it requires.• Fundamentally, it is about compensating for one simple fact.• Computers are soul-crushingly stupid, and they need people to

tell them what to do.

Page 8: CPP01 - Introduction to C++

Class Exercise• So, let’s see what writing a program works like in the abstract.• Get into groups of two or three.• Decide on a simple(ish) shape to draw.• Not a simple geometric shape, but nothing especially

complicated.• Then, write out the instructions for drawing that shape as

precisely as you can.• For someone who doesn’t know what your shape is supposed to

be.• After a few minutes, I’ll draw your shapes on the board from

the instructions you give me.

Page 9: CPP01 - Introduction to C++

A Computer Program• A computer program breaks down into a series of very small,

very specific instructions to the computer.• These have to be in the computer’s own language.• A series of low level, primitive grunts and whistles.

• 1s, 0s, and the ability to perform trivial operations on those numbers.

• In the Olden Days, this is how people wrote computer code.• In machine code

Page 10: CPP01 - Introduction to C++

Modern Programming• Over the years, we have increasingly abstracted away from

this idea.• We now use what are known as high level languages.

• High level indicates how far we are abstracted from the underlying 1s and 0s

• Most programming languages are now designed to be human readable.• Well…

Page 11: CPP01 - Introduction to C++

Modern Programming• C++ is an example of a high level language.• It frees us up to think about programs in terms of the flow of

logic rather than on the ‘administrative’ work.• We write in a vaguely human readable language.• Special software tools then turn this human readable language

into something the computer can understand.

Page 12: CPP01 - Introduction to C++

Compilation• The process of turning our human readable code into

something the computer understands is called compilation.• It’s kind of a translation process.

• In order for compilation to be possible, programming languages have to be very strict.• Computers cannot deal with ambiguity.

• The exact rules we must obey when giving instructions to the computer is known as the language syntax.

Page 13: CPP01 - Introduction to C++

Compilation• Where there is ambiguity, or when things have not been

expressed precisely enough for the compiler, it issues what are called syntax errors.• Essentially the compiler says ‘Woah, I don’t even know how to

turn that into something the computer understands!’• These must be fixed before a program can be compiled at all.• C++ complicates it by making the error messages horribly

unhelpful, but we’ll talk about these as we go along.

Page 14: CPP01 - Introduction to C++

The Implications• The implications of all of this is that it’s really important to

follow instructions that you are given – not just to the letter, but down to the punctuation• Punctuation symbols in computer languages are used to express

special meaning.• This will come easier with practice.• The rules aren’t complicated, they are just necessarily fiddly.

Page 15: CPP01 - Introduction to C++

After Compilation• Once your program has no more syntax errors (in technical

terms, it compiles), the program is then executed (or run).• Here is where the next level of problems occur.

• When a program loads, but doesn’t do what it’s supposed to do, it is said to have logic errors.• The problem is in what code has been written, not how the code

has been written.

Page 16: CPP01 - Introduction to C++

A Note of Advice• Please do not look on errors as a bad thing.• They’re really, really not at this stage.

• You will learn more from getting errors and fixing them than you will from getting everything right the first time.• Nobody gets everything right the first time.

• It’s easy to get discouraged, but you have to think of each error you solve as a little mini-lesson in programming.• As long as you know why it happened, and how to avoid it

happening in the future, you just became a better programmer.

Page 17: CPP01 - Introduction to C++

Writing a C++ Program• In the labs, we are going to be using a piece of software called

Visual Studio .NET.• It’s tremendously powerful, and as such not the easiest thing in

the world to use.• This is a package of software known as an Integrated

Development Environment (IDE).• You use your IDE to create the programs that the computer

will run.

Page 18: CPP01 - Introduction to C++

What We Study• This module is not just about writing programs.• You can feel free to disbelieve that, since we’ll be doing that a lot.

• It’s about building the skills and mindset needed to be able to write programs properly.• It’s about:

• Designing• Coding• Debugging• Testing• Documentation

Page 19: CPP01 - Introduction to C++

What We Study• You are not going to learn how to do any of this in these

lectures.• All these lectures can do is point you in the right direction.

• The only way you learn about programming is by practicing it.• It’s an active, doing skill. It’s not something you know, it’s

something you do.

Page 20: CPP01 - Introduction to C++

Practice• The lectures will introduce new syntax, new tools, and new

techniques.• The assessments will make sure you can use them.• In between those two, you have to practice.• Just write programs. Play about with programs you are given.

• Experiment with your programs.• Make a copy of code that works, and then just change things

around to see what happens.• ‘Well, do that and see what happens’ is something you’ll hear me

say a lot.

Page 21: CPP01 - Introduction to C++

Learning to Program• Programming is a skill built cumulatively.• If you fall behind, you’ll need to make the effort to catch up.

• You can’t miss any of the material and still progress.

• If you are having problems, the absolutely wrong way to deal with them is to skip classes.• That just makes the problem worse.

• Even if you find it difficult to begin with, there’s no reason to believe you always will.• There’s a point, and it’s a different point for everyone, where it all

just clicks.

Page 22: CPP01 - Introduction to C++

Programming is Fun• It really is, and that doesn’t get said enough.• Writing a program is like solving a crossword, or a Sudoku

puzzle.• Because it’s a pattern solving exercise, there are also many

ways in which you can get better at programming.• Many programmers are also good chess players for example,

because both are creative ,pattern solving exercises.

Page 23: CPP01 - Introduction to C++

Summary• Welcome to your module!• Programming is challenging, but very rewarding.• It’s also a skill very few people have.

• We’ll be writing C++ programs.• We write them• We debug them• We execute them

• Most of this is down to you.• I’m here to help, but I can’t really teach you how to do any of

this!