PIC10A midterms

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/198

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 4:29 AM on 5/14/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

199 Terms

1
New cards

code

Precise, logical instructions given to a computer to solve a task

2
New cards

Entry Point

The int main() function where every C++ program starts execution

3
New cards

Header Files

Libraries that provide "toolboxes" of features.

4
New cards

#include <iostream>

Required for input and output

5
New cards

#include <string>

Required for advanced string manipulation

6
New cards

Namespace (std)

A label that prevents name conflicts. Using using namespace std; allows you to write cout instead of the full std::cout

7
New cards

Semicolon (;)

Used to end an instruction, similar to a period in a sentence

8
New cards

Curly Braces ({})

Define Scope, grouping multiple statements into a single unit

9
New cards

Comments

Notes ignored by the compiler. Use // for single lines or /* ... */ for blocks

10
New cards

Variable

A named storage location in memory.

  • Declaration: Specifying a type and name (e.g., int coins;).

  • Assignment: Using the = operator to store a value (e.g., coins = 5;).

  • Initialization: The first time a value is assigned; it is "strongly suggested" to do this at the time of definition

11
New cards

Numeric Literals

Fixed values written directly in code, like 42 or 3.14

12
New cards

int (integers)

A datatype that stores whole numbers (integers); typically 4 bytes (PRECISION)

13
New cards

float

A datatype that uses decimal numbers with ~7 digits of precision (PRECISION)

14
New cards

double

A datatype that uses more precise decimal numbers with ~15–16 digits of precision

15
New cards

Scientific Notation

Use E for powers of 10. Example: 2.1E14 means 2.1×1014

16
New cards

Naming Rules

Names are case-sensitive, cannot start with a number, and cannot use symbols like $ or spaces

17
New cards

Basic Operators

  • +, -, * (multiplication), / (division), and % (modulus).

18
New cards

Integer Division

Dividing two int values discards the remainder. Example: 9 / 4 results in 2

19
New cards

Modulus (%)

Yields the remainder of a division. Example: 14 % 4 is 2

20
New cards

Increment/Decrement

  • Post-increment (x++): Use the current value, then add 1.

  • Pre-increment (++x): Add 1 first, then use the new value.

21
New cards

Compound Assignment

  • Shorthand like first_int += second_int (same as first_int = first_int + second_int).

22
New cards

Constants (const)

Values that cannot be changed once defined. Using these avoids Magic Numbers (unexplained literals in code).

23
New cards

Roundoff Error

Small errors caused because most real numbers cannot be stored exactly in binary.

24
New cards

Boolean (bool)

Stores true (internally 1) or false (internally 0).

25
New cards

Character (char)

Stores a single character in single quotes. Example: 'A'.

26
New cards

ASCII Code

The numeric representation of characters. Example: 'A' is 65.

27
New cards

Escape Sequences

  • Start with a backslash to represent special characters like \n (newline), \t (tab), or \' (single quote).

28
New cards

Casting

Converting between types.

  • Implicit: Automatic conversion (e.g., double x = 10;).

  • Explicit: Using static_cast<type>(value) to avoid compiler warnings and data loss.

29
New cards

String Manipulation

  • concatenation

  • zero-based indexing

30
New cards

Concatenation

Using + to join strings. Warning: You cannot concatenate two string literals like "Alex" + "ander" directly.

31
New cards

Zero-based Indexing

The first character is at index 0. Example: In "John", name is 'o'.

32
New cards

length() / size()

  • Returns the character count.

33
New cards

empty()

Returns true if the string is ""

34
New cards

substr(start, length)

Extracts a portion. Example: "Hello".substr(1, 3) is "ell".

35
New cards

find(str) / rfind(str)

Returns the index of a substring or string::npos if not found.

36
New cards

push_back(char) / pop_back()

Adds or removes a character at the end

37
New cards

size_t

A special unsigned integer type for sizes and indexes that matches the system's architecture.

38
New cards

stod(str)

Converts a numeric string to a double.

39
New cards

cin >>

Reads input until whitespace. Can be "chained" (e.g., cin >> bottles >> cans;).

40
New cards

getline(cin, variable)

Reads an entire line, including spaces, until the Enter key is pressed.

41
New cards

Prompts

Messages printed to the user telling them what to input.

42
New cards

Relational Operators

<, <=, >, >=, == (equality check), and != (not equal).

43
New cards

Lexicographic Ordering

Comparison based on ASCII/dictionary order.

  • Uppercase comes before lowercase ("Z" < "a").

  • Spaces come before printable characters.

  • Numbers come before letters.

  • Shorter strings are "less than" longer strings if they are prefixes.

    • spaces → numbers → uppercase → lowerspace

  • EX: Tom < Richard => false, R is before T in the alphabet

44
New cards

Math Libraries

  • <cmath>: sqrt(x), pow(base, exp), round(x).

  • <algorithm>: max(a, b), min(a, b).

45
New cards

What is the primary skill of a computer programmer, according to the PIC 10A materials?

Problem solving

46
New cards

What is the specific role of the << operator when used with cout?

It is the insertion operator that sends data into the output stream.

47
New cards

What is the standard convention for the return value of main() to signify that a program finished successfully?

0

48
New cards

Which C++ data type is specifically used to store a sequence of characters or text?

string

49
New cards

What is the limitation of using cin to read string input from a user?

It only reads one word and stops at the first space character.

50
New cards

Which C++ operator is known as the 'extraction operator' used to receive data from cin?

»

51
New cards

What is the difference between variable 'declaration' and 'assignment'?

Declaration sets aside memory and names the variable; assignment stores a specific value in that memory.

52
New cards

In C++, the first assignment of a value to a variable is formally called _____.

Initialization

53
New cards

How does the = operator in C++ differ from its meaning in mathematics?

In C++, it is a value-assigning operation rather than a statement of logical relationship.

54
New cards

What is 'syntactic sugar' in the context of programming languages?

A syntax feature that is not strictly necessary but makes the code easier to write or read.

55
New cards

Why is it illegal to name a variable 3dGraph in C++?

Variable names cannot start with a number.

56
New cards

Identify the error in the variable name MixedUp#3.

It contains an illegal symbol (#).

57
New cards

Approximately how many decimal digits of precision does the float type provide?

7

58
New cards

How many bytes of memory are typically used by the double data type?

8 bytes

59
New cards

In C++ scientific notation, what is the meaning of the value 2.1E14?

2.1×10^4

60
New cards

Why is 0.5 preferred over 1/2 when writing decimal fractions in C++?

The expression 1/2 performs integer division and results in 0.

61
New cards

What is the result of the integer division 9 / 4 in C++?

2

62
New cards

If x = 5, what are the values of a and x after the operation int a = x++;?

a=5 and x=6

63
New cards

What is the outcome of a 'pre-increment' operation like ++x?

The value of x is incremented first, then the new value is used in the expression.

64
New cards

What is the result of the expression -27 % 4 in C++?

-3

65
New cards

The shorthand first_int += second_int; is equivalent to which full assignment statement?

first_int = first_int + second_int;

66
New cards

Why do computers experience roundoff errors with decimal numbers like 0.1?

0.1 has an infinite repeating representation in binary (base 2), making exact storage impossible.

67
New cards

Which C++ keyword is used to define a value that cannot be changed during program execution?

const

68
New cards

What is a 'magic number' in programming, and why is it considered bad practice?

An unexplained numeric constant in code; it makes the program harder to maintain and understand.

69
New cards

Internally, how does C++ store the boolean value false?

0

70
New cards

Which character literal syntax is required to store a single character in a char variable?

Single quotation marks (e.g., 'A').

71
New cards

What is the ASCII value associated with the character 'A'?

65

72
New cards

If a char variable letter holds 'A', what is the result of letter = letter + 1;?

‘B’

73
New cards

What is 'implicit casting' in C++?

An automatic type conversion performed by the compiler, such as assigning an int to a double.

74
New cards

Which C++ function is used to perform a safe, explicit type conversion to avoid compiler warnings?

static_cast

75
New cards

Which header file must be included to use functions like sqrt and pow?

<cmath>

76
New cards

In the cmath library, how does the round(x) function behave if x is exactly halfway between two integers?

It rounds away from zero (e.g., -2.5 becomes -3).

77
New cards

What are the inputs and output of the pow(b, p) function?

It takes two double inputs (base and exponent) and returns the base raised to the power of the exponent.

78
New cards

Which header file contains the std::max(a, b) and std::min(a, b) functions?

<algorithmn>

79
New cards

What is the default value of a string variable if it is declared but not initialized?

An empty string ("").

80
New cards

Unlike fixed-size types like int, the string type uses _____ memory allocation.

Dynamic

81
New cards

What is the result of concatenating "Yesom" + "Park" using the + operator?

“YesomPark”

82
New cards

Why is the statement string name = "Alex" + "ander"; illegal in C++?

You cannot directly concatenate two string literals using the + operator.

83
New cards

In C++ strings, what index is used to access the very first character?

0

84
New cards

Which string member function returns the total number of characters in the string?

length() or size()

85
New cards

For a string s = "Hello", what is the result of s.substr(1, 3)?

“ell”

86
New cards

What happens if you omit the second argument in the substr(start) function?

It returns all characters from the start position to the end of the string.

87
New cards

Which C++ function is used to read an entire line of text, including spaces, from the keyboard?

getline(cin, variable_name)

88
New cards

Which string member function adds a single character to the end of a string?

push_back(char)

89
New cards

What does the function find(substring) return if the specified substring is not found in the string?

string::npos

90
New cards

What is the primary characteristic of the size_t integer type?

It is an unsigned type whose size depends on the system's architecture (32-bit or 64-bit).

91
New cards

What is the purpose of the stod() function in C++?

To convert a numeric string into a double value.

92
New cards

What does a comparison between two values using relational operators (like < or ==) return?

A boolean value (true or false).

93
New cards

In lexicographic ordering, which is considered 'less': uppercase 'Z' or lowercase 'a'?

Uppercase 'Z'

94
New cards

How are strings of different lengths compared lexicographically if one is a prefix of the other?

The longer string is considered greater.

95
New cards

Relational Operators

Used to compare both numbers and strings. The results are returned as boolean values (true/1 or false/0

96
New cards

Relational Operators and Boolean Results

  • > (Greater than), >= (Greater than or equal).

  • < (Less than), <= (Less than or equal).

  • == (Equality check): Returns true if values are identical.

  • != (Not equal).

97
New cards

Comparison vs. Assignment

The single equals sign (=) is used for assignment (e.g., x = 5 sets x to 5), while the double equals sign (==) is a logical test (e.g., x == 5 asks "Is x equal to 5?").

98
New cards

Comparison Logic

  • Strings are compared letter by letter, from left to right. Comparison stops at the first differing character.

  • If one string is a prefix of another, the longer string is considered "greater" (e.g., "John Doe" > "John").

  • Warning: To ensure correct comparison, at least one of the values must be a std::string variable; comparing two string literals directly may lead to unexpected results on some compilers.

99
New cards

Flow control

determines the order in which instructions are executed. While code usually runs top-to-bottom, flow control allows the program to skip code, repeat actions, or make decisions.

100
New cards

Flow control typed

  • Conditional Statements: if, else if, else.

  • Loops: while, for, do-while.

  • Function Calls: Jumping to and returning from different parts of the code.