Docsity

Introduction - Computer Science II - Lecture Notes | COP 3503, Study notes of Computer Science

Toggle sidebar
bg1
COP 3503 – Computer Science II – CLASS NOTES DAY #1
INTRODUCTION
Problem-Solving Techniques
1. Understand the problem completely.
2. Divide the problem into manageable pieces (divide and conquer)
3. Create solutions
4. Consider alternative solutions and refine the one selected
5. Implement the solution
6. Test and fix the solution
Polymorphism
(a general definition – having many forms)
Creating a general solution for a class of problems which may be further specified
to solve particular instances of the problem.
Syntax
A set of rules of a programming language that dictates the legal form of a
program
Semantics
Describes the meaning of the program statements
Day 1 -1
Example: Class of problem: addition
Polymorphic solution: counting
Specific problem #1: 3 + 1
Specific solution for #1: counting on your left hand
Another specific solution for #1: counting on your right hand
Specific problem #2: 3 + 4
Specific solution for #2: counting on both hands
Specific problem #3: 10 + 7
Specific solution for #3: counting on fingers and toes
pf3
pf4
pf5

Partial preview of the text

Download Introduction - Computer Science II - Lecture Notes | COP 3503 and more Study notes Computer Science in PDF only on Docsity!

COP 3503 – Computer Science II – CLASS NOTES DAY

INTRODUCTION

Problem-Solving Techniques

1. Understand the problem completely. 2. Divide the problem into manageable pieces (divide and conquer) 3. Create solutions 4. Consider alternative solutions and refine the one selected 5. Implement the solution 6. Test and fix the solution Polymorphism (a general definition – having many forms) Creating a general solution for a class of problems which may be further specified to solve particular instances of the problem. Syntax  A set of rules of a programming language that dictates the legal form of a program Semantics  Describes the meaning of the program statements

Example: Class of problem: addition

Polymorphic solution: counting

Specific problem #1: 3 + 1

Specific solution for #1: counting on your left hand

Another specific solution for #1: counting on your right hand

Specific problem #2: 3 + 4

Specific solution for #2: counting on both hands

Specific problem #3: 10 + 7

Specific solution for #3: counting on fingers and toes

Compile-Time Errors  Errors in syntax that can be caught by the compiler. These can be fatal or non- fatal. A fatal syntax error will halt compilation at the point of the fatal error. A non-fatal error will allow compilation to continue (although sometimes not correctly). Run-Time Error  Errors in semantics. This causes your program to blowup. Logical Errors  Errors in semantics which do not cause a run-time error but produce erroneous results. Encapsulation  A form of information hiding  Keeping data and non-essential methods private. Public methods are provided to allow user interaction.  Obscures or hides non-essential details and methods.  Objects are encapsulated. The rest of the system interacts with an object only through a well-defined set of services that it provides. Abstraction

Example: consider the sentence: “No fruit flies like a banana.”

Syntax is: qualifier / noun phrase / verb / noun phrase

Semantics: not(x) [ fruit fly (x) and likes(x, banana)]

Read as: there isn't a fruit fly that does not like

bananas.

OR - Syntax is: qualifier / noun / verb / adjective phrase

Semantics: not(x) [ fruit (x) and flies (x)  flies

(banana)]

Read as: there isn't any fruit that flies like a banana.

 Each subclass has one explicit parent ONLY but inherits from all "straight line" ancestors implicitly.  The original class used to define the new class is called the parent class , or superclass , or base class.  The derived class is called a child class , or subclass. (Java uses the keyword extends to indicate that the new class is being derived from another.)  The child class automatically inherits an initial set of methods and variables from the parent class. The inherited variables and methods can be used by the child class as if they had been locally declared in the child class. Multiple Inheritance: In multiple inheritance a subclass can inherit explicitly from an unbounded number of parent classes. Object Thing Stuff Kart Margay CRG motor Mine Compan y Chalk Books Stuffing This one

CS

texts COP 3503 T-day dinner

This is not good in general! Why? Consider the following situation. Problems:

  1. Which constructor does chalk use?
  2. If Truck and Car have methods with the same name – which method does Pick- up inherit?  Java uses interfaces (potentially multiple-levels of interfacing) to support some of the functionality of multiple-inheritance.  Java’s techniques allow for the “good” part of multiple inheritance without the “bad” parts Object constructor get constructor Truck constructor get constructor Car constructor get constructor Pick-up constructor