1 / 32

Concepts in C++

Concepts in C++. Games Audio Programming. Lecture 1. About the module Lectures/Tutorials The Assessment Assignment Language introduction. Module Text. Deitel, H.M. & Deitel, P.J. (2003) C++ How to program , Prentice Hall, U.S. ISBN 0-13-111881-1

Download Presentation

Concepts in C++

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Concepts in C++ Games Audio Programming

  2. Lecture 1 • About the module Lectures/Tutorials • The Assessment Assignment • Language introduction

  3. Module Text • Deitel, H.M. & Deitel, P.J. (2003) C++ How to program, Prentice Hall, U.S. ISBN 0-13-111881-1 • Liberty, J. & Horvath, D.B. (2005) Teach Yourself C++ in 24 Hours,Sams, USA. ISBN 0-672-32681-7 • Overland, B. (2005)C++ Without FearPrenctice Hall, USA. ISBN 0-321-24695-0

  4. Module Text for C++ • If available – second hand?Graham, N (1991) Learning C++McGraw Hill, USA. ISBN 0-07-100849-7 • Eckle, B. (2000) Thinking in C++ (Volume 1)Eckle, B. (2003) Thinking in C++ (Volume 2) • Both available as free downloadhttp://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html • Vol 1 – 867KB; Vol 2 – 991KB

  5. Module Schedule • Availability • Blackboard • Available beyond University Network

  6. Integrated Development Environment (IDE) • Using Microsoft Visual Studio.NET • Strictly C++ • Initial User Guide on Blackboard • Self discovery also required • Other IDE may be used – Borland, UNIX/Linux, Command Line) as long as strictly C++ • Should run on University computers though may use Notepads / Laptops.

  7. using namespace std;

  8. bool

  9. Class – Specifying the access • Class – default will not allow access • Access Specifiers • private: default • public: allows external access • protected: restricted external access • Concentrate on public & private for now. • protected covered in later lecture

  10. Constructor usage • Initialisation parameters added to code • e.g.int main(void){ Account Tom(250.00, 5.3);} • Tom’s account will be instantiated with… • An opening balance of £250.00 and • An opening interest rate of 5.3%

  11. Using a prototype #include <iostream> using namespace std; void function1(bool val); void function2(bool val); int main() { function1(true); function2(true); } void function2(bool val) { cout << "This is function 2" << endl; if (val) function1(!val); } void function1(bool val) { cout << "This is function 1" << endl; if (val) function2(!val); } function prototypes or declarations function definitions

  12. Header files • when developing larger programs, it is useful to put the prototypes in a separate header file • suffix .h, for example MyFunctions.h • any program file that uses these functions can include the header file #include “MyFunctions.h” • this enables the compiler to check the parameters and return type of any functions called are correct • without needing to access the function definitions • header files can also contain constants, enums, structures and class declarations • the use of header files allows the same declarations to be used in many .cpp files

  13. Guarding against multiple inclusions • functions can be declared multiple times in the same source file • prototypes repeated • but defined only once • method body • structures, enums and classes can be declared only once • it's easy to include the header file twice in the same source file • guard against this by using conditional definition or pragma

  14. Account.h #ifndef ACCOUNT_H #define ACCOUNT_H class Account { private: double balance; double interestRate; public: Account(double initialBalance, double rate); double getBalance(); void deposit(double amount); void withdraw(double amount); void addInterest(); }; #endif

  15. account.cpp #include "account.h" Account::Account(double initialBalance, double rate) : balance(initialBalance), interestRate(rate) { } double Account::getBalance(){return balance;} void Account::deposit(double amount) { balance += amount; } void Account::withdraw(double amount) { // implement this method yourself } void Account::addInterest() { balance *= (1 + interestRate/100.0); }

More Related