-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass_object.cpp
More file actions
34 lines (28 loc) Β· 810 Bytes
/
class_object.cpp
File metadata and controls
34 lines (28 loc) Β· 810 Bytes
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
#include <iostream>
using namespace std;
// Defining the class
class Car {
public:
// Attributes (properties)
string make;
string model;
int year;
// Constructor to initialize the attributes
Car(string carMake, string carModel, int carYear) {
make = carMake;
model = carModel;
year = carYear;
}
// Method to display car information with emojis
void displayInfo() {
cout << "π Car Information: " << year << " " << make << " " << model << " ποΈ" << endl;
}
};
// Main function
int main() {
// Creating an object of the Car class
Car myCar("Toyota", "Corolla", 2020);
// Accessing the object's method with emojis
myCar.displayInfo(); // Output: π Car Information: 2020 Toyota Corolla ποΈ
return 0;
}