

































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A comprehensive overview of fundamental c++ programming concepts, including data types, operators, classes, objects, and memory management. It covers essential topics like operator overloading, data abstraction, and object-oriented programming principles. The document also includes examples and explanations of key concepts, making it a valuable resource for beginners learning c++.
Typology: Exams
1 / 41
This page cannot be seen from the preview
Don't miss anything!


































bool operator==(const Object& other) const; - ANS Equivalency operator overload signature bool operator!=(const Object& other) const; - ANS Not equivalent operator overload signature bool operator<=(const Object& other) const; - ANS Less than or equal to operator overload signature bool operator>=(const Object& other) const; - ANS Greater than or equal to operator overload signature bool operator<(const Object& other) const; - ANS Less than operator overload header bool operator>(const Object& other) const; - ANS Greater than operator overload signature friend ostream& operator<<(ostream& stream, const Object& rhs); - ANS Out stream (output) operator overload header friend istream& operator>>(istream& stream, const Object& rhs); - ANS In stream (input) operator overload header using namespace std; - ANS "As", so it makes it so you don't have to use "std::" when doing istream/ostream operations. template
a = b; b = temp; } - ANS Simple swap; int can be switched out for any data type. int data_; - ANS How to format private data members. #include
return Object(); } - ANS General implementation for a multiply operation overload. Object Object::operator/(const Object& rhs) const { ... return Object(); } - ANS General implementation for a division operation overload. Object Object::operator-(const Object& rhs) const { ... return Object(); } - ANS General implementation for a subtraction operation overload. Object Object::operator+(const Object& rhs) const { ... return Object(); } - ANS General implementation for an addition operation overload. John Von Neumann - ANS Who had innovations in Set theory, Geometry, Quantum Mechanics, Economics, Statistics John Von Neumann - ANS Who founded Game Theory? John Von Neumann - ANS Who made the Monte Carlo Method? John Von Neumann - ANS Who was the Von Neumann Architecture named after?
John Von Neumann - ANS Who was involved in the Manhattan Project? John Von Neumann - ANS Who coined MAD? John Von Neumann - ANS Who authored the Merge Sort Algorithm? Why C++? - ANS Supports OOP fundamentals Why C++? - ANS Type Safety, Operator Overloading Why C++? - ANS Memory (stack/heap), OS, threads, usage of pointers, memory allocation/deallocation, low level functionality. Abstraction - ANS Allows the seperation of the implementation from the expression of the Class. ADT - ANS Abstract Data Type Data Abstraction - ANS A collection of data and a set of well-defined operations. The data can be reused without knowing the internal data representation and structure. Class Design Checklist - ANS • Constructors
const int kCardsInDeck = 52; - ANS Global definition of value which does not change void MyFuntion(int p) const; - ANS Modifier on member function which does not change data in object void MyFunction(const MyParamType& mpt); - ANS const reference to save space on passing in variable Classes - ANS a new data type formed of a collection of data and a set of operations on the data Data Structures - ANS a construct within a programming language that stores a collection of data How do we do encapsulation? - ANS With driver file (main.cpp), definition files (header files), implementation files (.cpp files) Ada Lovelace - ANS What is the most well-known name for Augustus Ada Byron, Augustus Ada Lovelace, and the Countess of Lovelace? Ada Lovelace - ANS Who was the daughter of the famous poet, Lord Byron? Ada Lovelace - ANS Who partnered with Charles Babbage on Analytical Engine? Ada Lovelace - ANS Who devised / imagined first computer program? Whose algorithm to be executed by the analytical machine? Compute Bernoulli numbers? Ada Lovelace - ANS Who was the first computer programmer? Object operator/(const Object& rhs) const; - ANS Division operator overload signature
Object operator-(const Object& rhs) const; - ANS Subtraction operator overload header Object operator+(const Object& rhs) const; - ANS Addition operator overload header Object operator(const Object& rhs) const; - ANS Multiplication operator overload header Object operator+=(const Object& rhs) const; - ANS += operator overload header Object operator-=(const Object& rhs) const; - ANS -= operator overload header Object operator=(const Object& rhs) const; - ANS *= operator overload header Object operator/=(const Object& rhs) const; - ANS /= operator overload header Object Object::operator+(const Object& rhs) const{ return Object(data_ + rhs.data_); } - ANS Example addition operator overload Object& Object::operator+=(const Object& rhs) const{ data_ += rhs; return *this; } - ANS Example += operator overload ostream& Object::operator<<(ostream& stream, const Object& rhs) {
#include
private: T data; } - ANS Templatized Object class. Geoffrey Hinton - ANS Who is currently unemployed? Geoffrey Hinton - ANS Who won the Turing Award: 2018, Deep Learning, Neural networks? Geoffrey Hinton - ANS Who resigned from Google to "freely speak out about the risks of A.I."? Speaking out about misuse of AI, technological unemployment, existential risks. Geoffrey Hinton - ANS Who fears AI-race between Google and Microsoft? Geoffrey Hinton - ANS Who won the NOBEL PRIZE 2024: Physics (w/John Hofield) "for foundational discoveries and inventions that enable machine learning with artificial neural networks"? Nicola Dell - ANS Who is an Associate Professor at Cornell University? Nicola Dell - ANS Who co-founded the Clinic to End Tech Abuse? Nicola Dell - ANS Who is the winner 2024 MacArthur Grant Award Winner? vector.push_back(data); - ANS Adds "data" to the end of the vector template
Manual Management: Memory on the heap must be manually managed using delete or free to avoid memory leaks. - ANS What gets added to the heap? template
p += 2; // Move two elements forward std::cout << "Fourth element: " << *p << std::endl; // Output: 40 p--; // Move one element backward std::cout << "Third element: " << *p << std::endl; // Output: 30 - ANS What code below uses pointer arithmetic to traverse an array? Dennis Ritchie - ANS Who was the inventor of Unix with Ken Thompson? Dennis Ritchie - ANS Who was the inventor of C? Dennis Ritchie - ANS Who won the Turing Award in 1983? Margaret Hamilton - ANS Who developed on-board flight software for the Apollo space program? Margaret Hamilton - ANS Who was a director of the MIT Instruments Lab? Margaret Hamilton - ANS Who was awarded Presidential Medal of Freedom in 2016? Margaret Hamilton - ANS Who was a First Site Reliability Engineer (SRE)? Margaret Hamilton - ANS Who made contributions to async software, priority scheduling and priority display? Barbara Simons - ANS Who had a focus on scheduling and compiler optimizations? Barbara Simons - ANS Who worked in IBM?
Recursive case - ANS part of a recursive function that includes a call to itself with modified arguments, working towards reaching the base case. Binary - ANS Base-2 number system Hex - ANS Base-16 number system Octal - ANS Base-8 number system Dynamic memory - ANS refers to memory that is allocated during runtime using operators like new and delete. Pointers to dynamically allocated memory also can be deleted. Pointers - ANS variables that store the memory address of another variable. When are copy constructors called? - ANS Object initialized from another object of the same class, pass- by-value to a function, object returned by value from a function, calling it manually. Copy constructor call - ANS Object(obj), where obj is of type Object. Copy constructor call - ANS Object obj2 = obj1, where obj1 is of type Object. Copy constructor call - ANS method(obj), where method(Object obj) Copy constructor call - ANS return obj, where Object method() Decimal to Binary Conversion - ANS Divide by 2, record the remainder, update the number to the quotient of the division, repeat until quotient is 0, read remainders in reverse order.
Binary to Hexadecimal Conversion - ANS Group digits in sets of four, add leading zeros if necessary, convert each set to hexadecimal equivalent. Binary to Octal Conversion - ANS Group digits in sets of three, add leading zeros if necessary, convert each set to octal equivalent. Decimal to Octal Conversion - ANS Repeatedly divide the decimal number by 8 and record the remainders. Decimal to Hexadecimal Conversion - ANS Repeatedly divide the decimal number by 16 and record the remainders. int* ptr; - ANS How do you declare an int pointer? int value = 42; int* ptr = &value; - ANS How do you define an int pointer? int* ptr = new int(42); - ANS How do you define a dynamically allocated int pointer? delete obj; - ANS How do you delete a dynamically allocated object? int* array = new int[size]; - ANS How do you declare a dynamically allocated int array? delete[] array; - ANS How do you delete a dynamically allocated int array? ptr = nullptr; - ANS How do you avoid dangling pointer?
Merge Sort : [5, 3, 8, 4, 2] : Step 3 (Split) - ANS [3] and [8] Merge Sort : [5, 3, 8, 4, 2] : Step 4 (Merge) - ANS [3, 8] Merge Sort : [5, 3, 8, 4, 2] : Step 5 (Split) - ANS [3, 5, 8] Merge Sort : [5, 3, 8, 4, 2] : Step 6 (Split) - ANS [4] and [2] Merge Sort : [5, 3, 8, 4, 2] : Step 7 (Split) - ANS [2, 4] [2, 3, 4, 5, 8] - ANS Merge Sort : [5, 3, 8, 4, 2] : Step 8 (Split) [5, 3, 8, 4, 2] - ANS Insertion Sort : [5, 3, 8, 4, 2] : Step 0 (Initial Array) Insertion Sort : [5, 3, 8, 4, 2] : Step 1 - ANS [3, 5, 8, 4, 2] Insertion Sort : [5, 3, 8, 4, 2] : Step 2 - ANS [3, 5, 8, 4, 2] Insertion Sort : [5, 3, 8, 4, 2] : Step 3 - ANS [3, 4, 5, 8, 2] [2, 3, 4, 5, 8] - ANS Insertion Sort : [5, 3, 8, 4, 2] : Step 4 [5, 3, 8, 4, 2] - ANS Bubble Sort : [5, 3, 8, 4, 2] : Step 0 (Initial Array)
Bubble Sort : [5, 3, 8, 4, 2] : Step 1 (Pass 1) - ANS [3, 5, 4, 2, 8] Bubble Sort : [5, 3, 8, 4, 2] : Step 2 (Pass 2) - ANS [3, 4, 2, 5, 8] Bubble Sort : [5, 3, 8, 4, 2] : Step 3 (Pass 3) - ANS [3, 2, 4, 5, 8] [2, 3, 4, 5, 8] - ANS Bubble Sort : [5, 3, 8, 4, 2] : Step 4 (Pass 4) template