Midterm review Flashcards
(62 cards)
1
Q
Using Directive
A
- Using System
- tells the compiler where to look for a class that’s used in this app
- Each using directive identifies a namespace containing predefined classes that a C# app should be able to use
2
Q
White space
A
- space bar, tab, blank lines
- Ignored by the compiler
- make code easier to read
3
Q
Class Name Convention
A
- begin with a capital letter and capitalize the first letter of each word they include
- a series of characters consisting of letters, digits and underscores (_) that does not begin with a digit and does not contain spaces
4
Q
Write
A
- cursor stays on the same line of text in the console window
5
Q
WriteLine
A
- cursor moves to the next line of text in the console window
6
Q
escape sequence
A
- \n, \t, \r, ", \
7
Q
\n
A
- New line. Positions the screen cursor at the beginning of the next line
8
Q
\t
A
- Horizontal tab. Moves the screen cursor to the next tab stop
9
Q
\r
A
- Carriage return. Positions the screen cursor at the beginning of the current line—does not advance the cursor to the next line. Any characters output after the carriage return overwrite the characters previously output on that line.
10
Q
"
A
- Double quote. Used to place a double-quote character (“) in a string—e,g., Console.Write( “"in quotes"” ); displays “in quotes”.
11
Q
\
A
Backslash. Used to place a backslash character in a string.
12
Q
declare a class named “Addition”
A
public class Addition
13
Q
declare the main method
A
public static void Main(string [ ] args)
{
}
14
Q
declare “number1” as an integer data type
A
int number1;
15
Q
initialize number1 as an integer data type equal to 10
A
int number1 = 10;
16
Q
convert “number1” to an Integer data type
A
number1 = Convert.ToInt32( Console.ReadLine ( ) );
17
Q
Integer data types
A
- byte
- short
- int
- long
18
Q
floating point data types
A
- float
- double
- decimal
19
Q
char data type
A
- one character - “A”
20
Q
Bool data type
A
- true / false
- yes / no
21
Q
String data type
A
“my name is Krista”
22
Q
Simple data types
A
- int
- float
- char
- bool
23
Q
complex data type
A
string
24
Q
=
A
- assignment oppertator
- reads right side first
25
Arithmetic Operators
- Addition ( + )
- Subtraction ( - )
- Multiplication ( * )
- Division ( / )
- Remainder ( % ) -> Modulas
26
Relational Operators
>, =, <=
| higher Precedence
27
Equality Operators
== , !=
| lower Precedence
28
get accessors
- reading the values of a variable
29
set accessors
- string values in a variable
30
create a Gradebook object of a Gradebook class in another class
- Gradebook mygb = new Gradebook( );
31
Call Gradebook's DisplayMessage method
myGradebook.DisplayMessage( );
32
new class all together
```
public class GradeBookTest
{
```
```
public static void Main( string[] args )
{
GradeBook myGradeBook = new GradeBook();
```
myGradeBook.DisplayMessage();
}
}
33
local variables
- Variables declared in the body of a method
| - can be used only in that method
34
instance variables
- When each object of a class maintains its own copy of an attribute
- each object (instance) of the class has a separate instance of the variable
35
public property
public class gradebook
36
constructor
- if you dont declare one it will automatically be assigned
- public GradeBook( string cname )
{
CourseName = cname;
}
37
constructor characteristics
- same name as class name
- no return type
- main method
38
auto implemented property
public string CourseName { get; set; }
39
selection
- if (one option)
- if / else (two options)
- switch (more than two options)
40
looping
- while (counter and sentinel controlled)
| - for
41
counter
int counter = 1
While (Counter <= 22)
{
functions
counter = counter + 1
}
42
if selection statement
if ( grade >= 60 )
| Console.WriteLine( "Passed" );
43
if / else double selection statement
if ( grade >= 60 )
Console.WriteLine( "Passed" );
else
Console.WriteLine( "Failed" );
44
Conditional Operator
- an be used in place of an if / else statement
| - Console.WriteLine( grade>=60 ? "Passed":"Failed" );
45
Nested if / else Statements
```
if ( grade >= 90 )
Console.WriteLine( "A" );
else if ( grade >= 80 )
Console.WriteLine( "B" );
else if ( grade >= 70 )
Console.WriteLine( "C" );
else if ( grade >= 60 )
Console.WriteLine( "D" );
else
Console.WriteLine( "F" );
```
46
while loop
int product = 3;
while ( product <= 100 )
product = 3 * product;
47
Arithmetic compound operators
counter = counter + 1
counter += 1
++ counter
counter ++
48
increment operators
- prefix increment ( ++a )
| - postfix increment ( a++ )
49
decrement operators
- prefix decrement ( --a )
| - postfix decrement ( a-- )
50
casting
double avg = (double) total / numofgrades
51
for
for ( int counter = 1; counter <= 10; ++counter )
Console.Write( "{0} ", counter );
for ( initialization; loopContinuationCondition; increment ) statement
52
while
initialization;
while ( loopContinuationCondition ) {
statement
increment; }
53
switch
```
switch ( grade / 10 )
{
case 9:
case 10:
++aCount;
break;
case 8:
++bCount;
break;
...
default:
++fCount;
break;
}
```
54
continue statement
skips the remaining statements in the loop body and proceeds with the next iteration of the loop.
55
Logical Operators
- enable you to form more complex conditions by combining simple conditions
- The logical operators are && (conditional AND), || (conditional OR), & (boolean logical AND), | (boolean logical inclusive OR), ^ (boolean logical exclusive OR) and ! (logical negation)
56
syntax error
- user typed something in wrong
57
logical error
- compiler will not catch it, but the code will not run correctly
58
run time error
- the user typed something in wrong
59
system
- namespace in the .Net library
60
class
a definition of things (blueprint)
61
format specifier
{ 0:F } - round to two decimal places
| { 0:C } - formats as currency
62
static
the code can run even with no object