850 likes | 876 Views
Introduction to OO Programming in C++ and Java. The lecturer of this course Dr Vasos Pavlika Vasos.Pavlika@conted.ox.ac.uk vp4@soas.ac.uk vpavlika@lse.ac.uk VPavlika@sgul.ac.uk (Vas for short). Course Lecturer. Dr Vasos Pavlika, Subject Lecturer at SOAS, University of London.
E N D
Introduction to OO Programming in C++ and Java The lecturer of this course Dr Vasos Pavlika Vasos.Pavlika@conted.ox.ac.uk vp4@soas.ac.uk vpavlika@lse.ac.uk VPavlika@sgul.ac.uk (Vas for short)
Course Lecturer • Dr Vasos Pavlika, Subject Lecturer at SOAS, University of London. • Subject Lecturer and online Tutor in Mathematical Economics at SOAS, University of London. • Senior Teaching Fellow, SOAS, University of London • Lecturer for the Department for Continuing Education, University of Oxford. • Associate Lecturer: New College, Oxford • Saturday School Lecturer: The London School of Economics and Political Science. • Associate Tutor: St George’s Medical School, University of London. • Consultant Mathematician. • Previously Senior Lecturer at the University of Westminster. • Field Chair at the University of Gloucestershire
Course BookYou should get a copy Programming and Problem Solvingwith C++ by Nell Dale 4th Edition ISBN 07637 0798-8 I will simply refer to this as Dale. E.g. Please do exercises 2-4 on page 101 in Dale. There is also a version available that includes a student edition of the Visual C++ Program Development Studio.
NOTE: Additional Books I may refer to the text: C++ from the Ground Up, 2nd Edition, by Herbert Schildt, ISBN: 0078824052 There are many good C++ books around, the net is also a good source of information. I will occasionally be handing out notes. I can send you the notes (Powerpoint slides) provided you email me first so that I have your reply addresses.
Lecture Format As of next week, each lecture will comprise a “Warm up Exercise” which consists of the writing of little programs in C++ using your understanding of the previous week’s material, occasionally you may have to give descriptive solutions. I will be using Microsoft Powerpoint presentations to introduce the material. There will be Tutorial Questions set weekly or fortnightly which can be used to obtain completion of the course and the associated CATS points. • A series of portfolio exercises and tutorial exercises will be set during the course, these exercises will constitute a log book of exercises that will count as the coursework component for this course. • These exercises will consists of programs as well as descriptions of topics covered in the lectures.
Portfolio Exercises • There will be two portfolio exercises for each 10 week course one in C++ the other in Java. • These are assessed and counts towards the award of the CATs Points • You can not be awarded the CATs points if your attendance falls below 70%.
Getting onto the system here at Oxford • Click TeachingTerminal1 • conted\ehc • murphyslaw • Locate quincy • Tools->option->Build goto compiler and type c:MinGW • ok
What is computer programming? • Getting a computer to do what would be extremely time consuming and inaccurate if a person was to do it. OR • Processing input data to produce an output.
Why use Computers? • Computers we know are very good at doing repetitive tasks without making mistakes and without complaining. • It would be difficult to get a human to sum the first 10,000 integers and of course to get it right, this would be child’s play for the computer.
The IDE • The IDE (Integrated Development Environment) used here at OUDCE is Quincy • Go to programs • Locate Quincy • Right click on the mouse when on Quincy to copy it onto the desktop • Launch Quincy
The Problem is that computer programming • It is very different from what many of you have done before. • It is the least “doable” subject from books. • One can not just read about programming and expect to become a master in it. • Requires creative problem solving (thinking) • Requires courage and confidence • Requires good organisation • Requires practice • Requires a version of C++ at home
The good thing is • We are all natural problem solvers! • In our lives we are constantly solving problems. • What to have for lunch? • Where to go on holiday? • How much will I earn this week at work?
The bad thing is • Many have difficulties generalising their day to day problem solving skills to the precision required for problem solving in computing. • E.g. A very simple example Bobs Bank
Bobs Bank • Problem • Given the current rate of interest, how much will all my customers have in their deposit accounts at the end of… • 1,2,3,…N years? • We want to write a program to solve this problem.
Computers are a bit dim! • We have to detail precisely the instructions… There is no Mr Data from Star Trek here, no computer understands English! • We must be able to figure out how to solve the problem first (on paper) before we attempt to write a computer program to tackle the task.
Analysis and Specification Design Implementation Testing Installation Operation and Maintenance Developing software: the traditional approach The Water Fall Method
The Waterfall model • Many people use “code and fix”, which means you sit at your computer, code and correct bugs when or if they are encountered. • This is fine if your program is small. • For programs with thousands of lines of code, you will have to do things away from the computer
Waterfall Model continued The standard Waterfall Model for systems development is an approach that goes through the following steps: • Document System Concept (what am I going to do) • Identify System Requirements and Analyze them • Analysis: what is it that I am going to build? • Break the System into Pieces (Architectural Design) • Design Each Piece (Detailed Design) • How am I going to achieve this? • Code the System Components and Test them Individually (Coding, Debugging, and Unit Testing) • Sometimes this is called the implementation phase
Waterfall Method continued • Integrate the Pieces and Test the System (System Testing) • Deploy the System and Operate It • Maintain the system updating the system when the need arises • Bring out later/better editions • This model is widely used on large governmental systems, particularly by the Department of Defense (DOD).
The Waterfall Model • One of the draw backs of the Waterfall Model is that each stage in the cycle (or process) must be completed before moving on to the next stage. • This can cause timing problems i.e. one simply does not have enough time to complete each task. • Are there other (and hopefully better) ways of doing things?
Analysis Building Prototypes Initial Planning Final Product Testing and Quality Assurance Reviewing Prototypes Developing software: the modern approach (RAD) RAPID APPLICATION DEVELOPMENT (RAD)
Rapid Application Development (RAD) • DEFINITION a software development process that allows usable systems to be built in as little as 60-90 days, often with some compromises. • Drawback: the final product often does not meet the exact requirements originally requested, there is a trade off in requirements.
RAD continued • PRINCIPLES BEHIND THE DEFINITION • In certain situations, a usable 80% solution can be produced in 20% of the time that would have been required to produce a total solution. • In certain situations, the business requirements for a system can be fully satisfied even if some of its operational requirements are not satisfied. • In certain situations, the acceptability of a system can be assessed against the agreed minimum useful set of requirements rather than all requirements.
PROBLEMS ADDRESSED BY RAD • With conventional methods, there is a long delay before the customer gets to see any results. • With conventional methods, development can take so long that the customer's business has fundamentally changed by the time the system is ready for use. • With conventional methods, there is nothing until 100% of the process is finished, then 100% of the software is delivered. • Hopefully this is still what is required by the user
Why Use RAD? • Problems with USING RAD • to prevent cost overruns(RAD needs a team already disciplined in cost management) • to prevent runaway schedules (RAD needs a team already disciplined in time management) • Good points for USING RAD • to converge early toward a design acceptable to the customer and feasible for the developers • to limit a project's exposure to the forces of change • to save development time, possibly at the expense of economy or product quality
Bobs Bank (tidy version) • Get the current interest rate (say 6%) • Get the number of years ahead we want the results for (1,2,3,N) • Get their current deposit value • Work out the calculation • If years equals 1 then • use equation 1 and Display the results • If years equals 2 then • use equation 2 and Display the results • If years equals 3 then • use equation 3 and Display the results • If years equals anything else • display an error message
//Bobs Bank#include <iostream>using namespace std;int main() { double interest; double deposit; double value; int years; cout << "hello, please enter the current interest rate : "; cin >> interest; cout << "now, please enter the initial deposit : "; cin >> deposit; cout << "now enter the number of years 1,2 or 3 ahead to calculate : "; cin >> years; if (years == 1) { value = deposit*(1 + interest); cout << "Value after " << years << " year is " << value << endl; } else if (years == 2) { value = deposit*(1 + interest)*(1 + interest); cout << "Value after " << years << " years is " << value << endl; } else if (years == 3) { value = deposit*(1 + interest)*(1 + interest)*(1 + interest); cout << "Value after " << years << " years is " << value << endl; } else { cout << "Invalid number of years entered" << endl; }//this is Bank1.cpp return 0;}
Demo • Please see hello1.cpp • Bank1.cpp • and explain • Show • Payroll.cpp (which is a bit advanced for week 1, look at others in folder first)
Practice, Practice, Practice • Computer programming is more like • Learning a musical instrument • Learning to play a new sport • Driving a car • It is an active process • It is an incremental process • It constantly builds from previous knowledge • TRY NOT to get left behind as it is VERY hard to catch up!
Why, What, How, Where and When • Why are you learning to program? • What will you learn? • How will you learn? • How will you be assessed? • Where will you learn? • When will you learn?
Why are you learning to Program?Or what’s in it for me? • For purely academic interest (I wish!) • To get a job and pay off your loans! • Because you want to move onto more courses here at Oxford or elsewhere.
Why are you learning to Program?Or What is in it for me? • Because it impacts on every subject you take, the programming principles you learn are applicable to other programming languages. • Learning C++ and Java here at OUDCE will enable you to pick up other languages very easily.
Why C++ • Supports procedural programming and object oriented programming. • What is OO programming? • An object is a variable of type class • What is procedural programming? • Functions/procedures • C/C++ de-facto industry standard programming language. • It works on the network here (I hope! We had problems last year!)
Why C++ • Friendly development environment and good debugging tools. • Cheap for student edition • C++ rather than C because I/O friendlier, easier introduction of functions and strings. • Supports Object Oriented Programming, C does not. • Java is even nicer, does away with pointers (hides their usage somewhat)
Procedural paradigm • Sequential • Program runs from top down, one command performed, then move onto the next • Selection • Can make choices in a program • Iteration • Can repeat certain parts of your program which are only terminated when certain criteria are satisfied
OO paradigm • Encapsulation • Polymorphism • Inheritance Both C++ and Java have these OO capabilities We will be introducing these concepts in due course
What will you learn? • You will learn how to begin the process of problem solving and designing a solution. • You will learn how to write the solution to a problem in an unambiguous way. • You will learn how to verify the solution i.e. Whether it is correct.
What will you learn? • You will learn how to use the C++ development environment to build and debug your programs. • You will learn how to translate the solution into C++ code in a systematic way. • You will learn how to verify whether the C++ code for the solution is correct. • You will learn the basic syntax and structure of simple C++ programs.
What you will learn? • You will learn how to apply the basic control structures in C++; sequences, selection, repetition, and subprogram (function) invocation. • You will learn how to construct and use the built in data structures; integer (int), double, char, strings (strictly speaking this is not built in!), arrays, files, structs and classes • You will learn the fundamentals of object oriented programming by creating classes and using objects
Overall Syllabus Goal (Term1) To be able to: • investigate and analyse a “real world problem” • Produce and verify a solution formally • Using sequences, selection, repetition and subprogram invocation. • Using C++ implement and test your solution - like we did with Bobs Bank • Introduce OO concepts
How will you learn? • Lectures with demonstrations, tutorials and portfolio exercises. • You have a course book with exercises and tutorials. (Sorry about the American bias!) • Check the internet there is a huge amount of material available • Check the library for resources • Try to find your own books to complement the course book
How will you learn? • YOU will have to take responsibility for learning to program by doing it. IT CAN NOT BE CRAMMED! • You cannot learn to program by reading a book – it is more like learning to play a musical instrument or driving a car! • This is a 10 week course worth 10 CATs points. • We estimate that you should try to put in at least 2 hours at home per week during the week away from the lab here
How will you learn? • Tutors (just me this year), are here to get you out of holes, and give one to one advice on techniques. Suggest approaches to problems NOT to solve problems for you. • I am here to answer any questions on written pre-lab and lab-exercises. • If you do not complete the set work in the tutorial it is hoped that you will complete the work in your own time as I follow on from the previous weeks lecture each week!
How will you be assessed? • Working at home/in other times. You should do this if you want any success. • Do not simply rely on exercises that I set, please work from your book. • If you want you can email me your work each week to look at and to give you feedback.
How will you be assessed? • At the end of each term you will be awarded the 10 CATs points (if you have enrolled of course and created appropriate programs and written answers), you receive confirmation of the award from the University of Oxford • NOT FROM ME.
Resources and To Do List! • You need to purchase a course book, and attempt exercises for next week. • Brush up on your basic windows skills, learn to; • rename files • create folders and subfolders • copy & move files to and from hard disk and floppy disk • delete files and folders
Resources and To Do List! • I will email the Powerpoint presentation to each of you after each lecture for you to have, tutorial questions will be given in the lectures. • I will also send source code for demonstration programs. You may want to download a free IDE and compiler these are available on the internet. E.g.http://www.bloodshed.net/dev/devcpp.html There is even talk of a site for our course, I will look into this for next week.
Resources and To Do List! Summary • Get C++ on your computer at home. • Send me an email. • Buy Course book and do initial pre-tutorial work. • Buy USB disks to take your work home etc.
The infamous Hello_World program • See programs in Week 1 folder and explain