Escrito por estudiantes que aprobaron Inmediatamente disponible después del pago Leer en línea o como PDF ¿Documento equivocado? Cámbialo gratis 4,6 TrustPilot
logo-home
Document preview thumbnail
Vista previa 3 fuera de 16 páginas
Notas de lectura

CSCE 120 Final Exam Notes

Document preview thumbnail
Vista previa 3 fuera de 16 páginas

CSCE 120 Final Exam Notes - based on lecture slides, includes code snippets, cheat sheet to take to exam

Vista previa del contenido

Condensed (14 pgs)

,EXAM 1
Lecture 2
• Double - same as float, but with double the precision
• Bool - takes on the values true (1) and false (0), C++ will accept numeric values where Boolean is expected (0 is
treated as false and anything else is true)
• Identifiers: letters, numbers, and underscore; must begin with letter/underscore, can’t be reserved word, case
sensitive
• / → if both operands are ints, int division happens so the result is truncated, (ex. 5/3 is 1 even if you’re storing the
result in a double), division by 0 is undefined behavior
• Chain assignments are valid (ex. x = y = z)

Lecture 3 → VECTORS/ARRAYS
• Header Files
• #include “{file name}.h”
• Header guards - prevent errors resulting from including same header file many times
#ifndef ADDITION_H
#define ADDITION_H

int add(int x, int y);
int add(double x, double y);
#endif
• Structs (public) → Used to group several related variables into a single data type, these variables can have the
same type or different types, used for “plain old datatypes” → want to group some related values
• Vectors - all elements have to be same type, need to #include<vector> to use vectors
std::vector<int> squares(10); //default value is 0
for(int i = 0; i < 10; i++) {
squares.at(i) = i * i; }
• std::vector<int> squares = {1, 2, 3, 4, 5, 6, 7, 8, 9};
• std::vector<int> squares(10, 7); //10 elements, initialized to value of 7
• At method - can be used for accessing & modifying elements, if given index is out of bounds then
out_of_range exception thrown
• Vectors can also be indexed w/ [] → w/ this bounds checking doesn’t occur & undefined behavior can
occur
• Functions
• x.size()
• x.push_back(n) → adds value to end of vector
• x.pop_back() → removes last value of vector
• x.insert(x.begin()+i, n) → inserts value n at index i in vector
• x.erase(x.begin()+i) → removes value at index i in vector, first param is iterator not index
• C-Style Arrays
int squares[10];
for(int i = 0; i < 10; i++) {
squares[i] = i*i; }
• Used to group variables of the same type
• Size of array must be specified when we define it & must be a constant (not a variable) → need to

, remember the size of our array in a variable
• Access elements of an array using square brackets [index] → indexing out of bounds in an array is
undefined behavior
• Not a class, so arrays don’t have methods like at or size
• Passing array into function → it decays into a pointer + need to pass the length
• Classes (private) → used for more complicated objects which have their own methods

Lecture 4 → STRINGS
• Strings
• #include<string>
• Without this we can still use string literals (ex. “Hello world”) but we can’t create variables of type
std::string
• String literals are technically represented as C-style arrays of characters → arrays implicitly
convert to strings if we use them where string is expected
• Don’t have methods (ex. “hello”.size())
• Methods
• size() and length() - return length of string
• at(int pos) - returns a reference to the character at position pos
• Can be used to access and modify character
• Throws an out_of_range exception
• str[pos] can also be used, but shouldn’t be because it doesn’t perform bounds checking
• append(const string str) - appends str to the end of the string
• push_back(const char c) - appends the single character c
• find(const string str) - returns the first index where str occurs in the string
• insert(int pos, const string str) - inserts str into the string immediately before index pos
• pos must be at least 0 and at most the size of the string
• Note that unlike the vector version, here pos is just an int
• erase(int pos, int len) - deletes len characters of the string, starting from position pos
• substr(int pos, int len) - return the substring of length len starting at index pos
• Const: create a variable that can’t be modified → if you try to modify, code doesn’t compile
• Must be assigned to a value when declared → if uninitialized, compiler error
• Initializer for const variable doesn’t need to be const
• int x = 5; const int y = x;
• Global variables: declared outside of any function and can be used in any function, making non-const variables
global is possible but not recommended
• Passing copies: Primitive types (int, char, etc.) & vectors behave like structs in copy, assignment, and pass-by-value:
operations work on full copies, not the originals
• Templates: Allow us to give compiler recipe for creating many diff overloads of a function

Lecture 5
• 2D Vectors
• vector<vector<int>> vec2d(3, vector<int>(4)); //3x4 vector, elements
initialized to 0
• vector<vector<int>> vec2d = {{0,1,2}, {3,4,5}, {6,7,8}};
• To access an element use square brackets - but if either index is out of bounds this will give us undefined
behavior instead of throwing an exception

Información del documento

Subido en
4 de agosto de 2026
Número de páginas
16
Escrito en
2026/2027
Tipo
Notas de lectura
Profesor(es)
Beideman
Contiene
Todas las clases
$10.99

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Vendido
1
Seguidores
0
Artículos
10
Última venta
3 año hace



Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes