CSE240: Midterm study review

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

bool

(not in C) boolean values

High-level languages

- Has variables of different types (real, integer, array) - Procedures or functions - Control structures Ex. Autocode, FORTRAN, COBOL, LISP, Scheme, and C. Requires a program (compiler) to translate to assembly language and a program (assembler) to translate it to machine code

(quiz) Features of the imperative or procedural paradigms includes:

- Manipulation of named data(variables) - conditional statements

(quiz) What common primitive data types are not primitive data types in C?

- String - bool - short - long

(quiz) Features of the functional paradigm includes:

- expresses computations in terms of mathematical functions - simpler semantics

(quiz) Features of the object-oriented paradigm includes:

- inheritance - classes and objects

(quiz) The lexical structure of all programming languages are similar and normally include which units:

- keywords - identifiers - literals - operators

(quiz) The semantic structure of the imperative programming languages normally include which validations:

- unicity - parameters type in a function declaration should match these in the function call - type matching

(quiz) The syntactic structure of imperative programming languages normally include which units:

-variable declaration - loop statements - conditional statements

(quiz) What is the output of the below code? #include <stdio.h> int main(){ int a[5] = {3, 1, 5, 20, 25}; int i, j, m; i = *(a + 1) - 1; j = a[1] + 1; m = a[j] + a[i]; printf("%d, %d, %d, i, j, m); }

0, 2, 8

(quiz) Data type

A classification that specifies which type of value a variable has and what type of mathematical, relational, or logical operations can be applied to it

destructor

A function whose name is the same as the class name (with a ~ as prefix) and is used to collect garbage.

constructor

A function whose name is the same as the class, and is used to automatically initialize objects.

The destructor should be explicitly called when:

A heap object is no longer needed. Stacks automatically call destructor after use.

array

A homogenous collection of data elements (all have the same type). Individual elements are accessed by an index.

The destructor is called when:

A local object (from stack) with a block scope goes out of scope. When a program (main function) ends and global or static objects exist (OS will collect them anyway) When the destructor is explicitly called. When the delete keyword is called.

(quiz) Variable

A name given to a storage location

(quiz) Pointer

A name given to a storage location that stores an address

Interpreter

A program that translates in runtime and executes each statement in the high level-language Advantages: No separate compilation phases Good debugging information Disadvantages: Slow execution Can use more memory space

Compiler

A program that translates the entire code from source to assembly code/machine code. Advantages: Faster than interpretation Good for multi-module programs Disadvantages: Separate compilation phase May lose debugging info

Machine language

A sequence of bytes stores in memory. CPU interprets the program in the specified order.

(quiz) What is a data type?

A set of primary values and the operations defined on these values.

(quiz) What is a programming paradigm?

A set of principles, concepts, and methods that is commonly accepted by members of a group or community.

Programming language

A set of symbols structured by a set of rules

struct

A structure is a composite data type declaration that defines a physically grouped list of variables to be placed under one name in a block of memory. Similar to a Java class, but does not allow methods. Example: struct person { char name[30]; int id; }

Intermediate code

Makes the language and compiler machine-independent. Implemented in 1970's to simplify compiler design. Used in Java. Ex. Bytecode for Java, MS IL for Microsoft Advantages: Single compiler for all machines Small virtual machine (interpreter) that fits in a web browser. Disadvantages: Slow execution and memory space Separate compilation phase and may lose debugging info

printf(control sequence, expressions)

Method in C to print a string. Control sequence includes a constant string to be printed, expressions is a list of expressions whose are to be printed out. ex. printf("Hello world"); or printf("Result : %f", sqrt(2));

Three types of symbols in a programming language

Numbers, letters and operators

Functions

Parts (components) of a C program, similar to methods in Java

short

Primitive type modifier, reserved a short range of digits for the value

long

Primitive type modifier, reserves a long range of digits for the value

signed

Primitive type modifier, turns data into negative or positive value

unsigned

Primitive type modifier, turns data into only positive values

Linker

Program that compiler uses to resolve external references (bring code in from libraries)

double

a double-precision floating point value

char

a single character

Procedural languages consists of:

algorithms + data (ex. C)

enum

allows us to define the allowed values for a new type. The elements in an enumeration are integer constants, i.e. they are labels that represent an integer value. Example: typedef enum {false, true} booOoolean; typedef enum {Sun, Mon, Tue, Wed, Thu, Fri, Sat} days; int main() { booOoolean a = false; days x = Mon, y = Fri; printf("%d", today); }

String

an array of characters

Logic languages consists of:

facts + rules (Prolog)

Memory value of char s1[] = {'a', 'l', 'p', 'h', 'a' } in C

s1 [a][l][p][h][a], size 5

Memory value of char s2[] = "alpha" in C

s2 [a][l][p][h][a][\0] size 6 where '\0' is the null terminator (null character) marking the end of a string, it's automatically added to the end of a string.

void

valueless special purpose type

If x is allocated at memory address 2000, and if y=&x, then what is y?

y = 2000

Assembly language

Use of letters and numbers (hexadecimal or decimal). Requires a program (assembler) to translate assembly language into machine code.

Local variables

Variables declared inside a function

Global variable

Variables declared outside a function

const

in C, equivalent of a final in Java. this is slower because it will have to read memory

#define

in C, it substitutes values for constant definitions in compilation time, faster execution.

int

integer

typedef (typename) (newname)

introduces a new name that becomes a synonym for the type given by the (typename) portion of the declaration Example: typedef int booOoolean; typedef char FlagType; int main() { booOoolean x = 0; FlagType y = 'A'; }

Object-oriented languages consists of:

objects + messages (ex, Java, C++)

%f

Control sequence for printing floating points (quiz) printing format for floating point values.

%c

Control sequence in C for printing characters (quiz) printing format for characters.

%d

Control sequence in C for printing integers. (quiz) printing format for integer values.

%s

Control sequence in C for printing strings of characters (quiz) printing format for strings of characters.

Semantic rules

Declaration and unicity (review variable has been declared) types (review types of variables match the input data) Array indexes (indexes must be integers) Conditions (expressions return boolean) Return type (Value returned match method header) Parameters (arguments match the parameters in method header)

public

Encapsulation modifier, allows all outside classes to use

protected

Encapsulation modifier, allows only classes within its own package and by a subclass of its class in another package.

private

Encapsulation modifier, allows only to be accessible to members within its own class.

main() function

Every program in C must contain exactly one main() function

(quiz) Features of the logic paradigm includes:

Expressing computation in terms of logic predicates

(quiz) True or false: Functional programming languages are low-level languages

False

(quiz) True or false: Prolog is a functional programming language

False

(quiz) True or false: The compiler executes the program.

False

(quiz) True or false: compilation of a program is to execute all of the statements of the program completely.

False

(quiz) Constant

Fixed value that the program may not alter during its execution

(quiz) What is printed on screen after running this program? #include <stdio.h> int main(){ int i = 0; char a[] = "H2o2"; while(a[i] != '\0') { *(a+1) = *(a + i) + 2; i++; } char *q; q = a; a[2] = '#'; printf("%s", a); return 0; }

H4#2

Lexical tokens

Identifiers (names), keywords, operators, delimiters(;, {}, etc), literals (5, 14.5, etc.), comments (//, /**, etc).

(quiz) This programming language uses two-step translation with intermediate codes for execution

Java

Logic/Declarative Paradigm

Key idea: A program is a set of facts about objects, rules about objects, and questions about the relations between objects Features: Get ride of programming altogether.

Object-Oriented Paradigm

Key idea: Encapsulation fo data and functionality of the program in objects Features: Inheritance and polymorphism Class vs. instance variables (static) Public, private and protected

Functional Paradigm

Key idea: Focus on higher level of abstraction (free from programming details) Features: Simpler semantics Closer to mathematical functions

Imperative or Procedural Paradigm

Key idea: Fully specified and fully controlled manipulation of named data in a step-wise fashion Features: - Divide the program into reasonable sized pieces named functions or procedures or modules or subroutines... - Local and global variables - Data structures - Conditional and loop statements

Three types of rules in a programming language

Lexical, syntactic, semantic

(quiz) What is the output of the following code? #include <stdio.h> int fun(int n) { if(n == 4) return n; else return 2*fun(n+1); } int main(){ printf("%d ", fun(3)); return 0; }

1.8

(quiz) What does the below program print on the screen? int main(){ int i = 3, *j, k; j = &i; printf("%d\n", i**j*i-*j); return 0; }

24

Libraries

Archive of built-in functions and user defined functions that are written by programmers

Paradigm

Basic assumptions, ways of thinking, and methodology that are commonly accepted by members of a group or community.

parent/super class (Java) or base class (C++)

Class in which other classes may inherit from

child/sub class (Java) or derived class (C++)

Class that inherits from parent class

Syntax

Relating to the arrangement of words in a sentence. Create sentences by combining words.

Semantics

Relating to the meaning of sentences. Sentences written must be meaningful to the program.

Lexical

Relating to the words of vocabulary of a language. Create words by merging symbols. Concatenate symbols until you found a whitespace, an operator, or a delimiter.

static variable

Shared by all the objects from a class, prevents functions outside the class to access the variable. Basically a global variable that's restricted to its own class.

(quiz) What kind of error is in the following line: int a ((2 *45)*(6/2)hello(4+90));

Syntactic Error

Encapsulation

The process of hiding data and providing accessible controls to it. Data and operations that manipulate date are encapsulated in classes. Data can only be accessed through their interface operations.

(quiz) What is a similarity between a struct and enum?

They let you define new data types

Goal of a programming language

To tell the computer what to do

(quiz) True or false: A programming language can belong to multiple paradigms

True

(quiz) True or false: During compilation, all the statements of a program in a high-level language are converted (translated) to a low-level language (such as assembly language).

True

(quiz) True or false: Interpretation of a program is the direct execution of one statement at a time sequentially.

True

(quiz) True or false: the following code is correct and prints "Hello": if(2 + 2 + 2 + 2) if(1) printf("Hello");

True

float

floating point value i.e. a number with a fractional part

Functional languages consists of:

functions * functions (LISP)

(quiz) What is printed by the following code? #include <stdio.h> void foo(int *n) { *n = 30; } void main() { int i = 15; foo(&i); printf("i = %d\n", i); i = 10; foo(&i); printf("i = %d\n", i); }

i=30 i=30

pointer

in C and C++, common in all imperative programming languages, a pointer variable stores an address to a memory in storage

Which language allows classes to inherit from more than one parent class?

in C++, derived classes may inherit from more than one base class, but this is not recommended (consider the diamond problem)

*

in C, C++ and imperative programming languages, & is a referencing function that represents the variable name for a given address.

&

in C, C++ and imperative programming languages, & is a referencing function that returns the address value of the variable it precedes.


Set pelajaran terkait

Chapter 9 Textbook: Cognition and Perception

View Set

Quiz - Ch. 6A: GDP and the Measurement of Progress

View Set

Business Statistics - Chapter 5: Discrete Probability Distributions Quiz

View Set

Pure Monopoly Asarta Module Russell B

View Set

أسئلة الفصل الثالث - أكمل

View Set

Marketing research chapter 6 smart book

View Set