Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions...
-
Upload
ashley-robinson -
Category
Documents
-
view
214 -
download
0
Transcript of Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions...
![Page 1: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/1.jpg)
Further Programming Concepts in C++
Ce00314-5
![Page 2: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/2.jpg)
Lecture 1
About the module
Lectures plus Q&A sessions
Tutorials The Assessment
Assignment
Class Test (Multi Choice) Language introduction
![Page 3: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/3.jpg)
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
![Page 4: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/4.jpg)
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/ThinkingInCPP2e.html
Vol 1 – 867KB; Vol 2 – 991KB
![Page 5: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/5.jpg)
Module Schedule
Availability Blackboard
Available beyond University Network
![Page 6: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/6.jpg)
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.
![Page 7: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/7.jpg)
![Page 8: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/8.jpg)
![Page 9: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/9.jpg)
![Page 10: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/10.jpg)
using namespace std;
![Page 11: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/11.jpg)
![Page 12: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/12.jpg)
![Page 13: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/13.jpg)
![Page 14: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/14.jpg)
bool
![Page 15: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/15.jpg)
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
![Page 16: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/16.jpg)
![Page 17: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/17.jpg)
![Page 18: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/18.jpg)
![Page 19: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/19.jpg)
![Page 20: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/20.jpg)
![Page 21: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/21.jpg)
![Page 22: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/22.jpg)
![Page 23: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/23.jpg)
![Page 24: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/24.jpg)
![Page 25: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/25.jpg)
![Page 26: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/26.jpg)
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%
![Page 27: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/27.jpg)
![Page 28: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/28.jpg)
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
![Page 29: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/29.jpg)
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
![Page 30: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/30.jpg)
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
![Page 31: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/31.jpg)
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
![Page 32: Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf8a1a28abf838c8a710/html5/thumbnails/32.jpg)
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); }