Top Banner
1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek
25
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: 1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek.

1

C++ for beginnersLecture 0

© 2008 Richèl Bilderbeek

Page 2: 1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek.

2

Question

• Which kind of programs can be written in C++?

Page 3: 1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek.

3

Answer

• Every kind of program

Page 4: 1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek.

4

Question

• Which programming style does C++ enforce?

Page 5: 1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek.

5

Answer

• None

Page 6: 1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek.

6

About C++

• Developed by Bjarne Stroustrup in 1983

• ‘A better C’

• (largely) backwards-compatible with C

• Emphasis on speed

• Platform independent, but without standard graphics support

• Many users (but declining in favor of C# and Java)

Page 7: 1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek.

7

About C++

• Multi paradigm language– You are allowed to do everything you want– You want to overload the plus operator to

subtract? That's fine– You don't want to program in a const-correct

way? That's fine– You don't want to use templates? That's fine– You don't want to use classes? That's fine

Page 8: 1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek.

8

Question

• In which ways should your Integrated Development Environment (IDE) (your 'programming program') help you?

Page 9: 1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek.

9

Answer

• Depends on your needs

• But a beginner can use all the help he/she can get!

Page 10: 1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek.

10

C++ Builder 6

• Borland (now CodeGear) IDE

• Helpful while programming– Function and class browsing

• Helpful while debugging– Breakpoints, step through code, call stack

• VCL library for Graphical User Interface (GUI) ('Windows') applications

Page 11: 1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek.

11

Question

• Which book is the best book to use for a beginners training?

Page 12: 1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek.

12

Answer

• Depends on the trainee– Dutch or English?– Easy read or correct?

Page 13: 1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek.

13

The book

• Ammeraal. C++. 6e editie, 2001.– Fine Dutch reference– Partly outdated*, due to this sometimes unusual

or 'evil' style

*The most important books came out later...

Page 14: 1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek.

14

Question

• What should be in a training manual?

Page 15: 1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek.

15

Answer

• Summary of the treated theory, especially the theory that cannot be found in the book

• Correction of the book

• Advice

• Additional exercises

• All is in the manual

Page 16: 1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek.

16

This training

• Day 1: Basics

• Day 2: Functions

• Day 3: std::vector

• Day 4: Classes

• Day 5: Polymorphism and inheritance

Page 17: 1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek.

17

A day of training

• 9:00 startup up with coffee

• 9:30-10:30: lecture

• 10:30-10:45: break

• 10:45-12:30: to work

• 12:30-13:15: luch

• 13:15-14:45: to work

• 14:45-15:00: break

• 15:00-16:30: to work

Page 18: 1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek.

18

Question

• Which steps are between code and executable?

Page 19: 1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek.

19

Answer

• Compiling– Convert code of each unit to object code– Many checks of your code

• Linking– Connects unit object code to single executable

Page 20: 1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek.

20

Your compiler is your friend

• The compiler does many checks on your code

• The compiler knows how you should write valid C++

• The compiler will give you advice in the form of warnings and 'errors'

• Always compile cleanly

Page 21: 1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek.

21

'Hello world' program

#include <iostream> //Header file

int main()

{

std::cout //Write to screen

<< “Hello world” //this text

<< std::endl; //end line

std::cin.get(); //wait for key

}

Page 22: 1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek.

22

Question

• Can you get a 'Hello World' program to run in C++ Builder 6?

• What to do if you don't succeed?

• If you make errors (on purpose), what does the compiler tell you?

• Can you save and load it?

• Try!

Page 23: 1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek.

23

Hint

• Always first do 'File | Close All'

Page 24: 1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek.

24

Hint

• Start a Console Application by – 'File | New | Other'– Select 'Console Wizard'– Set 'Source' to C++– Only leave 'Console Application' checked

Page 25: 1 C++ for beginners Lecture 0 © 2008 Richèl Bilderbeek.

25

Hint

• C++ Builder will create a Project and a Unit for you. Let the filename for the Project start with 'Project', let the filename for the Unit start with 'Unit'. If they are the same you loose either your project (ok) or your code (very bad)