Monday, February 19, 2024

PARTIAL LOOP IN C++

 Why is C++ a partial loop?


  • WHAT IS PARTIAL LOOP WITH EXAMPLES

The object-oriented features of the C language were the main motivation behind the construction of the C++ language.

The C++ programming language is classified as a partial object-oriented programming language, despite supporting OOP concepts including classes, objects, inheritance, encapsulation, abstraction, and polymorphism.

  1. A main function must always be outside a C++ class and is mandatory. This means we can do without classes and objects and have one main function in the application.

It is expressed as an object in this case, which is the first time that Pure OOP has been violated.

2) Global variables are a feature of the C++ programming language that can be used by any other object within the program and defined outside of it. Encapsulation is broken here. Although C++ encourages encapsulation of classes and objects, it ignores it for global variables.


 Let's see an example of a C++ class where we are initializing and displaying an object through the method

 

#include <iostream>  

using namespace std;  

class Student {  

   public:  

       int id;//data member (also instance variable)      

       string name;//data member(also instance variable)      

       void insert(int i, string n)    

        {    

            id = i;    

            name = n;    

        }    

       void display()    

        {    

            cout<<id<<"  "<<name<<endl;    

        }    

};  


int main(void) 

{  

    Student s1; //creating an object of Student   

    Student s2; //creating an object of Student  

    s1.insert(201, "aniket");    

    s2.insert(202, "riyali");    

    s1.display();    

    s2.display();  

    return 0;  

}  

 Output

Aniket

Riyali

Let's see an example of a C++ class where we are storing and displaying employee information using the method

 #include <iostream>  

using namespace std;  

class Employee {  

   public:  

       int id;//data member (also instance variable)      

       string name;//data member(also instance variable)  

       float salary;  

       void insert(int i, string n, float s)    

        {    

            id = i;    

            name = n;    

            salary = s;  

        }    

       void display()    

        {    

            cout<<id<<"  "<<name<<"  "<<salary<<endl;    

        }    

};  

int main(void) {  

    Employee e1; //creating an object of Employee   

    Employee e2; //creating an object of Employee  

    e1.insert(201, "Rinki",990000);    

    e2.insert(202, "Rakesh", 29000);    

    e1.display();    

    e2.display();    

    return 0;  

}  

 

Output

201, "Rinki",990000   

202, "Rakesh", 29000

No comments:

Post a Comment

Featured Post

ASSOCIATION RULE IN MACHINE LEARNING/PYTHON/ARTIFICIAL INTELLIGENCE

Association rule   Rule Evaluation Metrics Applications of Association Rule Learning Advantages of Association Rule Mining Disadvantages of ...

Popular