title-img


Overload Operators C++

You are given a class - Complex. class Complex { public: int a,b; }; Operators are overloaded by means of operator functions, which are regular functions with special names. Their name begins with the operator keyword followed by the operator sign that is overloaded. The syntax is: type operator sign (parameters) { /*... body ...*/ } You need to overload operators + and << for the Complex class. The operator + should add complex numbers according to the rules of complex ad

View Solution →

Array Mathematics Python

Basic mathematical functions operate element-wise on arrays. They are available both as operator overloads and as functions in the NumPy module. import numpy a = numpy.array([1,2,3,4], float) b = numpy.array([5,6,7,8], float) print a + b #[ 6. 8. 10. 12.] print numpy.add(a, b) #[ 6. 8. 10. 12.] print a - b #[-4. -4. -4. -4.] print numpy.subtract(a, b) #[-4. -4. -4. -4.] print a * b #[ 5. 12.

View Solution →

Attending Workshops C++

A student signed up for n workshops and wants to attend the maximum number of workshops where no two workshops overlap. You must do the following: Implement 2 structures: 1. struct Workshop having the following members: The workshop's start time. The workshop's duration. The workshop's end time. 2 . struct Available_Workshops having the following members: An integer, n (the number of workshops the student signed up for). An array of type Work

View Solution →

Bit Array C++

You are given four integers: N, S , P , Q . You will use them in order to create the sequence a with the following pseudo-code. a[0] = S (modulo 2^31) for i = 1 to N-1 a[i] = a[i-1]*P+Q (modulo 2^31) Your task is to calculate the number of distinct integers in the sequence. a . Input Format Four space separated integers on a single line, N, S , P , and Q respectively. Output Format A single integer that denotes the number of distinct integers in the sequence a . Co

View Solution →

Polar Coordinates Python

Task: You are given a complex z. Your task is to convert it to polar coordinates. Input Format: A single line containing the complex number z. Note: complex() function can be used in python to convert the input as a complex number. Constraints: Given number is a valid complex number Output Format Output two lines: The first line should contain the value of r. The second line should contain the value of y.

View Solution →