250 likes | 457 Views
C++ for beginners Lecture 0. © 2008 Richèl Bilderbeek. Question. Which kind of programs can be written in C++?. Answer. Every kind of program. Question. Which programming style does C++ enforce?. Answer. None. About C++. Developed by Bjarne Stroustrup in 1983 ‘A better C’
E N D
C++ for beginnersLecture 0 © 2008 Richèl Bilderbeek
Question • Which kind of programs can be written in C++?
Answer • Every kind of program
Question • Which programming style does C++ enforce?
Answer • None
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)
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
Question • In which ways should your Integrated Development Environment (IDE) (your 'programming program') help you?
Answer • Depends on your needs • But a beginner can use all the help he/she can get!
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
Question • Which book is the best book to use for a beginners training?
Answer • Depends on the trainee • Dutch or English? • Easy read or correct?
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...
Question • What should be in a training manual?
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
This training • Day 1: Basics • Day 2: Functions • Day 3: std::vector • Day 4: Classes • Day 5: Polymorphism and inheritance
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
Question • Which steps are between code and executable?
Answer • Compiling • Convert code of each unit to object code • Many checks of your code • Linking • Connects unit object code to single executable
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
'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 }
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!
Hint • Always first do 'File | Close All'
Hint • Start a Console Application by • 'File | New | Other' • Select 'Console Wizard' • Set 'Source' to C++ • Only leave 'Console Application' checked
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)