2 + 3. Anatomy of a program Flashcards

1
Q

when we run a program we are running

A

a) an object file
b) a machine language file

-computers understand machine language, and object files are in machine language

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

object file

A

file containing object code

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

use of xcode

A

to type in + edit your program files

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

terminal utility

A

gives UNIX interface, used to enter UNIX commands to iMac

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

terminal commands

A

cd: change directory
ls: show programs in folder
make: compiles program

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

when compiling program

A

don’t type .cpp, just write the file name

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

troubleshooting: ‘program’ is up to date

A

probably forgot to save edited program

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

troubleshooting: no rule to make target ‘program’

A

mistyped filename or file not in current directory

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

troubleshooting: use of undeclared identifier

A

syntax error, didnt declare a variable

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

Use of // or /* */

A

a comment (ignored)

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

include

A

allows program to use built-in facilities for input and output (IO)

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

int main () {}

A

a function that returns an integer (int), function is called main

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

return 0

A

main returns the integer 0

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

{ }

A

used to define functions/processes

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

variables

A

places which store values

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

valid variable names

A

start w/ letter or underscore

rest is letters, digits, or underscore

17
Q

notes on using variables

A
  • case sensitive eg. rate vs Rate vs RATE

- don’t use reserved keywords eg. int, for, while

18
Q

data type

A

what kind of thing you want to store in a variable

19
Q

Data types

A
  • int
  • double
  • bool
  • char
  • string
20
Q

int

A

integers

21
Q

double

A

decimal number

22
Q

bool

A

true/false values

23
Q

char

A

used to hold a letter/digit or other symbol eg. “a” “&” or “ “ (a space)

24
Q

string

A

for sequences of characters eg “hello”

25
Q

note on double: float

A

can be used for smaller less precise numbers

26
Q

note on string

A

include

data type not built in, must include string library at top

27
Q

variable declaration

A

variables + data types must be declared before use

28
Q

giving variables values

A

a) reading eg. cin&raquo_space; x;
b) assignment eg. sum = 0; name = “Mary”;

always give variables an initial value before use

29
Q

=

A

the assignment operator

30
Q

iostream

A

contains definitions for cout and cin

31
Q

cout and cin arrow directions

A

cout «

cin&raquo_space;

32
Q

/

A

divides

eg. 10/3 = 3 (for int)

33
Q

%

A

remainder

eg. 10%3 is 1

34
Q

integer division

A

only if both operands are integers that division is integer division

35
Q

cmath library common commands

A
cos/sin/tan
exp
log
pow
sqrt
fabs
36
Q

assigning int to a decimal value

A

by assigning a decimal value to an int variable, you effectively drop the decimals

eg. 
int i;
double x = 3.1415;
i = x;
i will equal 3