CSCI 1 - Midterm 1

studied byStudied by 29 people
5.0(1)
learn
LearnA personalized and smart learning plan
exam
Practice TestTake a test on your terms and definitions
spaced repetition
Spaced RepetitionScientifically backed study method
heart puzzle
Matching GameHow quick can you match all your cards?
flashcards
FlashcardsStudy terms and definitions

1 / 29

flashcard set

Earn XP

Description and Tags

Middler

30 Terms

1

VARIABLE DECLARATIONS

A variable is a named storage location in memory. The line of code where a variable is defined is the variable declaration.

int item;

New cards
2

CONSTANT DECLARATIONS

A variable whose value cannot be altered anywhere in the program.

const double pi = 3.14;

New cards
3

DATA TYPES

INT

‘CHAR’

“STRING”

FLOAT: Float(4bytes), Double (8bytes), Long Double

BOOL: True (1) or False (0)

New cards
4

VARIABLE INITIALIZATION AND ASSIGNMENT

An assignment statement uses the = operator to store a value in a variable

int length = 12;

New cards
5

COMPOUND ASSIGNMENT

num += 3;

New cards
6

ORDER OF OPERATIONS (+)

  1. ()

  2. - (unary negation)

  3. *, /, %

  4. +, -

New cards
7

USING MATHEMATICAL OPERATORS

Mathematical expressions can be created using multiple mathematical operators.

Parentheses can be used to override the order of operations.

New cards
8

USING RELATIONAL OPERATORS

Relational Expressions are made with Relational Operators to make a true/false determination (boolean expressions)

<, >, >=, <=, ==, !=

New cards
9

USING LOGICAL OPERATORS

  1. NOT !: reverses the value of a bool expression

  2. AND &&: true if both bool expressions are true

  3. OR ||: true if either expression is true

*ordered in highest precedence

New cards
10

TRACING IF ELSE STATEMENTS

😀

New cards
11

NESTED IF STATEMENTS

if (expression) {

if (expression) {

statement;

}

}

New cards
12

SWITCH STATEMENTS

Used to select among statements from several alternatives.

switch (exp [integer]) {

case exp1: statement1;

case exp2: statement2;

default: (optional);

}

*include break

New cards
13

TYPE CONVERSIONS (IMPLICIT)

(Type coercion) Automatic conversion of an operand to another data type. Promotion (convert to a higher data type) or Demotion. Lower is promoted to higher.

float val1 = 3.6;

int val2 = 2;

float result = val1*val2;

*val2 remains int

New cards
14

TYPE CONVERSIONS (EXPLICIT)

Manual type conversion. Useful for floating point division with ints.

static_cast<type>(expression)

New cards
15

CURLY BRACKET INCLUSION/EXCLUSION

Use curly brackets when executing more than one statement.

if (score > 90)

grade = ‘A’;

if (score > 90) {

grade = ‘A’;
cout << “Good job!”;

}

New cards
16

FORMATTING OUTPUT

  1. setw(x): prints in a field at least x spaces wide

  2. fixed: displays floating point numbers in fixed point notation

  3. showpoint: causes a decimal point and trailing zeros to be displayed, even if there is no fractional part

  4. setprecision(x): when used with fixed, print floating point value using x-digits after the decimal

  5. << left: output left justified

  6. << right: output right justified

  7. \ escape character

cout << right << setw(6) << setprecision(2) << fixed << num;

New cards
17

WHILE LOOP

A loop allows us to write code that repeats code until a condition is met. Can be infinite if nothing makes the expression false.

while (expression) {

statement;

}

New cards
18

DO WHILE LOOP

A posttest loop, executes the loop first then tests the expression.

do {

statement;

} while (expression);

New cards
19

FOR LOOP

A more compact way of writing a while loop. Good when you know in advance how many times to repeat.

for (initialization; test; update) {

statement;

}

for (count = 10; count < 20; count++ {

cout << count;

}

New cards
20

HIERARCHY OF TYPES (+)

  1. Long Double

  2. Double

  3. Float

  4. Unsigned long

  5. Long

  6. Unsigned int

  7. Int

  8. Unsigned Char

  9. Char

*unsigned means no negative value

New cards
21

TERNARY CONDITIONAL OPERATOR

Most frequently used to perform an assignment

expr (tested) ? expr (done if true) : expre (done if false);

New cards
22
<p><strong>WHAT IS OUTPUT WHEN ‘F’ IS ENTERED?</strong></p>

WHAT IS OUTPUT WHEN ‘F’ IS ENTERED?

Report to the student union.

Report to the student attendance office.

Report to the science building.

New cards
23
<p><strong>WHAT IS OUTPUT WHEN ‘M’ IS ENTERED?</strong></p>

WHAT IS OUTPUT WHEN ‘M’ IS ENTERED?

Go home

New cards
24
<p><strong>WHAT IS OUTPUT WHEN ‘D’ IS ENTERED?</strong></p>

WHAT IS OUTPUT WHEN ‘D’ IS ENTERED?

Report to the small gym.

New cards
25
<p><strong>WHAT IS OUTPUT WHEN ‘I’ IS ENTERED?</strong></p>

WHAT IS OUTPUT WHEN ‘I’ IS ENTERED?

Report to the student attendance office.

Go home

New cards
26
<p><strong>GIVEN THE FOLLOWING CODE, HOW MANY TIMES IF “GOT ONE!” PRINTED?</strong></p>

GIVEN THE FOLLOWING CODE, HOW MANY TIMES IF “GOT ONE!” PRINTED?

2

New cards
27
<p><strong>GIVEN THE FOLLOWING CODE, FOR WHAT VALUES OF i WILL “GOT ONE!” BE PRINTED?</strong></p>

GIVEN THE FOLLOWING CODE, FOR WHAT VALUES OF i WILL “GOT ONE!” BE PRINTED?

6 and 9

New cards
28
<p><strong>CONSIDER THE FOLLOWING CODE SEGMENT. WHAT IS OUTPUT WHEN THE VALUE INPUT IS 15?</strong></p>

CONSIDER THE FOLLOWING CODE SEGMENT. WHAT IS OUTPUT WHEN THE VALUE INPUT IS 15?

AD

New cards
29
<p><strong>CONSIDER THE FOLLOWING CODE SEGMENT. UNDER WHAT CONDITIONS WILL ‘C’ BE PRINTED?</strong></p>

CONSIDER THE FOLLOWING CODE SEGMENT. UNDER WHAT CONDITIONS WILL ‘C’ BE PRINTED?

No conditions allow it

New cards
30
<p><strong>CONSIDER THE FOLLOWING CODE SEGMENT. WHAT IS OUTPUT WHEN THE VALUE INPUT IS 1?</strong></p>

CONSIDER THE FOLLOWING CODE SEGMENT. WHAT IS OUTPUT WHEN THE VALUE INPUT IS 1?

F

New cards

Explore top notes

note Note
studied byStudied by 11 people
1117 days ago
5.0(1)
note Note
studied byStudied by 19 people
836 days ago
5.0(1)
note Note
studied byStudied by 469 people
761 days ago
5.0(1)
note Note
studied byStudied by 6 people
799 days ago
5.0(1)
note Note
studied byStudied by 27 people
720 days ago
4.0(2)
note Note
studied byStudied by 36 people
834 days ago
4.5(2)
note Note
studied byStudied by 8 people
540 days ago
5.0(1)
note Note
studied byStudied by 214 people
672 days ago
5.0(2)

Explore top flashcards

flashcards Flashcard (20)
studied byStudied by 9 people
756 days ago
5.0(1)
flashcards Flashcard (74)
studied byStudied by 52 people
737 days ago
4.8(8)
flashcards Flashcard (108)
studied byStudied by 9 people
25 days ago
5.0(2)
flashcards Flashcard (169)
studied byStudied by 20 people
64 days ago
5.0(3)
flashcards Flashcard (39)
studied byStudied by 45 people
811 days ago
5.0(1)
flashcards Flashcard (20)
studied byStudied by 3 people
679 days ago
5.0(1)
flashcards Flashcard (38)
studied byStudied by 92 people
394 days ago
5.0(1)
flashcards Flashcard (33)
studied byStudied by 6 people
756 days ago
5.0(1)
robot