-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.cpp
More file actions
56 lines (45 loc) · 1.07 KB
/
class.cpp
File metadata and controls
56 lines (45 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "Learn_CPP.h"
// Function to initialize classes and objects topics
std::unordered_map<std::string, Topic> getClassTopics() {
std::unordered_map<std::string, Topic> topics;
topics["Classes and Objects"] = {
"Classes and objects are the foundation of Object-Oriented Programming (OOP). A class is a blueprint for creating objects, which are instances of the class.",
R"(Syntax:
class ClassName {
public:
// Members (variables and functions)
int memberVariable;
void memberFunction() {
// Function body
}
};
Example:
class Car {
public:
string brand;
int year;
void displayInfo() {
cout << "Brand: " << brand << ", Year: " << year << endl;
}
};)",
R"(Example Code:
#include <iostream>
using namespace std;
class Car {
public:
string brand;
int year;
void displayInfo() {
cout << "Brand: " << brand << ", Year: " << year << endl;
}
};
int main() {
Car car1;
car1.brand = "Tesla";
car1.year = 2023;
car1.displayInfo();
return 0;
})"
};
return topics;
}