Programming Paradigms (Cambridge (CIE) A Level Computer Science): Flashcards

Exam code: 9618

1/70

0Still learning

Know0

  • Define programming paradigm.

Cards in this collection (70)

  • Define programming paradigm.

    A programming paradigm is a style or approach to programming that influences how programs are written, how problems are broken down and how solutions are structured.

  • Name the four programming paradigms.

    The four programming paradigms are low-level, imperative (procedural), object-oriented and declarative.

  • A                  paradigm is closest to machine code and uses mnemonics to control hardware directly.

    A low-level paradigm is closest to machine code and uses mnemonics to control hardware directly.

  • Which paradigm tells the computer how to perform a task using a sequence of commands?

    The imperative (procedural) paradigm tells the computer how to perform a task using a sequence of commands.

  • Which paradigm describes what should be done rather than how to do it?

    The declarative paradigm describes what should be done rather than how to do it.

  • Which paradigm models real-world entities using objects that combine data and behaviour?

    The object-oriented paradigm models real-world entities using objects that combine data and behaviour.

  • Give two examples of low-level languages.

    Two examples of low-level languages are x86 Assembly and ARM Assembly.

  • Give two examples of declarative languages.

    Two examples of declarative languages are SQL and Prolog.

  • Give two examples of object-oriented languages.

    Two examples of object-oriented languages are Java and C++.

  • True or False?

    Declarative programming relies on explicit control flow.

    False.

    Declarative programming has no explicit control flow, because it focuses on outcomes and results rather than on the steps taken.

  • State two key characteristics of the low-level paradigm.

    Two key characteristics of the low-level paradigm are direct memory access and register manipulation.

  • State one strength of the procedural paradigm.

    One strength of the procedural paradigm is its clear flow of control from top to bottom.

  • State one weakness of the procedural paradigm.

    One weakness of the procedural paradigm is that it becomes hard to manage in large programs.

  • State two strengths of the object-oriented paradigm.

    Two strengths of the object-oriented paradigm are enhanced modularity through encapsulation and code reuse through inheritance.

  • State one weakness of the object-oriented paradigm.

    One weakness of the object-oriented paradigm is that it can be slower due to object overhead.

  • State one strength of the low-level paradigm.

    One strength of the low-level paradigm is that it gives complete control over the hardware.

  • State one weakness of the low-level paradigm.

    One weakness of the low-level paradigm is that it is hardware-specific and therefore not portable.

  • State one strength of the declarative paradigm.

    One strength of the declarative paradigm is that it is concise and expressive, focusing on the result rather than the process.

  • State one weakness of the declarative paradigm.

    One weakness of the declarative paradigm is that debugging is challenging because of the level of abstraction.

  • Object-oriented programming uses                  to provide flexible interfaces.

    Object-oriented programming uses polymorphism to provide flexible interfaces.

  • True or False?

    The object-oriented paradigm is the best choice for every type of problem.

    False.

    Object-oriented programming is not ideal for every problem, and misusing it leads to bloated hierarchies and unnecessary complexity.

  • Name the two low-level languages.

    The two low-level languages are machine code and assembly language.

  • Define immediate addressing.

    Immediate addressing loads a constant value directly into the accumulator.

  • Define direct addressing.

    Direct addressing loads the value stored at the specified memory address.

  • Define indirect addressing.

    In indirect addressing the address given points to another address, and it is that second address which holds the data.

  • Define indexed addressing.

    Indexed addressing loads from the base address plus the contents of the index register.

  • Define relative addressing.

    Relative addressing jumps to a new instruction relative to the current instruction, rather than to an absolute address.

  • Memory location 150 holds the value 300, and memory location 300 holds the value 42. Using indirect addressing on location 150, what value is loaded into the accumulator?

    Using indirect addressing on location 150, the value 42 is loaded into the accumulator, because location 150 points to location 300, which holds the data.

  • An indexed instruction uses base address 500 and the index register holds 2. Which memory address is accessed?

    Address 502 is accessed, because indexed addressing adds the contents of the index register to the base address.

  • Immediate addressing is used when you want to work with                  values rather than data held in memory.

    Immediate addressing is used when you want to work with literal values rather than data held in memory.

  • Indexed addressing is used for working with                  or tables, where the index changes.

    Indexed addressing is used for working with arrays or tables, where the index changes.

  • When is direct addressing used?

    Direct addressing is used when the data is stored at known memory addresses.

  • When is indirect addressing used?

    Indirect addressing is used when data is stored in dynamically referenced locations.

  • What is relative addressing used for in a program?

    Relative addressing is used for loops and conditional branches, so that control flow works without absolute addresses.

  • True or False?

    Direct addressing loads the memory address itself into the accumulator.

    False.

    Direct addressing loads the value stored at that memory address, not the address itself.

  • True or False?

    Changing the contents of the index register changes which memory address an indexed instruction accesses.

    True.

    The address accessed is the base address plus the index register, so altering the index register moves the access to a different address.

  • Which addressing mode requires two memory accesses to reach the data?

    Indirect addressing requires two accesses, because the first address holds a second address, and the data is at that second address.

  • Define imperative programming.

    Imperative programming tells the computer how to perform a task, using a top-down, sequential flow of commands.

  • Name three high-level languages that support the imperative style.

    Python, Java and Visual Basic all support the imperative style.

  • How can imperative code be made more organised and readable?

    Imperative code can be made more organised and readable by applying structured programming principles.

  • In a purely imperative program with no procedures, every variable is declared                 .

    In a purely imperative program with no procedures, every variable is declared globally.

  • State one drawback of writing a whole program as a single imperative block.

    One drawback is that there is no reusability, so repeating a task means rerunning the entire program.

  • Why does an unstructured imperative program become harder to maintain as it grows?

    Changes are likely to lead to code duplication, and any edit affects the entire block rather than one part of it.

  • True or False?

    In structured programming, each procedure can have its own local variables.

    True.

    Each procedure declares its own local variables, so data is kept inside the block that uses it.

  • True or False?

    Structured programming uses only global variables.

    False.

    Structured programming uses a mix of global and local variables, whereas the purely imperative version uses only global ones.

  • Compare reusability in imperative and structured programming.

    Imperative code offers no reuse, while structured code makes it easy to reuse procedures.

  • Compare modularity in imperative and structured programming.

    Imperative code keeps all logic in one block, while structured code is divided into named units.

  • Which of the two approaches is the industry standard for real-world applications?

    Structured (procedural) programming is the industry standard approach, because a single imperative block is not ideal for real-world applications.

  • In the structured temperature converter, only one global variable,                 , is used for communication between the procedures.

    In the structured temperature converter, only one global variable, choice, is used for communication between the procedures.

  • How is a temperature in Celsius converted to Fahrenheit?

    Multiply the Celsius value by 9 / 5 and then add 32.

  • How is a temperature in Fahrenheit converted to Celsius?

    Subtract 32 from the Fahrenheit value and then multiply by 5 / 9.

  • How is a temperature in Celsius converted to Kelvin?

    Add 273.15 to the Celsius value.

  • State two benefits of dividing a program into procedures.

    The program becomes easier to read and maintain, and new features can be added and extended more easily.

  • In the structured version of the temperature converter, what is the role of the main procedure?

    The main procedure displays the menu, reads the user's choice and calls the matching conversion procedure.

  • Define declarative programming.

    Declarative programming is a paradigm in which you describe what you want the program to accomplish, not how to do it.

  • Which declarative language is used to extract and manipulate data held in a database?

    SQL is used to extract and manipulate data using queries, without specifying the control flow.

  • Name a logic-based declarative language.

    Prolog is a logic-based declarative language.

  • What two things is declarative code made up of?

    Declarative code is made up of facts and rules.

  • Define fact.

    A fact is a statement that is known or assumed to be true, such as type(beagle, hound).

  • Define rule.

    A rule is a logical relationship built from facts.

  • Define query.

    A query is a question put to the knowledge base, such as size(X, medium).

  • What is the general format of a fact?

    A fact uses the format predicate(object, property).

  • True or False?

    Facts and rules must be written in a set order for the program to work.

    False.

    Facts and rules can appear in any order, unlike imperative programming where order and control flow are essential.

  • The interpreter answers a query by                  patterns in the query against the known facts.

    The interpreter answers a query by matching patterns in the query against the known facts.

  • What does the clause size(labrador, large). mean?

    It means that a Labrador is a large-sized dog.

  • What does the clause shedding(bulldog, low). state?

    It states that a bulldog has low shedding.

  • Given the dog facts, what does the query ?- type(X, retriever). return?

    It returns X = labrador and X = golden_retriever, because both are recorded as retrievers.

  • Given the dog facts, what does the query ?- shedding(X, low), size(X, medium). return?

    It returns X = poodle and X = bulldog, because those are the only dogs that are both low shedding and medium sized.

  • True or False?

    Given the dog facts, the query ?- size(poodle, medium). returns true.

    True.

    The fact size(poodle, medium). is in the knowledge base, so the query matches and returns true.

  • Unlike imperative programming, declarative code has no explicit                  flow.

    Unlike imperative programming, declarative code has no explicit control flow.

Sign up to unlock flashcards

or