Unit 1 - CH 2 Flashcards Preview

Computer Science > Unit 1 - CH 2 > Flashcards

Flashcards in Unit 1 - CH 2 Deck (45):
1

Define Variable

A location in memory that contains one or more data values

2

Define Identifier

A unique name given to a variable, procedure, or function, etc

3

Define High-level programming language

A language that has English-like keywords and commands to express the basic constructs of sequence, selection, and iteration

4

Define Integer Division

A process that returns only the whole number section of a division.

E.g. 7/2 = 3.5 but integer division would return 3

5

Define Compiler

A program that translates source code into executable object code

6

Define Console Application

A program that runs on a text-based window into which the user types and which displays text output from the computer

7

C# Integer Division

int wholeNumberPart = num1 / num2

8

C# modulo operation

int remainder = num1 % num2

9

C# commenting

Single line
// comment

Multi line
/* comments */

10

C# user input

string input = Console.Readline ()

11

C# display/output

Display and leave cursor on same line
Console.Write ("Heya")

Display and move cursor to newline
Console.WriteLine ("Coolio")

12

C# string formatting layout

Console.WriteLine("{0} plus {1} is {2}", num1, num2, sum);

13

Define Global variable

A variable declared at the beginning of a program and accessible from anywhere in the program.

Not always desirable as its values 0may be accidentally changed

14

Define Local variable

A variable declared in a program block and only accessible within the scope of that routine.

15

Define Constant

A variable whose value does not change throughout the program runtime

16

What is the difference between an integer and a real number?

Integers are whole numbers, real numbers can have a fractional part/decimal point.

17

Why use int instead of real?

They use less memory and store values accurately.

18

Define string

A sequence of zero or more characters

19

Define character

Any letter, number, or symbol in a character set such as ASCII

20

C# string accessing

charThree = aString [4]

Zero-indexed

21

C# dateTime usage

dateTime today;
today = DateTime.Today;

dateTime tomorrow = today.AddDays (1);

dateTime anniversary = System.Convert.ToDateTime ("08/09/2017");

22

Define Record

A data structure that groups a number of variables.
Lightweight classes, basically.

23

What data structure is this?

struct Book
{
public string Title, ISBN;
public decimal Price;
public int PublicationYear;
}

Book theMazeRunner;
theMazeRunner.Title = "The Maze Runner"

Defining and then initializing a record in C#

24

Define Enumerated type

An ordered set of values

25

Define Field

A variable that is part of a record

26

Define Set

A collection of values of the same ordinal type with no associated order.

27

What are the 4 set operators?

1. Union (set3 = set1 + set2): values from both sets minus duplicates

2. Difference (set3 = set1 - set2): all set1 values that are not in set2

3. Intersection (set3 = set1 * set2): only values found in both sets

4. Membership (if a in set1 then): tests whether a value is in a set

28

What are the 4 logical bitwise operators?

NOT
AND
OR
XOR

29

What are the 3 Boolean operators?

AND
NOT
OR

30

What are the relational operators?

==
<
>
!=
<=
>=

31

C# nested IF statement

if (condition){ }

else if (alternate condition){ }

else{ }

32

C# switch case statement

switch (x){
case 4:
z += 1;
break;
case 5:
z -= 1;
Console.Write (x);
break;
}

33

Difference between nested IF statements and switch case statements?

IF statements are executed when a condition is met (e.g. x > 5)

Case statements are executed when a variable x has a specific value (e.g. case 6)

34

C# for loop

for (int count=1; count <5; count++)
{
Console.WriteLine (count)
}

Used when the number of iterations is known and finite

35

C# foreach loop

foreach (name in namesList)
{
Console.WriteLine(name);
}

Good for inspecting every element in an array

36

C# do while loop

do
{
Console.Write ("Your name: ");
name = Console.ReadLine ();
}
while (name != "Ash");

37

What is the difference between passing parameters by reference and passing by value?

Calling by reference:
Passes a reference to the memory location of the variable to another procedure. Anything done to the variable in this procedure will also change it's value elsewhere.

Calling by value:
A copy of the variable is passed to the called procedure and anything done to it has no effect outside the procedure scope.

38

C# one dimensional array

string[ ] arrayName = {"I'm", "an", "array"};
arrayName [0] = "I am";

Console.Write(arrayName [0], arrayName [2]);

OUTPUT:: I am array

39

C# two dimensional array

int [ , ] arrayName = new int [4,4]
arrayName [0,3] = 123

#Accesses first row, fourth column

40

In C#, array elements have to be of the same datatype. Parallel arrays of different datatypes are inefficient; how do you go around this?

Create an array of records (custom datatype struct)

recordDataType [ ] arrayName = new recordDataType[5]
arrayName [0].recordField1 = value

41

What's a CSV file?

Comma Separated Values file.
Text file with one record per line, and record fields separated by commas.

Used as data files for mail-merge programs.

42

What's a Binary file?

A file of records, usually containing multiple datatypes. Datatypes other than strings and chars are stored in internal format and can't be displayed in a meaningful way in a text editor (which only interprets ASCII or Unicode character codes).

43

What's a Text file?

A sequence of printable characters organised line by line, which can be accessed and read in a text editor.

44

C# Writing to a text file

static StreamWriter currentFileWriter;
static void Main(string [ ] args)
{
string fileName = "filename.txt";
currentFileWriter = new StreamWriter(fileName);
currentFileWriter.WriteLine("Hello World");
currentFileWriter.Close ()
}

45

C# readimg a text file

static StreamReader currentFileReader;
static void Main(string [ ] args)
{
string fileName = "filename.txt";
currentFileReader = new StreamReader(fileName);
Console.WriteLine (currentFileReader.ReadLine());
currentFileReader.Close ()
}