NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

//Program to create a simple class and object to understand the concept of classes and objects:

// #include <iostream>
// using namespace std;

// // //Let us create a class named Person;

// // class Person{
// // public:
// // //create a member function with argument name and age;
// // void creds(string name, int age){
// // cout<<"nI am "<<name<<" and " << age<<" years oldn"<<endl;
// // };
// // };

// // int main(){
// // //create an object named p1;
// // Person p1;
// // p1.creds("Suresh", 20);
// // return 0;
// // }


// template <class T1, class T2>
// class Base{
// public:
// void add(T1 a, T2 b){
// cout<< a + b;
// }
// };

// class Derived : public Base <float, float>{

// };

// int main(){
// Derived d;
// d.add(4.5, 5.5);
// return 0;
// }


// #include <iostream>
// using namespace std;

// void swap (int &x, int &y){
// int temp;
// temp = x;
// x = y;
// y = temp;
// }

// int main(){
// int a, b;
// a = 5, b = 6;
// cout<< "before swapping value of a: "<<a<<endl;
// cout<< "before swapping value of b: "<<b<<endl;
// //calling a function to swap the values using variable reference.
// swap (a, b);
// cout<< "After swapping value of a: "<<a<<endl;
// cout<< "After swapping value of b: "<<b<<endl;
// return 0;
// }


// #include <iostream>
// using namespace std;
// class Area{
// public:
// int a, b;
// int areaof(){
// return a*b;
// }
// };


// int main(){
// int a, b;
// cout<<"Enter the integer value of a and b: "<<endl;
// cin>>a>>b;
// Area ar;
// ar.a = a;
// ar.b = b;
// cout<<"The area is : "<<ar.areaof()<<endl;
// return 0;
// }

// #include <iostream>
// using namespace std;

// class Math{
// private:
// double length;
// double height;
// double breadth;

// public:
// double printData(double len, double h, double b){
// length = len;
// height = h;
// breadth = b;
// }

// double calculateArea(){
// return length * breadth;
// }

// double calculateVolume(){
// return length * breadth * height;
// }
// };

// int main(){
// Math math;
// double l, b, h;
// cout<<"Enter the values of length, height and breadth respectively: "<<endl;
// cin>>l>> h>> b;
// math.printData(l, b, h);
// cout<<"The area is : "<<math.calculateArea()<<endl;
// cout<<"The volume is : "<<math.calculateVolume()<<endl;
// }

// Parameterized constructor demonstration.
// #include <iostream>
// using namespace std;

// class Wall{
// private:
// double length;

// public:
// Wall(double len){
// length = len;
// cout<<"Creating a wall!n"<<endl;
// cout<<"length of wall is: "<<length<<endl;
// }

// };

// int main(){
// double l;
// cout<<"Enter the required length of wall: n";
// cin>>l;
// Wall wall(l);
// return 0;
// }

//Default constructor demonstration.

// #include <iostream>
// using namespace std;

// class Wall{
// private:
// double height;
// double length;

// public:
// Wall(){
// height = 6.5;
// length = 5.5;
// cout<<"nCreating a wall of height "<<height<<" and length "<<length<<endl;
// }
// };

// int main(){
// Wall wall;
// return 0;
// }

// #include <iostream>
// using namespace std;

// class Wall {
// private:
// double height;
// double length;

// public:
// Wall(double h, double len){
// height = h;
// length = len;
// }

// double calculateArea(){
// return height * length;
// }
// };

// int main(){
// double h, l;
// cout<<"Enter height and length of wall respectively: "<<endl;
// cin>>h>>l;
// Wall wall1(h, l);
// cout<<"The area of the wall is "<<wall1.calculateArea()<<endl;
// return 0;
// }

// #include <iostream>
// using namespace std;

// class Wall{
// private:
// double height;
// double length;

// public:
// Wall(double h, double len){
// height = h;
// length = len;
// }

// Wall (Wall &obj){
// height = obj.height;
// length = obj.length;
// }

// double calculateArea(){
// return height*length;
// }
// };

// int main(){
// double h, l;
// cout<<"Enter the values of h and l respectively: "<<endl;
// cin>>h>>l;
// Wall wall1(h, l);
// Wall wall2 = wall1;
// cout<<"The area of wall1 is : "<<wall1.calculateArea()<<endl;
// cout<<"The area of wall2 is : "<<wall2.calculateArea()<<endl;
// return 0;
// }


//program to demonstrate the copy constructor;

// #include <iostream>
// using namespace std;

// class Math{
// private:
// double length;
// double breadth;
// double height;

// public:
// Math(double len, double b, double h){
// length = len;
// breadth = b;
// height = h;
// }

// Math (Math &obj){
// length = obj.length;
// breadth = obj.breadth;
// height = obj.height;
// }
// double calcaulateVolume(){
// return length*breadth*height;
// }
// };

// int main(){
// double l, b, h;
// cout<<"Enter the value of length breadth and height respectively: "<<endl;
// cin>>l>>b>>h;
// Math math1(l, b, h);
// Math math2 = math1;
// cout<<"The volume of math1 is : "<<math1.calcaulateVolume()<<endl;
// cout<<"The volume of math2 is : "<<math2.calcaulateVolume()<<endl;
// return 0;
// }


// #include <iostream>
// using namespace std;

// class Test{
// public:
// Test(){
// cout<<"Test constructor called"<<endl;
// }

// ~Test(){
// cout<<"Test destrucotr called"<<endl;
// }
// };

// int main(){
// Test test1, test2, test3;
// return 0;
// }

//program to compile working of destructor;

// #include <iostream>
// using namespace std;

// class Demo{
// private:
// int num1, num2;

// public:
// Demo(int n1, int n2){
// cout<<"Hello from Constructor!"<<endl;
// num1 = n1;
// num2 = n2;
// }

// void display(){
// cout<<"num1 = "<<num1<<endl;
// cout<<"num2 = "<< num2 <<endl;
// }

// ~Demo(){
// cout<<"Hello from Destructor!"<<endl;
// cout<<"Object destroyed Successfully!"<<endl;
// }
// };

// int main(){
// Demo d1(5, 10), d2(6, 8);
// d1.display();
// d2.display();
// return 0;
// }

//Program to pass object as arguments in function.

// #include <iostream>
// using namespace std;

// class Student{
// public:
// double marks;

// Student (double m){
// marks = m;
// }
// };

// void calculateAverage(Student s1, Student s2){
// double average = (s1.marks + s2.marks)/2;
// cout<<"nThe average marks of two students is: "<<average<<"n"<<endl;
// }

// int main(){
// Student s1(56.33), s2(78.6);
// calculateAverage(s1, s2);
// return 0;
// }

//program to return object from function

// #include <iostream>
// using namespace std;

// class Student{
// public:
// double marks1, marks2;
// };

// Student createStudent(){
// Student student;

// student.marks1 = 56.45;
// student.marks2 = 78.33;

// cout<<"Marks of first student: "<<student.marks1<<endl;
// cout<<"Marks of second student: "<<student.marks2<<endl;

// return student;
// }

// int main(){
// Student s1;
// s1 = createStudent();
// return 0;
// }

//Program to overload unary operator .

// #include <iostream>
// using namespace std;

// class Math{
// public:
// int value;

// Math(){
// value = 5;
// }

// void operator ++(){
// ++value;
// }

// void display(){
// cout<<"Count is :"<<value<<endl;
// }
// };

// int main(){
// Math count;
// ++count;
// count.display();
// return 0;
// }

//program to overload binary operator;


// #include <iostream>
// using namespace std;

// class Complex{
// public:
// int real;
// int imaginary;
// Complex(int r, int img){
// real = r;
// imaginary = img;
// }
// void info(){
// cout<<real<<" + "<<imaginary<<"i"<<endl;
// }
// Complex operator+(const Complex &x){
// return Complex(real+x.real, imaginary + x.imaginary);
// }


// };
// int main() {
// Complex c1(4,5), c2(2,3);
// cout<<"First complex number :";
// c1.info();
// cout<<"second complex number : ";
// c2.info();
// Complex c3 = c1 + c2;
// cout<<"The addition of the above two number is : ";
// c3.info();
// }


// //Program to illustrate concept of Inheritance

// #include <iostream>
// using namespace std;

// // Base class
// class Vehicle {
// public:
// Vehicle(const string& make, const string& model): make_(make), model_(model) {}
// void DisplayInfo() const {
// cout << "Make: " << make_ << endl;
// cout << "Model: " << model_ << endl;
// }
// private:
// string make_;
// string model_;
// };
// // Derived class 1
// class Car : public Vehicle {
// public:
// Car(const string& make, const string& model, int doors): Vehicle(make, model), numDoors_(doors) {}
// void DisplayCarInfo() const {
// DisplayInfo();
// cout << "Number of Doors: " << numDoors_ << endl;
// }
// private:
// int numDoors_;
// };
// // Derived class 2
// class Motorcycle : public Vehicle {
// public:
// Motorcycle(const string& make, const string& model, bool hasFairing): Vehicle(make, model), hasFairing_(hasFairing) {}
// void DisplayMotorcycleInfo() const {
// DisplayInfo();
// cout << "Has Fairing: " << (hasFairing_ ? "Yes" : "No") << endl;
// }
// private:
// bool hasFairing_;
// };
// int main() {
// Car myCar("Toyota", "Camry", 4);
// Motorcycle myMotorcycle("Harley-Davidson", "Sportster", true);
// cout << "Car Information:" << endl;
// myCar.DisplayCarInfo();
// cout << "nMotorcycle Information:" << endl;
// myMotorcycle.DisplayMotorcycleInfo();
// return 0;
// }


// #include <iostream>
// using namespace std;
// // Base class
// class Animal {
// public:
// string publicName = "Animal"; // Public member variable
// void publicMethod() {
// cout << "This is a public method in Animal class." << endl;
// }
// protected:
// string protectedName = "Animal"; // Protected member variable
// void protectedMethod() {
// cout << "This is a protected method in Animal class." << endl;
// }
// private:
// string privateName = "Animal"; // Private member variable
// void privateMethod() {
// cout << "This is a private method in Animal class." << endl;
// }
// };
// // Derived class
// class Dog : public Animal {
// public:
// void printNames() {
// cout << "Public Name (from subclass): " << publicName << endl;
// //Accessible (public)
// cout << "Protected Name (from subclass): " << protectedName << endl;
// //Accessible (protected)
// // Private members are not accessible in the subclass
// }
// void callMethods() {
// publicMethod(); // Accessible (public)
// protectedMethod(); // Accessible (protected)
// // privateMethod(); // Not accessible in the subclass
// }
// };
// int main() {
// Dog myDog;
// //Accessible (public)
// cout << "Public Name (from outside): " << myDog.publicName << endl;
// // protectedName and privateName are not accessible from outside
// myDog.printNames();
// myDog.callMethods();
// return 0;
// }

// #include <iostream>
// using namespace std;
// // Base class
// class Shape {
// public:
// virtual double area() {
// return 0.0; // Default implementation for an undefined shape
// }
// };
// // Derived class representing a Circle
// class Circle : public Shape {
// private:
// double radius;
// public:
// Circle(double r) : radius(r) {}
// // Override the area() function to calculate the area of a circle
// double area() override {
// return 3.1415 * radius * radius;
// }
// };
// // Derived class representing a Rectangle
// class Rectangle : public Shape {
// private:
// double length;
// double width;
// public:
// Rectangle(double l, double w) : length(l), width(w) {}
// // Override the area() function to calculate the area of a rectangle
// double area() override {
// return length * width;
// }
// };
// int main() {
// Shape* shapePtr;
// Circle circle(8.0);
// Rectangle rectangle(3.0, 5.5);
// shapePtr = &circle;
// cout << "Area of the Circle: " << shapePtr->area() << endl;
// shapePtr = &rectangle;
// cout << "Area of the Rectangle: " << shapePtr->area() << endl;
// return 0;
// }


// #include <iostream>
// using namespace std;
// // Abstract base class Vehicle
// class Vehicle {
// public:
// // Pure virtual function for starting the vehicle (no implementation)
// virtual void start() = 0;
// // Regular virtual function
// virtual void displayInfo() {
// cout << "This is a vehicle." << endl;
// }
// };
// // Concrete subclass Car
// class Car : public Vehicle {
// public:
// // Override the pure virtual function start() in the derived class
// void start() override {
// cout << "Car engine started." << endl;
// }
// // Override the displayInfo() function
// void displayInfo() override {
// cout << "This is a Car." << endl;
// }
// };
// // Concrete subclass Bicycle
// class Bicycle : public Vehicle {
// public:
// // Override the pure virtual function start() in the derived class
// void start() override {
// cout << "Pedaling the Bicycle." << endl;
// }
// // Override the displayInfo() function
// void displayInfo() override {
// cout << "This is a Bicycle." << endl;
// }
// };
// int main() {
// // Create objects of Car and Bicycle
// Car car;
// Bicycle bicycle;
// // Define an array of Vehicle pointers
// Vehicle* vehicles[] = {&car, &bicycle};
// // Call start() and displayInfo() for each vehicle
// for (Vehicle* vehiclePtr : vehicles) {
// vehiclePtr->start();
// vehiclePtr->displayInfo();
// cout << endl;
// }
// return 0;
// }


// #include <iostream>
// #include <string>
// using namespace std;
// // Base class Human
// class Human {
// public:
// string name;
// // Constructor
// Human(string n) : name(n) {}
// // Virtual function to display the role (no implementation)
// virtual void displayRole() {
// cout << "Role: Not specified for this person." << endl;
// }
// };
// // Derived class Student
// class Student : public Human {
// public:
// // Constructor
// Student(string n) : Human(n) {}
// // Override the displayRole() function to display the role of a student
// void displayRole() override {
// cout << "Role of " << name << ": Student" << endl;
// }
// };
// // Derived class Teacher
// class Teacher : public Human {
// public:
// // Constructor
// Teacher(string n) : Human(n) {}
// // Override the displayRole() function to display the role of a teacher
// void displayRole() override {
// cout << "Role of " << name << ": Teacher" << endl;
// }
// };
// int main() {
// // Create objects of Student and Teacher
// Student student("Aman Dangi");
// Teacher teacher("Mr. GD");
// // Define a pointer to the base class Human
// Human* humanPtr;
// // Point the base class pointer to a Student object and call displayRole()
// humanPtr = &student;
// humanPtr->displayRole(); // Calls the displayRole() of the Student class
// // Point the base class pointer to a Teacher object and call displayRole()
// humanPtr = &teacher;
// humanPtr->displayRole(); // Calls the displayRole() of the Teacher class
// return 0;
// }
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.