When to Write Your Own Assignment Operator in C++ Programming

Arnab Chakraborty
Updated on 18-Dec-2019 10:12:49

260 Views

Here we will see when we need to create own assignment operator in C++. If a class do not have any pointers, then we do not need to create assignment operator and copy constructor. C++ compiler creates copy constructor and assignment operator for each class. If the operators are not sufficient, then we have to create our own assignment operator.Example#include using namespace std; class MyClass { //no user defined assignment operator or copy constructor is present    int *ptr;    public:       MyClass (int x = 0) {          ptr = new int(x);       }       void setValue (int x) {          *ptr = x;       }       void print() {          cout

Find Maximum Number of Elements with Absolute Difference ≤ 1 in C++

Arnab Chakraborty
Updated on 18-Dec-2019 10:11:28

377 Views

Suppose we have an array of n elements. We have to find the maximum number of elements to select from the array, such that the absolute difference between any two of the chosen elements is less than or equal to 1. So if the array is like [2, 2, 3, 4, 5], then the element will be 3, so the sequence with maximum count is 2, 2, 3.The absolute difference of 0 and 1 means, that the number can be of type x and x + 1. So the idea is to store the frequencies of array elements. So if ... Read More

Sort in C++ Standard Template Library (STL)

Arnab Chakraborty
Updated on 18-Dec-2019 10:09:23

732 Views

Here we will see how to use the sort() function of C++ STL to sort an array So if the array is like A = [52, 14, 85, 63, 99, 54, 21], then the output will be [14 21 52 54 63 85 99]. To sort we will use the sort() function, that is present in the header file . The code is like below −Example Live Demo#include #include using namespace std; int main() {    int arr[] = {52, 14, 85, 63, 99, 54, 21};    int n = sizeof(arr) / sizeof(arr[0]);    cout

Find Maximum in a Stack in O(1) Time and O(1) Extra Space in C++

Arnab Chakraborty
Updated on 18-Dec-2019 10:07:51

646 Views

Suppose we want to make a stack that can store the maximum element in the stack. And we can get it in O(1) time. The constraint is that, it should use O(1) extra space.We can make one user-defined stack, that will store the max value, when one operation is performed, like pop or peek, then the max will be returned. For peek operation, return the maximum of stack top and the max element, for pop operation, when the top element is larger, then print it and update max as 2*max – top_element. otherwise return top_element. For push operation update the ... Read More

Use jQuery hasAttribute Method to Check for Element Attributes

Amit D
Updated on 18-Dec-2019 10:07:36

3K+ Views

Use jQuery hasAttribute() method to see if there is an attribute for an element.ExampleYou can try to run the following code to learn how to use hasAttribute() method:Live Demo                          $(document).ready(function(){            $('button').on('click', function() {              if (this.hasAttribute("style")) {                alert('True')              } else {                alert('False')              }                         })          });                      Check for attribute in the button element             Button                   Button 2          

Perform Null Check Using HANA SQL Script

Smita Kapse
Updated on 18-Dec-2019 10:06:46

4K+ Views

You can go for using either NULLIF or COALESCE function to serve your requirement.NULLIF (expression, expression"): This function will return the same type whatever is specified as the first expression.Basically, NULLIF returnsThe first expression if the two expressions are not equal.NULL of type of first expressions if the expressions are equalThe other function available is COALESCE which basically checks if the first Value provided is NULL then it will return the second value.Examplec = COALESCE(b , a)If b is null then the function will return an otherwise b. So If you need to put a null check and use some ... Read More

Complex Numbers in C++ Programming

Arnab Chakraborty
Updated on 18-Dec-2019 10:06:32

1K+ Views

In this section we will see how to create and use complex numbers in C++. We can create complex number class in C++, that can hold the real and imaginary part of the complex number as member elements. There will be some member functions that are used to handle this class.In this example we are creating one complex type class, a function to display the complex number into correct format. Two additional methods to add and subtract two complex numbers etc.Example Live Demo#include using namespace std; class complex{    int real, img;    public:       complex(){       ... Read More

Delete Duplicate Alphanumeric Entries from Column Data in SQL

Nitya Raut
Updated on 18-Dec-2019 10:05:14

204 Views

You can opt for using regular expressions to remove the duplicate numbers from column c or any other intended column.ExampleSELECT REPLACE_REGEXPR ('([A-Za-z0-9])\1+' in 'BB11222343CC'    WITH '\1'    OCCURRENCE ALL) FROM OutputB12343C

Issue Regarding JCo SAP Server Out of Network

Jennifer Nicholas
Updated on 18-Dec-2019 10:03:48

239 Views

You need to perform the below actions when you are stopping the JCO server instanceDelete all the references of your server from ServerDataEventListener instance. If you need to use the reference, then you can use registered ServerDataProvider object to fetch reference of ServerDataEventListener instance.Delete all the references of your destination from DestinationDataEventListener instance. If you need to use the reference, then you can use registered DestinationDataProvider object to fetch the DestinationDataEventListener instance.

Refer and Import SAP UI Core.js in SAPUI5 Project

Vrundesha Joshi
Updated on 18-Dec-2019 10:03:04

441 Views

The SAPUI5 library files are a part of Eclipse SAPUI5 plug-in.If you are running the app by using the Web App preview on the startup page ( Go to Run As -> select “Web APP Preview”), then eclipse starts a local HTTP server for development which serves at “/resources” the library.Till the preview window is open, you can go ahead and use the URL in any browser of your choice to debug the application.

Advertisements