The code is an example of how to define a class and create objects of that class in C++. The class is named Car and has three public member variables brand, model, and year of type string and int respectively.
In the main() function, two objects carobj1 and carobj2 are created using the Car class. The member variables of these objects are initialized using the dot notation (.) to access the member variables of the object. Then, the member variables of both objects are printed using cout.
#include<iostream> using namespace std; class Car { public: string brand; string model; int year; }; int main() { Car carobj1; carobj1.brand="BMW"; carobj1.model="X5"; carobj1.year=1999; Car carobj2; carobj2.brand="Audi"; carobj2.model="A3"; carobj2.year=1969; cout<<carobj1.brand<<" "<<carobj1.model<<" "<<carobj1.year<<"\n"; cout<<carobj2.brand<<" "<<carobj2.model<<" "<<carobj2.year<<"\n"; return 0; }To download raw file Click Here
BMW X5 1999 Audi A3 1969
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions