Code:
#include<iostream>
using namespace std;
class SpecialArray
{
public:
int *arr;
int size;
SpecialArray(int n)
{
size=n;
arr=new int[size];
}
void setArray()//sets array
{
int i;
cout<<"enter array's
contents:"<<endl;
for(i=0;i<size;i++)
{
cin>>arr[i];
}
}
bool operator < (const SpecialArray& s)
const
{
if(size<s.size) return true;//if
size is less than other array return true
int i, asum=0, bsum=0;
for(i=0;i<size;i++)//calculate
sum of two arrays
{
asum+=arr[i];
}
for(i=0;i<s.size;i++)
{
bsum+=s.arr[i];
}
if(asum<bsum) return true;
return false;
}
bool operator >(const SpecialArray& s)
const
{
if(size>s.size) return
true;
int i, asum=0, bsum=0;
for(i=0;i<size;i++)
{
asum+=arr[i];
}
for(i=0;i<s.size;i++)
{
bsum+=s.arr[i];
}
if(asum>bsum) return true;
return false;
}
bool operator ==(const SpecialArray& s)
const
{
if(size!=s.size) return false;//if
sizes arent equal
int i, asum=0, bsum=0;
for(i=0;i<size;i++)
{
asum+=arr[i];
}
for(i=0;i<s.size;i++)
{
bsum+=s.arr[i];
}
if(asum==bsum) return true;//if
sums are equal
return false;
}
};
ostream & operator << (ostream &out, const
SpecialArray &s)
{
int i;
for(i=0;i<s.size;i++)
{
out<<s.arr[i]<<"
";
}
}
int main()
{
SpecialArray s1(3),s2(5);
s1.setArray();s2.setArray();
if(s1<s2)
{
cout<<"s1 is less than
s2"<<endl;
}
if(s1>s2)
{
cout<<"s1 is greater than
s2"<<endl;
}
if(s1==s2)
{
cout<<"s1 is less than
s2"<<endl;
}
cout << s2;
return 0;
}
Output:

Programming Question 4: Operator Overloading [20 marks] The class SpecialArray represents an arra...
How do i Overload the & operator to concatenate two arrays?, so elements from both arrays will be seen Below is code i have so far. everything works except the operator overload of &. The & operator only works when both array are equal, first array smaller then second, fails when first array is the largest. class smartArray{ public: int *elements; // dynamic array, memory is allocated in the constructor. Use *this to access size member. int length(); // returns...
Project 1 - Operator Overloading (FlashDrive 2.0) In C++, many of the keyboard symbols that are used between two variables can be given a new meaning. This feature is called operator overloading and it is one of the most popular C++ features. Any class can choose to provide a new meaning to a keyboard symbol. Not every keyboard letter is re-definable in this way, but many of the ones we have encountered so far are like +, -, *, /,...
C++ NEED AS SOON AS POSSIBLE! BigInt class is used for the mathematical operations that involve very big integer calculations that are outside the limit of all available primitive data types. For example, factorial of 100 contains 158 digits in it so we can’t store it in any primitive data type available. We can store as large Integer as we want in it. Your goal is to overload the operators for a generic “BigInt” class. You will need to write...
This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...
C++
myStack.lh stackADT.h Instructions main.cpp 1 #include«iostream» 2 #include<stdlib.h> 3 #include«conio.h> 4 #include«ostream» 5 using namespace std; 6 const int SIZE-5; //Stack size 7 //class declaration 8 class stack Instructions Two stacks of the same type are the same if they have the same number of elements and their elements at the corresponding positions are the same Overload the relational operatorfor the class stackType that returns true if two stacks of the same type are the same; it returns false...
Start by using the starter code provided for the Line class. It implements operator overloading so you can use cin/cout with line objects. A line will be made up of two points. Create an object to implement a “line” class which allows the programmer to store a line. This class must use the “point” class developed in Part B. The object should have two constructors, appropriate set/get functions, and overloaded I/O (cin/cout) functions. It should include functions the return the...
The WideArray class implements a special array type for which each element consists of two 64-bit (long) quantities. That is, the first element of a WideArray is the first two elements of the underlying long array, the second element of the WideArrayconsists of the third and fourth words of the underlying array, etc. class WideArray { public: WideArray(int n) { m_data = new long[2*n] ; m_size = n ; } // Other class methods class waIterator { public: waIterator(long *ptr...
Given two complex numbers, find the sum of the complex numbers using operator overloading. Write an operator overloading function ProblemSolution operator + (ProblemSolution const &P) which adds two ProblemSolution objects and returns a new ProblemSolution object. Input 12 -10 -34 38 where, Each row is a complex number. First element is real part and the second element is imaginary part of a complex number. Output -22 28 Two complex numbers are 12-10i and -34+38i. Sum of complex numbers are =...
C++ Class and Operator Overloading part 1 The source file contains a C++ program that declares and initializes an array of Circles. The program is using a for loop statement to find the largest circle in the array and display it on the output screen. However, the program is currently not working. The problem is the program uses logical operator ' > ' for comparison of circles and it is not working unless we overload such operator for the class...
Create the abstract data type IntSet used to implement a mathematical set of non-negative integers (includes zero). Each object of class IntSet can keep track of whether integers are in the set or not. Implement as follows. A set is to be represented internally as a bool array containing true and false. For example, if you call the array set, then set[num] is true if the integer num is in the set, false if num is not in the set....