Trending November 2023 # Definition, Types, Precedence And Examples # Suggested December 2023 # Top 15 Popular

You are reading the article Definition, Types, Precedence And Examples updated in November 2023 on the website Hatcungthantuong.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested December 2023 Definition, Types, Precedence And Examples

What are Operators in C?

The C programming language utilizes operators as symbols representing precise operations to be executed on one or more operands. C provides a wide range of operators that can perform arithmetic, logical, and bitwise operations and operations on pointers and arrays. Operators are symbols that help in performing functions of mathematical and logical nature. The classification of C operators is as follows:

Arithmetic

Relational

Logical

Bitwise

Assignment

Conditional

Special

Even though there are many operators, the execution of these operations happens based on the precedence given to them. Precedence is the order in which the compiler executes the code comprising numerous operators.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Explanation of Operators in C

Below is a detailed explanation of operators in C:

#1 Arithmetic Operators

These operators are responsible for performing arithmetic or mathematical operations like addition (+), subtraction (-), multiplication (*), division (/), the remainder of the division (%), increment (++), and decrement (–).

There are two types of arithmetic operators:

Unary Operators: This type of operator works with a single value (operand) like ++ and –.

Binary Operators: This type of operator works with two operands like +,-,*,/

Here is a tabular form of the number of arithmetic operators in C with the functions they perform.

Operator Function

– Subtract a second value from the first.

* Multiply two values

/ Divide numerator by the denominator

% Remainder of division

++ Increment operator – increases integer value by one.

— Decrement operator – decreases integer value by one

int main() { int a = 12, b = 6, c; c = a + b; printf(“a+b = %d n”, c); c = a – b; printf(“a-b = %d n”, c); c = a *b; printf(“a*b = %d n”, c); c = a / b; printf(“a/b = %d n”, c); c = a % b; printf(“Remainder when a divided by b = %d n”, c); return 0; }

Output:

#2 Relational Operators

The below table lists the relational operators in C with their functions.

Operator Function Example

== It will check if the two operands are equal 6 == 2 returns 0

!= It will check if the two operands are not equal. 6 != 2 returns 1

> It will check if the operand on the left is greater than the operand on the right

< It will check if the operand on the left is smaller than the right operand 6 < 2 returns 0

>= It will check if the left operand is greater than or equal to the right operand

<= It will check if the operand on the left is smaller than or equal to the right operand 6 <= 2 return 0

Example: C Program using relational operators

int main() { int a = 7, b = 7, c = 10; printf(“%d == %d = %d n”, a, b, a == b); printf(“%d == %d = %d n”, a, c, a == c); printf(“%d < %d = %d n”, a, b, a < b); printf(“%d < %d = %d n”, a, c, a < c); printf(“%d != %d = %d n”, a, b, a != b); printf(“%d != %d = %d n”, a, c, a != c); printf(“%d <= %d = %d n”, a, b, a <= b); printf(“%d <= %d = %d n”, a, c, a <= c); return 0; }

Output:

#3 Logical Operators

Logical Operators are to get True or False results.

The table below lists the logical operators used in C

Operator Function Example (if a=1 and b=0)

&& Logical AND (a && b) is false

|| Logical OR

! Logical NOT (!a) is false

Example: C Program using logical operators.

int main() { int a = 8, b = 8, c = 12, result; result = (a == b) && (c < b); printf(“(a == b) && (c < b) equals to %d n”, result); result = !(a != b); printf(“!(a == b) equals to %d n”, result); result = !(a == b); printf(“!(a == b) equals to %d n”, result); return 0; }

Output:

#4 Bitwise Operators

These operators are for bit-level operations on the operands. The operators first convert into bit-level and then perform the calculations.

Operator Function

& Bitwise AND

| Bitwise OR

^ Bitwise exclusive OR

~ Bitwise complement

<< Shift left

>> Shift right

Example: C program for Bitwise AND

int main() { int a = 10, b = 8; printf(“Output = %d”, a&b); return 0; }

Output:

Explanation:

00001010 & 00001000 = 00001000 = 8 (In decimal)

#5 Assignment Operators

These types of operators help us assign a value to a variable.

Operator Function Example

= It will assign values from right-side operands to left-side operands a=b

+= It will add the right operand to the left operand and assign the result to left a+=b is the same as a=a+b

-= It will subtract the right operand from the left operand and assign the result to the left operand a-=b is the same as a=a-b

*= It will multiply the left operand with the right operand and assign the result to the left operand a*=b is the same as a=a*b

/= It will divide the left operand with the right operand and assign the result to the left operand a/=b is the same as a=a/b

%= It will calculate the modulus using two operands and assign the result to the left operand a%=b is the same as a=a%b

#6 Conditional Operators

Also, known as Ternary Operator or? : Operator, these operators are useful for decision-making.

Syntax:

Expression 1? Expression 2: Expression 3 #7 Special Operators

Here are some special operators used in C

Operator Function

& This operator is used to get the address of the variable.

Example: &a will give an address of a.

* This operator works as a pointer to a variable.

Example: * a where * is a pointer to the variable a.

size of () This operator gives the size of the variable.

Example: The size of (char) will give us 1.

Example: C program using a special operator

int main() { int *ptr, q; q = 40; /* It assigns the address of q to ptr */ ptr = &q; /* display q’s value using ptr variable */ printf(“%d”, *ptr); return 0; }

Output:

C Operators Precedence

Generally, arithmetic, logical, and relational operators are used while coding in C. The precedence for these operators in arithmetic is greater than logical and relational. Note that all the operators in arithmetic also follow a different order of precedence. Let’s check which operators hold the highest precedence.

Order of Precedence in Arithmetic Operators

The increment and decrement (+ + and – -) operators hold the highest precedence in arithmetic operators. After that next precedence is for the unary minus ( – ) operator; next, three operators, /, *, and %, have equal precedence. The lowest precedence is for the operators like addition ( + ) and subtraction ( – ). In case of equal priority, the compiler takes charge while evaluating them. Remember the C operator associativity rule for all operators with the same precedence. Then the execution happens from left to right.

For example,

int main() { int a = 15, b = 20, c = 32, result; result = a * b – ++c; printf(“The result is: %d”, result); return 0; }

Output:

Explanation: Here, in the given equation, first, “++” executes; hence the value of c will be 33. Next, “* “holds the highest precedence after “++.” Hence after the execution of “a * b,” the result will be 300. Then the execution of “-” happens and results in 267.

Order of Precedence in Relational/Logical Operators

For example,

Output: False

Misc Operators in C

The Misc operators or miscellaneous operators are conditional operators that include three operands. In these 3, the execution of the first operand happens first. Then the execution of the second operand, if it is non-zero, or a third operand executes to provide the necessary Output. Besides the operators discussed above, C programming language supports a few other special operators like sizeof and “?:”.

Operator Description Example

sizeof() Finds the size of a variable sizeof(b), if b is an integer, then the Output will be 4.

?: Conditional operator Condition? X: Y; here, if the condition is true, the result will be X, else Y.

* Pointer *a

Time and Space Complexity

Time and space complexity are the terms concerning the execution of an algorithm. The Time complexity is the time taken to run the algorithm as a function of the input. Space complexity is the space or memory the algorithm takes as an input function. These two terms depend on many terms like processor, operating system, etc.

Final Thoughts

C operators are the symbols used to perform relational, mathematical, bitwise, or logical operations. C language includes a lot of operators to perform various tasks as necessary in the program. Different kinds of operators are arithmetic, logical, and relational.

Q1. What are the boolean operators in C?

Q2. What does ** mean in C?

Answer: The “**” in C is a double-pointer or pointer-to-pointer. Where * is a pointer that holds the address of the variable. ** mean the address of a variable already holding an address of a different variable.

Q3. What is the difference between prefix and postfix operators in C?

Answer: Prefix and postfix are the operators written before and after the operands. These operators are the increment (+ +) and decrement (- -) operators. For example, “++c” is the prefix operator, and “c++” is the postfix operator.

Q4. What is the Modulus operator?

Answer: The modulus operator is the arithmetic operator of C, and it works between two operands. The division of the numerator value by the denominator results in the remainder. In simpler words, the produced rest for the integer division is the modulus operator.

Answer: Operator overloading is a method of polymorphism where the programmer makes specific changes in the existing code without changing its meaning. Operator overloading is possible only in C++. Since polymorphism is possible only in an object-oriented language, C doesn’t support operator overloading.

Recommended Articles

This EDUCBA guide to C Operators discusses the operators used in C language with their syntax and examples. EDUCBA also suggests the following articles to learn more.

You're reading Definition, Types, Precedence And Examples

Boosting In Machine Learning: Definition, Functions, Types, And Features

This article was published as a part of the Data Science Blogathon.

Introduction

Boosting is a key topic in machine learning. Numerous analysts are perplexed by the meaning of this phrase. As a result, in this article, we are going to define and explain Machine Learning boosting. With the help of “boosting,” machine learning models are able to enhance the accuracy of their predictions. Let’s take a closer look at this approach:

What is Boosting in Machine Learning?

Before delving into the topic of ‘Machine Learning boosting,’ it is necessary to explore the term’s meaning. Boosting is defined as ‘encouraging or assisting something in improving.’ Machine learning augmentation does the same objective by empowering machine learning models and increasing their accuracy. As a result, it is a widely used algorithm in data science.

IMAGE

In machine learning, boosting refers to the methods that transform weak learning models into strong ones. Assume we need to categorize emails as ‘Spam’ or ‘Not Spam’. To make these differences, we can apply the following approach:

If an email has only one picture file, it is spam (because the image is usually promotional)

If the email begins with the line ‘You have won the lottery,’ it is spam.

If an email has only a collection of links, it is spam.

If the email originates from a source in our contact list, it is not spam.

Now, while we have categorization criteria in place, do you believe they are powerful enough on their own to determine if an email is a scam or not? That is not the case. On their own, these principles are insufficient to categorize an email as ‘Not Spam’ or ‘Spam.’ We’ll need to strengthen them, which we may achieve by adopting a weighted average or by taking into account the forecast of the higher vote.

Thus, in this situation, we have five classifiers, three of which classify the email as ‘Spam.’ As this class has a greater vote total than the ‘Not Spam’ category, we will consider an email to be ‘Spam’ by default.

This example was intended to demonstrate the concept of boosting techniques. They are more intricate than that.

How do they work?

As seen in the preceding example, boosting combines weak learners to generate rigorous rules. Therefore, how would you recognize these flaws in the rules? To discover an unknown rule, instance-based learning techniques must be used. Whenever a base learning method is used, a weak prediction rule is generated. You’ll repeat this procedure numerous times, and the boosting algorithm will merge the weak rules into a strong rule with each iteration.

Each iteration of the boosting algorithm finds the best possible distribution. It will begin by distributing the allocations equally across several categories. Observations will be given more weight if the first learning process makes a mistake. After allocating weight, we go on to the next step.

In this stage, we’ll continue the procedure till our algorithm’s accuracy improves. The output of the weak learners will then be combined to produce a strong one, which will strengthen our model and enable it to make more accurate predictions. A boosting algorithm focuses on the assumptions that result in excessive mistakes as a result of their insufficient regulations.

Different Kinds of Boosting Algorithms

Boosting algorithms may be implemented using a variety of different types of underlying engines, such as margin maximizers, decision stamps, and others. There are three primary types of Machine Learning augmentation algorithms:

XGBoost

The first two, AdaBoost and Gradient Boosting, will be discussed briefly in this article. XGBoost is a far more difficult subject, which we will address in a future article.

Consider a box with five pluses and five minutes. Your assignment is to categorize them and organize them into distinct tables.

In the first iteration, you weigh each data point equally and use a decision stump in the box. However, the line separates just two pluses from the group; the remaining pluses stay together. Your decision stump (which is a line that runs through our fictitious box) fails to accurately forecast all data points and has substituted three pluses for the minuses.

In the subsequent iteration, we give greater weight to the three pluses we overlooked earlier; but, this time, the decision stump only separates the group by two minutes. We’ll reweight the minuses that were overlooked in this iteration and restart the procedure. After a few repetitions, we can integrate several of these outcomes to generate a single rigorous prediction rule.

AdaBoost operates in the same manner. It begins by predicting using the original data and weighing each point equally. Then it gives bigger weight to observations that the first learner fails to accurately anticipate. It repeats this procedure until the model’s accuracy exceeds a predefined limit.

Adaboost supports decision stamps as well as other Machine Learning methods.

Here is an AdaBoost implementation in Python:

from sklearn.ensemble import AdaBoostClassifier from sklearn.datasets import make_classification X,Y = make_classification(n_samples=100, n_features=2, n_informative=2, n_redundant=0, n_repeated=0, random_state=102) clf = AdaBoostClassifier(n_estimators=4, random_state=0, algorithm=’SAMME’) clf.fit(X, Y)

Gradient Boosting uses the Gradient descent approach to minimize the operation’s loss function. Gradient descent is a first-order optimization process for locating a function’s local minimum (differentiable function). Gradient boosting trains several models consecutively and can be used to fit innovative models to provide a more accurate approximation of the response.

It creates new base learners that correspond with the negative gradient of the loss function and are connected to the whole system. Gradient Tree Boosting will be required in Python (also known as GBRT). It may be used to solve classification and regression difficulties.

Here is an implementation of Python Gradient Tree Boosting:

Features of Boosting in Machine Learning

Since boosting is an ensemble model, it’s pretty natural to interpret its predictions.

Boosting algorithms have higher predictive power than decision trees and bagging.

Scaling it up is a little more challenging, as each estimator in boosting is predicated on the previous estimators.

Conclusion

I really hope you found this post about boosting to be informative. First, we spoke about what this algorithm is and how it may be used to address problems in Machine Learning. Its functioning and how it functions were then examined in greater detail.

We also spoke about the many kinds of it. We learned about AdaBoost and Gradient Boosting as a result of their examples, which we shared as well.

I’m glad you found it interesting. In order to contact me, you may do so using the following methods:

If you still have questions, feel free to send them to me by e-mail.

Read more articles on Machine Learning on our blog.

Related

Salesforce Testing: Definition, Types, Tools, Jobs, Benefits

What is Salesforce Testing?

Salesforce testing primarily concerns testing your Salesforce deployments to affirm their functionality as required. Salesforce testing is validation testing by a tester to check codes in developed applications with built-in salesforce functionality. It is mainly the customization of codes performed with vanilla SDFC and done primarily to test codes developed by developers.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Key Highlights

Salesforce testing tests and customizes applications to provide quality and error-free applications.

Its types include End-to-End, Regression, Load & performance, and manual and automated testing.

Some famous tools are Selenium, testRigor, Tricentis, and Panaya Foresight.

Coordination, clear communication, and role-based testing are important roles of testers.

Why is it Important?

It is essential for reducing development costs and application development in a short time.

It helps to verify the problems and fix them quickly by providing easy functional flow creation to the team.

It allows the organization to limit physical servers of web applications and storage issues.

It helps to customize the application codes, and customer needs as per requirement. As a result, it is the most relevant method and tool for validating customized features in built-in applications.

Furthermore, it helps to enable quality in the finished product by identifying the bugs and risks at the initial stages.

Types #1 Manual testing

The manual testing process includes testing through the chúng tôi application through traditional methods.

The QA team uses manual functional testing like happy path tests, integration tests, and system and regression tests.

#2 Automated testing

Automated testing includes using a computer testing program for testing in chúng tôi or chúng tôi applications.

#3 End-to-end testing

Administrators prebuilt test cases and situations with limited technical experience in this testing.

It is time-consuming but provides a quick workout of an exhaustive process.

This testing includes visual testing to track user experiences.

#4 Regression testing

Through this testing, developers and testers identify the need for new or existing changes in the codes of applications.

The difference can be either small or large and completed after changes are made to any code of an application.

Testers use this testing to leverage automation tools in the sandbox environment.

It is done to confirm the performance of the salesforce in serving users by monitoring inputs, workflows, and queries.

Top Testing Tools 1. Selenium

Selenium Contains different tools and libraries to support browser automation.

It is an open-source umbrella project that helps authoritarian functional tests all over modern websites.

2. TestRigor

TestRigor provides effortless solutions for testing using simple English commands.

It is supported in Web, all browsers, mobile, iOS, and OS systems.

3. Tricentis

Tricentis provides fast and relevant UI testing facilities for salesforce applications.

Tricentis contain self-healing and improving locators to stabilize tests and reduce maintenance costs. End-to-end extensions of scenarios from web applications are also available.

4. Panaya Foresight

Panaya Foresight is a salesforce testing tool that controls an organization’s salesforce through risks and impacts identification.

It enables 85% bug reduction in the production process and risk-based testing.

Increasing Demand for Salesforce Testing

Every enterprise nowadays needs automation as a mandatory process to solve critical production issues.

It is expected to provide easy solutions to functional flow creation with the visual and no-code approach in teams of organizations.

According to the World Quality Report 2023-2023, the need for quality assurance in the future will accelerate. Thus, the need for manual and automated testing will grow.

Important Roles of Salesforce Testing

Clear communication among testers and developers is essential in salesforce testing.

Coordination among testers and business as per required document for salesforce needs efforts.

Role-based testing by testers to ensure consistent data testing is an essential role.

Furthermore, compatibility testing in third-party applications is an important role that testers must be familiar with.

Familiarity with application flows and performing tests per salesforce standard rules is also necessary.

The tester needs to understand the customizable features that can help develop the salesforce application.

Boundary value analysis and Equivalence partitioning are essential roles for a tester.

Related Jobs a. Salesforce Developer

Responsibilities include a timeline and goal creation. Also, need to test the stability and functioning of the application.

A Salesforce Developer (fresher) salary starts from \$62k to \$124k per annum.

b. QA Analyst

They are responsible for identifying flaws and errors in a program.

Full functionality and free-from-bug applications are the primary goals of QA Analysts.

The basic salary for QA Analyst starts from \$42k to \$83k.

c. ETL Testers

The job responsibility includes transformation logic, validating data sources, and uploading data in target areas.

The salary of an ETL Tester averages up to \$95k per annum.

Essential Tips for Salesforce Testing

In salesforce testing, test data needs to be validated before reporting functionality.

Automation testing should be done using Selenium and HP functional testing tools.

It must include UI testing, Regression, system, and functional testing methods.

Testers must know their roles and positive & negative functional flows in applications.

Tests should be run as real profile users rather than testers and developers.

Benefits of Salesforce Testing

Salesforce testing provides reliable software development.

It improves the quality of end products.

It helps to reduce business risks.

It can provide quick execution and test coverage.

It also reduces the development and maintenance costs of organizations.

Optimization of the test process is available.

Reduce data leakage and security issues.

Increases customer relationships and confidence.

Salesforce administration can develop internal users in salesforce platforms.

Developers can easily reuse existing applications from App Exchange to customize their applications.

Conclusion

Salesforce is the first cloud-based Customer Relationship Management. It is used to validate and customize applications per requirements and bug detections. Salesforce testing contains challenges of testing the customization without testing the SDFC features. Selenium, UFT, and other crucial salesforce tools for testing.

FAQs Q1. How to carry out salesforce testing?

Answer: To test, as a tester, you must do functional testing to check bugs. Then check for the smooth running of the development with existing features. Salesforce UAT testing is the next phase, where the real-world business case should be used for functionality checking.

Q2. Is Salesforce testing in demand? Q3. What is required for Salesforce testing?

Answer: For performing Salesforce testing, a tester must include functional testing, system testing, UI testing, regression testing, and system integration testing. Tools such as Selenium and HP Unified Functional Testing (UFT) can be used for automation testing.

Q4. Is coding required for Salesforce testing?

Answer: Salesforce, a low or no-code app development organization, doesn’t need a salesforce developer with a background in coding. This is why it can be a perfect choice for an IT aspirant without a coding background.

Recommended Articles

Types Of Xml Parsers With Examples

Definition of XML Parsers How does XML Parsers Work?

Fig: XML parser Process

The Parser could be categorized as validating and non- validating

Validating Parser: It needs a Document type Declaration to parse and gives an error if the respective document doesn’t match with DTD and constraints.

Non-Validating: This Parser eliminates DTD and the parser checks for the well-formed document.

Types of XML Parsers with Examples

This section talks about various types of parsers used recently in parsing XML document. They are:

DOM Parser

SAX Parser

JDOM Parser

stAX Parser

Xpath Parser

The most important type is DOM and SAX which is explained detail in this article.

1. DOM Parser (Tree-Based)

Document Object Model is a W3C Standard and converts the XML document which is to parsed into a collection of objects and uses DOM API. It consists of a collection of nodes and is associated with other nodes in the tree. DOM is much easier to use as sorting and searching process is made chúng tôi DOM parser the content of the XML file is modified with Node and Node List. The Steps involved in Parsing with java:

Getting document builder objects

Taking XML document as input, parseit and return the class.

Getting values of the input id through attributes and sub-elements.

Display the results.

First is the XML file that generates the values which are going to be parse and java objects are constructed automatically.

Example

chúng tôi

}

And here is the Output is shown for the XML File. Save XML and java file in the same folder during execution. In this article I have used java-jdk- 13.0.1 using command prompt. Save the respective folder in any drive and do the set path.

Output:

2. SAX Parser

SAX Is Simple API for XML and meant has Push Parseralso considered to be stream-oriented XML Parser. it is used in case of high- performance applications like where the XML file is too largeand comes with the community- based standard and requires less memory. The main task is to read the XML file and creates an event to do call functionor uses call back routines. The working of this parser is just like Event handler part of the java. it is necessary to register the handlers to parse the document for handing different events. SAX Parser uses three methods startElement() , endElement() , characters().

startElement(): Is used to identify the element, start element is identified.

endElement(): To stop the Supermarket tag in the example.

character(): Is used to identify the character in the node

The xml file is the same file used in DOM Parser chúng tôi and next step generate chúng tôi file

Example

Rsax.java

}

Output:

Conclusion

Therefore, we have discovered how to use XML parsers in Java with the powerful APIs in the applications.Also, we have seen the implementation of two parsers using java. When compared with DOM,sax parser uses arbitrary size to parse whereas DOM requires available memory to load the complete chúng tôi Parsers differs based on the performance.

Recommended Articles

This is a guide to XML Parsers. Here we also discuss how does xml parsers work? along with examples and its code implementation. You may also have a look at the following articles to learn more –

Oracle Pl/Sql Object Types Tutorial With Examples

What is Object Type in PL/SQL?

Object-Oriented Programming is especially suited for building reusable components and complex applications. They are organized around “objects” rather than “actions” i.e. the programs are designed to work and interact with the entire object rather than the single action. This concept allows the programmer to populate and manipulate the details at object entities level.

Below picture depicts an example of the object type in which a bank account is considered an object entity. The object attributes include things which are holding some attribute values, for example in Bank Account; it is Account number, bank balance, etc. while object methods describe the things like calculating interest rate, generating bank statement, etc. which requires certain process to be completed.

In PL/SQL object-oriented programming is based on object types.

An object type can represent any real-world entity. We are going to discuss more object types in this chapter.

In this tutorial – you will learn,

Components of Object Types

PL/SQL object type contains mainly two components.

Attributes

Members/Methods

Attributes

Attributes are the column or field in which data are stored. Each attribute will be mapped to the datatype that defines the processing and storage type for that attribute. The attribute can be of any valid PL/SQL datatype, or it can be of another object type.

Members/Methods

Members or Methods are subprograms that is defined in the object type. They are not used to store any data. They are mainly used to define process inside the object type. For examples validating data before populating the object type. They are declared in the object type section and defined in the object type body section of the object type. Body section in object type is an optional part. If no members are present, then an object type will contain no body part.

Create Object in Oracle

An Object type cannot be created at subprogram level, They can be created only at the schema level. Once the object type is defined in the schema, then the same can be used in subprograms. The object type can be created using ‘CREATE TYPE’. The type body can be created only after creating its object type.

( . . ); / ( IS BEGIN END;‭ . . ‬ ); /

Syntax Explanation:

The above syntax shows the creation of ‘OBJECT’ with attributes and ‘OBJECT-BODY’ with methods.

The methods can also be overloaded in the object body.

Declaration Initialization of Object Type

Like other components in PL/SQL, object types are also needed to be declared before using them in the program.

Once the object type is created it can be used in subprogram declarative section to declare a variable of that object type.

Whenever any variable is declared in the subprogram as object type, at run-time a new instance of the object type will be created, and this newly created instance can be referred to the variable name. By this way, a single object type can store multiple values under different instances.

DECLARE BEGIN . . END; /

Syntax Explanation:

The above syntax shows the declaration of a variable as an object type in the declarative section.

Once the variable is declared as an object type in a subprogram, it will be atomically null i.e. the entire object itself a null. It needs to be initialized with values to use them in the program. They can be initialized using constructors.

Constructors are the implicit method of an object that can be referred with the same name as that of the object type. The below syntax shows the initialization of the object type.

DECLARE BEGIN END; /

Syntax Explanation:

The above syntax shows the initialization of the object type instance with a null value.

Now the object itself is not null as it has been initialized, but the attributes inside the object will be null as we have not assigned any values to these attributes.

Constructors

Constructors are the implicit method of an object that can be referred with the same name as that of the object type. Whenever the object is referred for the first time, this constructor will be called implicitly.

We can also initialize the objects using these constructor. The constructor can be defined explicitly by defining the member in object type body with the same name of the object type.

Example 1: In the following example we are going to use the object type member to insert the record into emp table with values (‘RRR’, 1005, 20000, 1000) and (‘PPP’, 1006, 20000, 1001). Once the data is inserted, we are going to display the same using object type member. We are also going to use the explicit constructor to populate the manager id by default with 1001 value for the second record.

We are going to execute it in below steps.

Step1:

Create Object type

Object type body

Step2: Creating an anonymous block to call created object type through implicit constructor for emp_no 1005.

Step3: Creating an anonymous block to call created object type through explicit constructor for emp_no 1006.

Step 1) Create Object type and Object type body

CREATE TYPE emp_object AS OBJECT( emp_no NUMBER, emp_name VARCHAR2(50), salary NUMBER, manager NUMBER, CONSTRUCTOR FUNCTION emp_object(p_emp_no NUMBER, p_emp_name VARCHAR2, p_salary NUMBER) RETURN SELF AS RESULT), MEMBER PROCEDURE insert_records, MEMBER PROCEDURE display_records); /

CREATE OR REPLACE TYPE BODY emp_object AS CONSTRUCTOR FUNCTION emp_object(p_emp_no NUMBER,p_emp_name VARCHAR2, p_salary NUMBER) RETURN SELF AS RESULT IS BEGIN Dbms_output.put_line(’Constructor fired..'); SELF.emp_name:=p_emp_name; SELF.salary:=p_salary; SELF.managerial:=1001; RETURN; END: MEMBER PROCEDURE insert_records IS BEGIN INSERT INTO emp VALUES(emp_noemp_name,salary,manager); END MEMBER PROCEDURE display_records IS BEGIN END: END: /

Code Explanation

Code line 1-9: Creating the ’emp_object’ object type with 4 attributes and 3 members. It contains the definition of constructors with only 3 parameters. (Actual implicit constructor will contain the number of parameters equal to the number of attributes present in the object type)

Code line 10: Creating the type body.

Code line 11-21: Defining the explicit constructor. Assigning the parameter value to the attributes and assigning the value for attribute ‘manager’ with the default value ‘1001’.

Code line 22-26: Defining the member ‘insert_records’ in which the attributes values are inserted into ’emp’ table.

Code line 27-34: Defining the member ‘display_records’ in which displaying the values of the object type attributes.

Output

Type created

Type body created

Step 2) Creating anonymous block to call created object type through implicit constructor for emp_no 1005

DECLARE guru_emp_det emp_object; BEGIN guru_emp_det:=emp_object(1005,’RRR',20000,1000); guru_emp_det.display_records; guru_emp_det.insert_records; COMMIT; END;

Code Explanation

Code line 37-45: Inserting the records using the implicit constructor. Call to constructor contains the actual number of attributes values.

Code line 38: Declares the guru_emp_det as object type of ’emp_object’.

Code line 41: Statement ‘guru_emp_det.display_records’ called the ‘diplay_records’ member function and the attributes values are displayed

Code line 42: Statement ‘guru_emp_det.insert_records’ called the ‘insert_records’ member function and the attributes values are inserted into the table.

Output

Employee Name: RRR

Employee Number: 1005

Salary: 20000

Manager : 1000

Step 3) Creating anonymous block to call created object type through explicit constructor for emp_no 1006

DECLARE guru_emp_det emp_object; BEGIN guru_emp_det:=emp_object(1006,'PPP',20000); guru_emp_det.display_records; guru_emp_det.insert_records; COMMIT; END; /

Output

Employee Name:PPP Employee Number:1006 Salary:20000 Manager:1001

Code Explanation:

Code line 46-53: Inserting the records using the explicit constructor.

Code line 46: Declares the guru_emp_det as object type of ’emp_object’.

Code line 50: Statement ‘guru_emp_det.display_records’ called the ‘display_records’ member function and the attributes values are displayed

Code line 51: Statement ‘guru_emp_det.insert_records’ called the ‘insert_records’ member function and the attributes values are inserted into the table.

Inheritance in Object Type

Inheritance property allows the sub-object type to access all the attribute and members of the super object type or parent object type.

The sub-object type is called inherited object type, and the super object type is called parent object type. The below syntax shows the how to create parent and inherited object type.

( . . )NOT FINAL; /

Syntax Explanation:

The above syntax show the creation of SUPER type.

( . ); /

Syntax Explanation:

The above syntax shows creation of SUB type. It contains all the members and attributes from the parent object type.

Example1: In the below example, we are going to use the inheritance property to insert the record with manager id as ‘1002’ for the following record (‘RRR’, 1007, 20000).

We are going to execute the above program in the following steps

Step1: Create SUPER type.

Step2: Create SUB type and body.

Step3: Creating an anonymous block to call the SUB type.

Step 1) Create SUPER type or Parent type.

CREATE TYPE emp_object AS OBJECT( emp_no NUMBER, emp_name VARCHAR2(50), salary NUMBER, manager NUMBER, CONSTRUCTOR FUNCTION emp_object(p_emp_no NUMBER,p_emp_name VARCHAR2(50), p_salary NUMBER)RETURN SELF AS RESULT), MEMBER PROCEDURE insert_records, MEMBER PROCEDURE display_records)NOT FINAL; /

Code Explanation:

Code line 1-9: Creating the ’emp_object’ object type with 4 attributes and 3 members. It contains the definition of constructors with only 3 parameters. It has been declared as ‘NOT FINAL’ so it is parent type.

Step 2) Create SUB type under SUPER type.

CREATE OR REPLACE TYPE sub_emp_object UNDER emp_object (default_manager NUMBER,MEMBER PROCEDURE insert_default_mgr); / CREATE OR REPLACE TYPE BODY sub_emp_object AS MEMBER PROCEDURE insert_default_mgr IS BEGIN INSERT INTO emp VALUES(emp_no,emp_name:salary,manager): END; END; /

Code Explanation:

Code line 10-13: Creating the sub_emp_object as inherited type with additional one attribute ‘default_manager’ and member procedure declaration.

Code line 14: Creating the body for the inherited object type.

Code line 16-21: Defining the member procedure which is inserting the records into “emp” table with the values from ‘SUPER’ object type, except for manager value. For manager value, it is using the ‘default_manager’ from ‘SUB’ type.

Step 3) Creating anonymous block to call the SUB type

DECLARE guru_emp_det sub_emp_object; BEGIN guru_emp_det:= sub_emp_object(1007,'RRR',20000,1000,1002); guru_emp_det.insert_default_mgr; COMMIT; END; /

Code Explanation:

Code line 25: Declaring ‘guru_emp_det’ as ‘sub_emp_object’ type.

Code line 27: Initializing the object with the implicit constructor. The constructor is having 5 parameters (4 attributes from PARENT type and 2 attributes from SUB type). The last parameter (1002)defines the value for default_manager attribute

Code line 28: Calling the member ‘insert_default_mgr’ to insert the records with the default manager id passed in the constructor.

Equality of PL/SQL Objects

The object instance that belongs to the same objects can be compared for equality. For this, we need to have the special method in the object type called ‘ORDER’ method.

This ‘ORDER’ method should be the function that returns numerical type. It takes two parameters as input, (first parameter: id of the self-object instance, second parameter: id of another object instance).

The id of the two object instance is compared, and the result is returned in numerical.

Positive value represents that the SELF object instance is greater than another instance.

Negative value represents that the SELF object instance is lesser than another instance.

Zero represents that the SELF object instance is equal to another instance.

If any of the instances is null, then this function will return null.

( RETURN INTEGER IS BEGIN RETURN -1; --any negative number will do RETURN 1; —any positive number will do ELSE RETURN 0; END IF; END; . . ); /

Syntax Explanation:

The above syntax shows the ORDER function that needs to be included in the type body for equality check.

The parameter for this function should be an instance of the same object type.

The above function can be called as “obj_instance_1.match(obj_instance_2)” and this expression will return the numerical value as shown, where obj_instance_1 and obj_instance_2 are the instance of object_type_name.

Example1: In the following example we are going to see how to compare two objects. We are going to create two instances and we are going to compare attribute ‘salary’ between them. We are going to do int two steps.

Step 1: Creating the Object type and body.

Step 2: Creating the anonymous block to call compare the object instance.

Step 1) Creating the Object type and body.

CREATE TYPE emp_object_equality AS OBJECT( salary NUMBER, ORDER MEMBER FUNCTION equals(c emp_object_equality)RETURN INTEGER); / CREATE TYPE BODY emp_object_equality AS ORDER MEMBER FUNCTION equals(c emp_object_equality)RETURN INTEGER IS BEGIN‭ ‬ IF salary<c.salary THEN RETURN -1; THEN RETURN 1; ELSE RETURN 0; END IF:‭ ‬ END; END; /

Code Explanation:

Code line 1-4: Creating the ’emp_object_equality’ object type with 1 attributes and 1 member.

Code line 6-16: Defining the ORDER function which compares the ‘salary’ attribute of SELF instance and parameter instance type. It returns negative if SELF salary is lesser or positive if SELF salary is greater and 0 if salaries are equal.

Code Output:

Type created

Step 2) Creating the anonymous block to call compare the object instance.

DECLARE l_obj_l emp_object_equality; l_obj_2 emp_object_equality; BEGIN l_obj_l:=emp_object_equality(15000); l_obj_2:=emp_object_equality(17000); THEN Dbms_output.put_line(’Salary of first instance is greater’): ELSIF l_obj_l.equalS(l_obj_2)<0 THEN Dbms_output.put_line(’Salary of second instance is greater’); ELSE Dbms_output.put_line(’Salaries are equal’); END IF; END; /

Output

Salary of second instance is greater

Code Explanation:

Code line 20: Declaring the l_obj_1 of emp_object_equality type.

Code line 21: Declaring the l_obj_2 of emp_object_equality type.

Code line 23: Initializing l_obj_1 with salary value as ‘15000’

Code line 24: Initializing l_obj_1 with salary value as ‘17000’

Code line 25-33: Print the message based on the return number from the ORDER function.

Summary

In this chapter, we have seen the object type and their properties. We have also discussed about Constructors, Members, Attributes, Inheritance and Equality in PL/SQL objects.

Undue Enrichment: Definition And Meaning

Undue enrichment is a compound word composed of the phrases “undue” and “enrichment.” If we discuss immorality or injustice, Unfairness is defined as a situation that does not adhere to the rules of justice and justification.

“Unjust” is described as something that is both unjust and not in conformity with the established norms of justice or fairness.

On the other hand, if we are talking about wealth or enrichment, it is claimed that someone has enriched themselves when they get something from someone. Additionally, this prosperity may be both just and unjust. Unless the loss of the other person is adequately made up for, that is, if anything is given in exchange for its loss, this enrichment continues to fall under the category of being unjustified.

What is the meaning of Undue Enrichment?

A restitutionary remedy would be used to return the benefit to its rightful owner, either on the grounds that there has been a complete failure of consideration or via a quantum merit payment for the reasonable value of the performance. In the general field of contracts, undue enrichment typically takes the form of a benefit accruing to one party that, for some reason, may be regarded as belonging to another. These situations are frequently referred to as examples of enrichment via deductions from the claimant. Restitutionary remedies in this situation do not address a party’s failure to meet another party’s contractual obligations.

Instead, they attempt to recover money that was paid out or the value of a benefit received in situations where there is no contract or where there is no longer a duty to perform under an acknowledged contract. As a result, their availability is not solely dependent on whether a contract has been broken; however, in cases where a breach has occurred, the plaintiff will need to choose between a claim for expectation loss and a restitutionary remedy to determine which would offer a higher level of compensation. On the other hand, there may be enrichment, which in some cases may be deemed unjust, when one party benefits from an injustice committed against the other party without taking anything away from that party. In such situations, the question of whether restitutionary damages will be available is raised.

Element of Undue Enrichment

The main elements of undue enrichment are as follows −

The defendant has been enriched by the receipt of a chúng tôi defendant has been enriched by the receipt of a benefit. The retention of the enrichment be unjust. There is no defence or bar to the claim. It is unethical and illegal act in the eyes of society.

Provisions under the Indian Law

The basis for quasi-contractual responsibilities is the principle of undue enrichment. According to Lord Mansfield, the idea that justice and the law should work to prevent one person from gaining wealth at the expense of another. The type of liability that develops for a person who benefits from it is similar in some ways to tort liability and similar in some ways to contract law. As a result, it can be justified by an implicit contract or under natural justice and equity to avoid undue enrichment. The latter view was more appealing to Lord Mansfield.

Such circumstances are covered under the title “Of Certain Relations Resembling Those Created by Contract” in Chapter V of the Indian Contract Act. Five types of quasi-contractual responsibilities are set out in S. 68–72 −

Section 68: Claim for necessaries supplied to person incapable of contracting, or on his account

The present section is applicable to persons of unsound mind, minors, and others, if any, who are disqualified from contracting by any law to which they are subject.

Necessaries

This section is applicable only in cases where life’s necessities have been provided to such an incapable person. Necessaries, normally, include articles, which is required to maintain a particular person in the state, degree, and station in life in which he lives. It need to be determined with reference to the fortune and circumstances of that person.

Therefore, whenever a person who is unable to enter into a contract does so and enjoys the needs that result from that contract, they are obligated by law to return those benefits to the claimant. The provision of necessities of life and nothing else will prevent this clause from being applied.

Section 69: Reimbursement of person paying money due by another in payment of which he is interested

This section lays down a wider rule than appears to be supported by any English authority. The idea behind this provision is that if one person is obligated to make a payment and another person who is not obligated but has an interest in the payment being made and pays up to protect it is entitled to repayment from the person who was initially obligated to make the payment. The requirements for culpability under this clause might be summed up as follows

The plaintiff must be motivated to make the payment. Obviously, the plaintiff’s interest must be one that is legally discernible. It is sufficient that he really believes he has interests to safeguard.

It is essential that the plaintiff himself not be obligated to pay.

The defendant ought to have been required by the law to make the payment. When someone owes someone money only morally and not legally, they are not obligated to repay the person who fulfills their moral responsibility.

The plaintiff ought to have paid the other party instead of keeping the money for himself.

Therefore, the undue enrichment principle forbids the defendant from unfairly benefiting himself to the point where he would be obligated to reimburse the claimant for the sum that was paid on his behalf but not at his instruction.

Section 70: Obligation of person enjoying benefit of non-gratuitous act

Section 70 creates a liability to pay for the benefits of an act that the doer did not intend to do gratuitously, following the conditions

The person who did the act should have done it without any intention of doing it gratuitously. He should have contemplated being paid from the very beginning.

The person for whom the act is done is not bound to pay unless he has the choice to reject the services. The services so rendered should be without request.

The services should be lawfully rendered. Here, a point must be noted that some lawful relationship must exist between the person claiming for compensation and the person against whom it is claimed. Furthermore, it should arise by reason of the fact that what has been done by the former has been accepted and enjoyed by the latter.

Section 71: Finder of goods

The responsibilities of a finder of items are outlined in this section. In essence, it implies that if someone finds anything that belongs to someone else, they must care for it as the owner’s bailee under the law. In other words, to treat it as his own and give it back to its rightful owner upon request. When a person finds someone else’s possessions, the idea of undue enrichment is therefore applied.

Section 72: Liability of a person to whom money is paid, or thing delivered, by mistake or under coercion

If money is paid to or a thing is delivered to a person under coercion or mistake, he must repay or return it. Thus, if A and B jointly owe a sum of money to C, and A pays it, and thereafter, not knowing of A’s payment, B also pays the same amount to C, C must repay the amount to B.

Coercion

The Judicial Committee had established that the definition of “coercion” in Section 15 is not controlling and that the word is employed in this section in its wide and ordinary sense. As a result, when Z, who had obtained a decree against Y, obtained an attachment against W and took possession of his property to obtain satisfaction for the amount of the decree, and W paid the amount claimed under protest after being evicted from his property, W was held entitled to recover the amount as money paid under coercion in accordance with this section.

If a person accused of a non-compoundable crime is persuaded to pay money to the complainant in order to thwart the prosecution, he may be able to get that money back under this section.

Defenses of Undue Enrichment

In cases where a restitution ground has been established, relief will nonetheless be refused if a recognized defense or bar applies. If the claimant is estopped, the defendant cannot be put back in his prior position, or if public policy prohibits repayment, restitution will be refused. In the location where the benefit was given, it is also denied

As a valid gift. Pursuant to valid common law, equitable or statutory obligation owed by the claimant to the defendant. By the claimant while performing an obligation owed to a third party. In submission to an honest claim, under process of law or a compromise of a disputed claim. By the claimant acting “voluntarily” or “officiously”.

Conclusion

Undue enrichment is not based on a written agreement. When there is no written or verbal contract to back up their request for remedies, plaintiffs typically turn to the remedy of undue enrichment. In some situations, parties to a lawsuit urge a court to identify an implicit contract, or fake connection, hat was formed by the law to serve justice in a particular case.

In some other cases, undue enrichment is an appropriate remedy for parties who have made a legally binding agreement, but whose performance by one party goes beyond the specific terms of the contract. Therefore, endue enrichment is a versatile remedy that gives courts significant flexibility in distributing benefits and losses among the parties as equality, fairness, and justice require.

Q1. What is an example of undue enrichment?

Ans. A painter who paints someone’s home is a prime example of undue enrichment. The painter may walk outside and paint the defendant’s home, providing the defendant with a benefit in the form of fresh paint.

Q2. Who has the burden to prove undue enrichment?

Ans. In order to succeed on an undue enrichment claim, the plaintiff must demonstrate that the defendant unfairly benefited from the plaintiff’s loss. Therefore, the plaintiff has the burden of proof.

Q3. When a person can sue for undue enrichment?

Ans. In English law, a claim for undue enrichment must satisfy four requirements −