Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 3 out of 16 pages
Class notes

CSCE 120 Final Exam Notes

Document preview thumbnail
Preview 3 out of 16 pages

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

Content preview

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

Document information

Uploaded on
August 4, 2026
Number of pages
16
Written in
2026/2027
Type
Class notes
Professor(s)
Beideman
Contains
All classes
$10.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Sold
1
Followers
0
Items
10
Last sold
3 year ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions