4. C++ OOP

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

1/22

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 11:09 PM on 5/22/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

23 Terms

1
New cards

How is a method implemented in C++

Usually outside of the class, using the scope resolution operator ::

Car::Car() {}

2
New cards

What is the scope resolution operator ::

Links a method implementation to its class

3
New cards

What goes in the header file (.h)

Contains class definitions

4
New cards

What goes in the source file (.cpp)

Contains method implementations and code

5
New cards

What are the three types of scope that C++ structures can be defined as

private

public

protected — private but accessible to subclasses

6
New cards

how do you define a class in C+ in the header file

class Car{
private:
	int milesDriven;
	int age;

public:
	Car();
	void drive(int miles);
};

7
New cards

how do you initialise an object in C++

Car::Car() {
	milesDriven = 0;
	age = 10;

8
New cards

How do you define a class in the source file in C++

void Car::drive(int miles) {
	milesDrive += miles;
}

9
New cards

What is a stack-allocated object

Declared like normal variables, and automatically destroyed when scope ends.

10
New cards

What is a heap-allocated objecet

Created with new, returned as a pointer, and must be deleted manually.

11
New cards

How does a pointer work in C++

Declared with *, accessed with →

12
New cards

How does references to objects work in C++

Declared with & , must be initialised, immutable and accessed with.

13
New cards

What pass-by method does C++ use

Pass by value (copies of variables)

14
New cards

what is <iostream> in c++

input/output streams (replaces stdio.h)

15
New cards

What is <string> in C++

The string class (wrapper around char arrays)

16
New cards

How do strings work in C++

  • C-style string (char *)

  • high-level (std::string)

17
New cards

what methods does string have

  • length

  • find

  • substr

  • append

    • replace

18
New cards

how does ‘cin’ work in C++

reads input

int age;
std::cin >> age;

19
New cards

how does ‘cout’ work in C++

std::cout << "hello, " << name << "!";

20
New cards

what is a namespace

they group related identifiers (classes, functions, variables) to avoid name collisions. the standard library lives in the std namespace.

21
New cards

How do you access a namespace member

:: notation

22
New cards

how do you define a namespace

namespace MyMath {
	int add(int a, int b){
		return a + b;
	}
}

23
New cards

how do you use a method defined inside a namespace

int x = MyMath::add(3, 5);