1.4 Principles of programming Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What are meta languages and why are they preferable to using natural English

A

meta language - a language which describes the syntax of another language (e.g. BNF, syntax diagram)

They are preferable to natural languages as they are unambiguous (sentence has one meaning) which is good for the computer as it needs to know precisely what it is being asked to do when running the program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

define syntax

A

rules of a particular programming language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

do bnf questions

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

do syntax diagram questions

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

why do programming languages need to be unambiguous and compare to natural language

A

programming languages need to be unambiguous because:
-computers have to know exactly what it is being asked to do

this is unlike natural languages which are ambiguous

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what is a programming paradigm and describe the various paradigms

A

programming paradigm - a fundamental structure and approach of a programming language

Types:
Procedural languages - (e.g. C++) written as an ordered set of instructions in a sequence that the computer follows strictly i.e. actions/calculations/selection/iteration/procedure calls in order

Non-procedural languages - (e.g. PROLOG) allows programmers to specify the results they want without having to solve the problem. The program is written as a list of facts and rules. Used for making AI like expert systems.

Event-Driven programming - (e.g. sensors monitoring heat) more often part of a visual programming language, rather than one main subroutine that runs and calls other subroutines, subroutines are written to react to events that occur e.g. button press

Visual Programming - (e.g. visual basic) allows rapid, easy development of professional-looking applications which reduces the need for typical programming

Mark-up languages - (e.g. HTML) not really a programming paradigm, but are a key part of web programming. They add commands to a text document to add further meaning to the text or to structure it (e.g. titles)

Object-oriented programming - ability to combine data and the procedures that use the data into one object, makes the program easier to maintain and understand as the object complexity can be hidden from the program.

NOT MUTUALLY EXCLUSIVE - CAN BE MULTIPLE (e.g.visual basic event driven, visual and object oriented)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Define inheritance

A

easy to re-use objects in other programs and if necessary create new objects that inherit from other objects without having to recode.

Inheritance enables new objects to take on the properties of existing objects

It is when a new class is created that is based on another class

It can take on the methods and attributes of the parent class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what are the features of a low level language

A

e.g. assembly language which is usually specific to the type of processor on which the program needs to run

programmers have to write the software in a ‘computer-centric’ way, interacting directly with registers, memory locations, etc.

one low level instruction translates into one machine code instruction, therefore will run faster. They are also programs smaller in size.

Slower and more difficult to program

Uses more cryptic and harder to understand references to memory locations and sections of code (i.e. contains no self-documenting identifiers)

time to convert to machine code (using an assembler) is negligible so can run immediately

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what are the features of a high level language

A

e.g. Java, Python, VB which is available on many different computer architectures.

a compiler translates the source code into machine code

Programmer works in a more ‘human-centric’ way, not requiring direct access to the internal registers of the processor. Closer to spoken english semantics

One line of code translates into many lines of machine code, compiler will generally not translate into as few machine code instructions as a hand-crafted low level program

Easier to program and programs that translate into hundreds of machine code instructions can be rapidly created.

has self-documenting identifiers

requires compilation before code can be run for the first time

easier to create modules that can be re-used and accessed by other parts of the program

allow the use of powerful commands that can perform quite complex tasks

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what is standardisation, why is it useful to standardise computer languages and explain the difficulties of doing to

A

Most languages started out standardised e.g. basic -> then different companies added extra functions and commands to produce various different variants -> e.g. Quick Basic, BBC basic, Visual Basic, etc.

Difficult to agree standards as it takes time, languages need to develop and evolve new features as computers become more powerful and new tech appears

Programming in a popular language is a good idea-> compilers available for many different systems -> companies fan more easily create different versions of their software for different operating systems

Makes it easier for companies to employ programmers that are already skilled in a particular language (programmers are in demand)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

define class

A

is used in object-oriented programming

A template defining methods and attributes used to make objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

define object

A

The definition of an object is known as a class

is used in object-oriented programming

Are created for things that the program needs to manage e.g. student as an object

Contains:
-data fields (attributes) about the object, such as StockID, Description, etc.

-subroutines/procedures that can be performed on the object e.g. Addstock, DisplayQuantitySold, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

define attributes

A

is used in object-oriented programming

Data fields about the object e.g. stockID, Description, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

define methods

A

Subroutines/procedures that can be performed on the object

E.g. addstock, displayquantitysold

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what are the advantages of the object-oriented paradigm

A

Classes can be reused in future programs and objects can be created that inherit attributes and methods from another object but also gains its own methods such as Add_Exam_Scores

E.g.

Class student inherits from person Method Input_Exam_Results (exam, grade)
End method
..more methods
End class

Private attributes cannot be inherited still however protected can be

Ability to combine data and procedures that use the data together in one object is more intuitive

Encapsulation makes the program easier to maintain and understand (complexity is hidden from program/people that use it)

Abstraction is similar to encapsulation but it means that we allow access only where necessary to the encapsulated data via public or protected methods/attributes

Inheritance: easy to reuse objects in other programs and if necessary create new objects that inherit from other objects without having to recode

E.g. gears in a car are encapsulated (hidden), Abstraction is provided via a gearstick to allow the driver to change gears

In visual languages, new custom controls can be created, inheriting all the methods and attributes of a normal listbox

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

what does an object consist of?

A

-Data fields
-Subroutines/Procedure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are the disadvantages of object oriented programming?

A
18
Q

Define Public, Private, protected attributes and methods and explain the difference between them

A

Public attributes can be accessed anywhere as its public and inherited

Protected attributes can be accessed through inheritance but I’d private in every other case

Private attributes can be accessed through methods in subclass

19
Q

define instantiation

A

Creating a new object

20
Q

define abstraction

A
21
Q

define encapsulation

A

All attributes and methods related to one thing kept together in a single object

(Effectively another form of modularisation and black-box programming)

22
Q

Look at UML class diagrams

A
23
Q

explain the nature of procedural and non-procedural programming paradigms and their application

A
24
Q

explain the advantages of using a procedural language to write a program based on an algorithm

A
25
Q

explain the features of the mark-up language programming paradigm

A
26
Q

explain the features of event-driven language

A
27
Q

explain the features of visual programming languages

A
28
Q

How do you create an object variable of value b based on the class person

What can it then be used to do

A

Define p as new person

Can now use the public methods of the object

E.g. p.InputDetails(“Smith”,”Janet”,”12/5/1990”)

And public attributes

E.g. p.surname

But cannot access any private or protected attributes

29
Q

What is different about protected and private attributes compared to public

A

Protected and private attributes and methods are accessible only within the class.

However, protected attributes and methods can be used by derived classes that inherit from the class

30
Q

Explain instantiation

A

A class (which acts like a template)

Instantiate, so declares a variable object based on the class template

So e.g. a variable p1 has all the public properties within the class (variables, methods)

Can do stuff like p1.surname = “smith” and the property surname for that object is changed to smith

Another one is p1.AddToFile(“students.txt”) is a public method which will he called and students.txt will be sent to it

31
Q

What is a superclass

A

It is a term given to the parent class

32
Q

What is a subclass

A

The derived class

33
Q

What is UML

A

Unified modelling language

Often used in class diagrams to describe classes and inheritence:
Example:
________________________
| Vehicle |
|——————————‐|
|-Manufacturer :String |
|#Price :Real |
|+colour : string |
|——————————‐|
| +GetManufacturer() |
|+GetPrice |
|——————————‐|
Top box:name of class
Middle box:list of attributes
Bottom box: list of methods

  • denotes a private attribute or method
    + denotes a public attribute or method
    # denotes a protected attribute or method
34
Q

What is a reason that methods in subclasses are required

A

There could be a private attribute that couldn’t be inherited from the superclass so a method is developed to allow the private attribute to be given a value

35
Q

What is a reason that methods in subclasses are required

A

There could be a private attribute in attribute so cannot be set directly

35
Q

What is a reason that methods in subclasses are required

A

There could be a private attribute in the subclass so cannot be set directly

Requires a publicly available method

36
Q

What does inheritance enable

A

Classes that are similar to existing classes can be created by indicating differences (rather than starting again) and thereby allowing code to be organised and reused effectively

37
Q

What does inheritance define

A

It defines relationships between classes and organises classes into groups

38
Q

What is polymorphism

A

Allows a derived class to provide its own version of a method from the superclass

I.e. subclasses can override the inherited superclass method with their own

39
Q

What are the differences between natural language and computer languages

A

Natural languages are ambiguous I.e. there can be more than 2 meanings to a sentence

Computer languages are designed to be unambiguous I.e. 1 meaning and the computer needs to know precisely what is being asked to do when running

The rules of how a particular language is structured is known as the syntax of the language

Because a computer language is unambiguous the syntax rules of the language can be defined using a meta language

40
Q

What is the purpose of BNF

A

To describe unambiguously the syntax of the computer language