Download presentation
Presentation is loading. Please wait.
Published byAshley Robinson Modified over 9 years ago
1
Further Programming Concepts in C++ Ce00314-5
2
Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi Choice) 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 Fear Prenctice Hall, USA. ISBN 0-321-24695-0
4
Module Text 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 download http://www.mindview.net/Books/TICPP/ThinkingInCPP 2e.html http://www.mindview.net/Books/TICPP/ThinkingInCPP 2e.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.
10
using namespace std;
14
bool
15
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
26
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.00and An opening interest rate of 5.3%
28
Using a prototype #include 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
29
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
30
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
31
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
32
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); }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.