Unit 1 - CH 2 Flashcards

Programming (C#) (45 cards)

1
Q

Define Variable

A

A location in memory that contains one or more data values

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

Define Identifier

A

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

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

Define High-level programming language

A

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

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

Define Integer Division

A

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

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

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

Define Compiler

A

A program that translates source code into executable object code

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

Define Console Application

A

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

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

C# Integer Division

A

int wholeNumberPart = num1 / num2

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

C# modulo operation

A

int remainder = num1 % num2

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

C# commenting

A
Single line 
// comment
Multi line
/* comments */
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

C# user input

A

string input = Console.Readline ()

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

C# display/output

A

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

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

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

C# string formatting layout

A

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

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

Define Global variable

A

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

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

Define Local variable

A

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

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

Define Constant

A

A variable whose value does not change throughout the program runtime

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

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

A

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

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

Why use int instead of real?

A

They use less memory and store values accurately.

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

Define string

A

A sequence of zero or more characters

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

Define character

A

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

20
Q

C# string accessing

A

charThree = aString [4]

Zero-indexed

21
Q

C# dateTime usage

A

dateTime today;
today = DateTime.Today;

dateTime tomorrow = today.AddDays (1);

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

22
Q

Define Record

A

A data structure that groups a number of variables.

Lightweight classes, basically.

23
Q

What data structure is this?

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

Book theMazeRunner;
theMazeRunner.Title = “The Maze Runner”

A

Defining and then initializing a record in C#

24
Q

Define Enumerated type

A

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 () } ```