Further Programming Concepts in C++ Ce00314-5. Lecture 1 About the module Lectures plus Q&A sessions...

32
Further Programming Concepts in C++ Ce00314-5

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.

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.

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.

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.

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.

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.

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.
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.
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.
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.

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.
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.
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.
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.

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.

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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.

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.
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.

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.

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.

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.

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.

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); }