#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
int length = 0;
cout << "Enter a string: " << endl;
getline(cin, str);
// this will take only one word cin>>str;
for (int i = 0; str[i] != '\0'; i++) {
length++;
}
// or we can write length = str.length();
cout << "Length of string: " << length << endl;
return 0;
}
Introduction to Object-Oriented Programming (OOP) in C++ Object-Oriented Programming (OOP) is a programming paradigm that uses objects and classes to organize software design. It allows for modelling real-world entities and relationships in a program. C++ is an object-oriented programming language that provides features to implement OOP concepts effectively. Key Concepts of OOP Class and Object o Class : A blueprint for creating objects. It defines properties and behaviours of objects. class Car { public: string brand; string model; int year; }; o Object : An instance of a class. Car car1; car1.brand = "Mahindra"; car1.model = "THAR"; car1.year = 2024; Encapsulation o Encapsulation is the bundling of data and methods that operate on that data within a single unit, or class. It restricts direct acces...
Comments
Post a Comment