Integ Programming Flashcards

kupal ka ba?

1
Q

is a set of fixed number of values called elements that can be accessed using integer index

A

array

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

on an array are
of the same data type

A

Elements

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

is used to store multiple values of the same data type at a time
without declaring a different variable name for each value. Array elements can be of any data type

A

array

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

is an array in which all elements are arranged like a list

A

one-dimensional array

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

The following example of one-dimensional array that can store 10 integers and all the array elements are
initialized to zero

A

int[] numbers = new int[10];

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

The following example shows how to assign values to individual array elements by using an index number

A

numbers[0] = 45;
numbers[4] = 23;

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

The example below shows how to initialize an array upon declaration:

A

double[] grades = { 2.50, 2.75, 1.25, 5.0, 1.50 };

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

in C# is used to process the elements of an array starting with index 0 up to the ending index. T

A

foreach statement

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

The following example shows how to use a foreach statement to access the all the
elements of the array grades:

A

foreach (double grade in grades)
{
Console.Write(grade + “ / “);
}
Output:
2.5 / 2.75 / 1.25 / 5 / 1.5 /

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

the array elements are arranged in rows and columns. The elements in this array are arranged in a
tabular form and are therefore stored and accessed by using two (2) indices: one (1) index refers to the row, and the other
refers to the column location.

A

a two-dimensional array,

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

The following example defines a two-dimensional array consisting of two (2)
rows and four (4) columns:

A

int[,] table = new int[2, 4];

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

The example below shows how to assign values to individual array elements by specifying the row and column numbers:

A

table[0, 1] = 18;
table[1, 3] = 4;

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

The following example shows how to initialize a two-dimensional array upon declaration:

A

int[,] table = {
{ 2, 3 },
{ 12, 5},
{ 3, 8 },
{ 18, 3 }
};

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

The following shows how to access the element of a two-dimensional array:

A

Console.WriteLine(table[3, 0]); //this prints the 18

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

in C# is a collection that behaves as a dynamic array where the array size can dynamically increase as
required

A

ArrayList class

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

The ArrayList class is defined in the

A

System.Collections namespace

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

The following example shows how to create an ArrayList:

A

ArrayList nameList = new ArrayList();

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

is used to add an element to the list

A

Add() method

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

The following is the example of adding elements on the ArrayList
named nameList:

A

nameList.Add(“Jack Paul”);
nameList.Add(“Adrian Castro”);
nameList.Add(“Peter Cruz”);
nameList.Add(“Angela Cruz”);

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

The elements of an ArrayList can be accessed by specifying an integer index. For example:

A

Console.WriteLine(nameList[2]); //this will print Peter Cruz

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

is used to process all the elements of an ArrayList

A

The foreach loop

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

Example of foreach loop

A

foreach (string name in nameList)
{
Console.Write(name + “, “);
}
Output:
Jack Paul, Adrian Castro, Peter Cruz, Angela Cruz

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

is a sequential collection of characters that is used to represent text

A

string

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

In C#, a string is an object of class string in the

A

System namespace

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
In C#, a string variable can be initialized by using either of the following:
* directly assigning a string literal; or * using the new keyword and calling the String class constructor.
26
is used to escape characters with special use, such as newline (\n)
the backslash (\)
27
The following statements show an example of how to use new keyword and String class constructor:
char[] word = { 'H', 'e', 'l', 'l', 'o', '!' }; string strGreet = new string(word);
28
This property is used to get the character at a specified index position of a string. For example:
char –
29
This property is used to get the total number of characters in the string. For example
Length –
30
Example for Char:
string word = "Computer"; char letter = word[2]; //the value of variable letter is character 'm'
31
Example for Length
string word = "Computer"; int total = word.Length; //the value of variable total is 8
32
This returns true if the specified substring occurs within the string object; otherwise, it returns false. For example: string sentence = "The quick brown fox jumps."; bool isContain = sentence.Contains("fox"); //returns tru
bool Contains(string value)
33
This determines whether the specified substring has the same value with the string object. The comparisonType parameter specifies the rules to use in comparing strings, such as ignoring the case version of the characters. Example 1: string word = "Computer"; bool isSame = word.Equals("computer", StringComparison.CurrentCulture); //this returns false Example 2: string word = "Computer"
bool Equals(string value, StringComparison comparisonType)
34
This returns the index position value of the first occurrence of the specified character within the string object if that character is found; otherwise, it returns -1 if not found. For example: string word = "Computer"; int index = word.IndexOf('p'); //returns integer 3
int IndexOf(char value)
35
This returns a copy of the string object except that all of the occurrences of an old character are replaced with a new character. For example: string word = "Color"; string strChanged = word.Replace('o', '#'); //returns a copy of string "C#l#r
string Replace(char oldValue, char newValue)
36
This returns a converted copy of object as a string. For example: double value = 105.25; string strValue = value.ToString(); //converted 105.25 into string
string ToString()
37
This returns a copy of the string object converted to lowercase. For example: string word = "COMPUTER"; string strConverted = word.ToLower(); //returns a copy of string "computer"
string ToLower()
38
This returns a copy of the string object converted to uppercase. For example: string word = "computer"; string strConverted = word.ToUpper(); //returns a copy of string "COMPUTER"
string ToUpper()
39
C# provides the ___________ class that represents a mutable string of characters.
StringBuilder
40
represents a mutable string of characters that allows the user to expand the number of characters in the string object without allocating additional memory space.
StringBuilder class r
41
The following shows the way of creating a string using the StringBuilder class and using the new keyword and StringBuilder constructor:
StringBuilder strComputer = new StringBuilder("Computer");
42
to concatenate a string to the string object of StringBuilder class.
Append() method
43
The example below will return the string ("Computer is a great invention.".
strComputer.Append(" is a great invention.");
44
The following example shows how to use these properties:
StringBuilder word = new StringBuilder("Computer"); word[0] = '#'; //change the character at index 0 to '#' for (int index = 0; index < word.Length; index++) { Console.Write(word[index] + " + "); //gets the character at the specified index } Output: # + o + m + p + u + t + e + r +
45
This appends a copy of the specified substring to the StringBuilder object. For example: StringBuilder word = new StringBuilder("Computer"); word.Append(" Ethics"); //returns the string "Computer Ethics"
Append(string value)
46
This returns true if the specified substring is equal to the StringBuilder object; otherwise, it returns false. For example: StringBuilder wordA = new StringBuilder("computer"); StringBuilder wordB = new StringBuilder("computer"); wordA.Equals(wordB); //returns true because same content
Equals(string value)
47
This removes all characters from the current StringBuilder object. For example: StringBuilder word = new StringBuilder("Computer"); word.Clear(); word.Append("Ethics"); //returns the string "Ethics" only
Clear()
48
This replaces all occurrence of a specified old character of the StringBuilder object with a new character. For example: StringBuilder word = new StringBuilder("Color"); word.Replace('o', '*'); //returns the string "C*l*r"
Replace(char oldValue, char newValue)
49
This converts the value of the StringBuilder object to a string. For example: StringBuilder word = new StringBuilder("computer"); string strWord = word.ToString();
ToString()
50
refers to a construct that enables a program to execute a block of statements or a loop body repetitively as long as the defined condition evaluates to true.
loop
51
is used when an operation needs to repeat multiple times
Looping
52
This loop repeats a block of statements as long as a given condition evaluates to true. It evaluates the condition first before executing the loop body
while –
53
This is similar with while loop, except that it executes the block of statements before evaluating the given condition regardless if it evaluates to true or false.
do…while –
54
This loop repeats a block of statement for a specified number of times
for –
55
. The following is the general syntax of while loop in C# including an example:
Syntax: while (condition) { //statements in loop body } For example: //this will print a sequence of numbers from 1 to 10 int start = 1; while (start <= 10) { Console.WriteLine(start); start++; }
56
that is used to control the loop condition
loop control variable
57
Otherwise, the loop body continues to execute endlessly. This is called
infinite loop
58
The following is the general syntax of do…while loop in C# including the example:
Syntax: do { //statements in loop body } while (condition); For example: //this will print a sequence of numbers from 1 to 10 int start = 1; do { Console.WriteLine(start); start++; } while (start <= 10);
59
The for loop in C# takes the following general syntax including an example: riteLine(start); }
Syntax: for (initialization; condition; update) { //statements in loop body } For example: //this will print the numbers from 1 to 10 for (int start = 1; start <= 10; start++) { Console.W
60
The following is the flow of control of a for loop:
1. The initialization step is executed first, and it contains the starting value of the loop. This is executed only once. 2. The defined condition is then evaluated. If it evaluates to false, then the loop terminates and the loop body will not be executed. However, if the condition evaluates to true: Step A. The statements in the loop body is executed. Step B. After executing the loop body, the flow of control jumps up to the update step to update the loop control variable or condition. Step C. The condition is reevaluated. If it evaluates to true, then repeat Step A. However, if it evaluates to false, then the loop execution is terminated.
61
are used to change the flow of control of a looping structure.
Jump statements
62
terminates a loop or a switch statement and transfers the flow of program execution to the statements following the enclosing loop or switch statement
e break
63
The following example shows how to implement a break statement in a loop:
Example: for (int num = 1; num <= 10; num++) { if (num == 5) { break; //if this statement is executed the loop will stop } Console.Write(num + " "); } Output: 1 2 3 4
64
statement is used to skip the remaining statements in the loop body and immediately reevaluates the condition if it’s a while or do…while loop, or it jumps to the update step if it’s a for loop.
e continue
65
The following example shows how to implement a continue statement in a loop:
Example: for (int num = 1; num <= 10; num++) { if (num == 5 || num == 6) { continue; //if this statement is executed it will ignore the print statement below and the execution jumps back to the loop } Console.Write(num + " "); } Output: 1 2 3 4 7 8 9 1
66
are used to execute particular statements whether the value of the given condition evaluates to true or false. These are used to alter the flow of program that willselect a block of statements to execute.
Selection statements or selection structures
67
The C# provides three (3) selection structures:
* The if and if…else statements are conditionalstatements that include a logical expression and provide a one- or two-way selections. * The switch statement executes a block of statements based on the variable to be tested for equality against a list of values
68
instructs the program to execute a certain block of statements only if a particular condition evaluates to true; otherwise, the program will execute the bock of statements in the else statement if false
if statement
69
An if-else statement in C# takes the following syntax and example:
Syntax: if (expression) { //statement(s) } else { //statement(s) } For example: int exam_score = 75; if ( exam_score >= 60 ) { Console.WriteLine("The student passed the exam."); } else { Console.WriteLine("The student failed the exam."); }
70
is used to combine multiple conditions into a single selection structure. This is also called multiple selection
else if statement
71
An else if statement is placed after the if statement or another else if statement. For example:
int exam_score = 75; if (exam_score >= 90) { Console.WriteLine("The grade of the student is A."); } else if (exam_score >= 80) { Console.WriteLine("The grade of the student is B."); } else if (exam_score >= 70) { Console.WriteLine("The grade of the student is C."); } else if (exam_score >= 60) { Console.WriteLine("The grade of the student is D."); } else { Console.WriteLine("The grade of the student is F."); }
72
is used to execute a block of statements based on the variable to be tested for equality against predefined list of values.
switch statement
73
The general syntax of a switch statement in C# is as follows:
switch (variable or expression) { case value1: //statement(s) break; case value1: //statement(s) break; . . . case valuen: //statement(s) break; default: //statement(s) break; }
74
is a special type of decision-making operator used to perform an operation that evaluates a logical expression then selects between two (2) single statements depending on whether the defined expression evaluates to true or false and evaluates it
conditional operator, also called as ternary operator (?:),
75
The general syntax of ternary operator i
condition ? consequence : alternative Example 1: int sum = 4 > 2 ? 4 + 2 : 4 – 2; //the return value is 6 and assigned to the variable sum Example 2: int exam_score = 75; string result = exam_score >= 60 ? "Student passed the exam." : "Student failed the exam."; Console.WriteLine(result)
76