You are required to create a class for dealing with complex numbers. In this particular
example we are only applying two arithmetic operations over complex number – addition
and subtraction. In complex numbers, we treat the real and imaginary part separately. You
need to define a constant char and assign it ‘i’, indicating the imaginary part. Also declare
two variables for denoting the real part and coefficient of the imaginary part. Define the
appropriate constructors, getters, setters and destructor as per the requirements.
You are required to create an object passing 2 arguments to its constructor, another
constant object with 2 arguments to its constructor. Add them both and store the resultant
object in a third instance by using the concept of copy constructor. Following are the
function prototypes,
Complex()
Complex(int, int)
Complex add(Complex)
void display()
void display() const
You are required to create a class by the name of ‘Matrix’. The matrix private domain must
contain a 2-Dimentional array of floats. The constructor should initialize a passed value to all the locations of the array being created and if the argument is missing, it should assign 0 by default to the entire array. Define appropriate functions for inserting data into the matrix and displaying the array in a matrix form. You need to define a function by the name of ‘dot’ that would take a matrix object as an argument and would return the matrix object (temporary) to where it was called from. From where it was called, there it should assign the returned object to a new matrix class instance.
Matrix obj3=obj1.dot(obj2);
Call the display function from the new instance to see the result of two matrices multiplied.
NOTE: Define a function ’float retreive(int, int)’ where if two indices are
passed to it, it must return the value located at those locations.
Create a class by the name of ‘Product’. Create the following private members
name(String), price(Int) and quantity(Int). Define a parameter-less and a
parameterized constructor. Define the following two member functions outside the class,
void getData()
static void counter()
static int countProduct()
The class would contain a static int ‘totalProduct’, having initial value equal to zero.
Each time an instance of the product class is created, the ‘counter()’ should be called.
The ‘counter()’ increments the static member by 1 value. Suppose I create 5 products,
when I execute the following code it should display 5.
Product::totalProducts;
Create a 'Circle' class with having a static data member name 'radius' and two pointer
data members name 'circumference' and 'area' as private. Allocate memory to the
two pointers in both parameter-less and parameterized constructors - parameterized
constructor must take a single float argument for radius. Define a deep copy constructor for
the class. Note that the constructor should assign data as well as calculate 'area' and
'circumference' based on the formulae. Two other functions with return type float
must return the value 'circumference' and 'area' are holding. Get rid of the
allocated space in destructor.
Write a program in C++ to find the largest and smallest of N numbers of any data type (use function overloading). The value of N is available only at the time of execution
If the number is only divisible by 3, print "Fizz"
If the number is only divisible by 5, print "Buzz"
If the number is divisible by both 3 and 5, print "FizzBuzz"
If nothing is true in the previous conditions, skip the number
Input two integers in one line. The first inputted integer will be the starting point, and the second one shall serve as the ending point.
Use the power of loops to loop through the starting point until the ending point (inclusive), and print out each number within the range with the corresponding format shown on the sample output. However, skip the printing of statement if the integer is divisible by 4. Tip: Utilize the continue keyword to complete the process
Print out the cube values of the numbers ranging from 1 to 20 (inclusive). However, if the number is divisible by either 3 or 5, do not include them in printing and proceed with the next numbers. Tip: When skipping through special values, make use of the keyword continue and put them inside a conditional statement.
Consider the abstract class declaration:
class aPolygon
{
protected:
long double * sides, // There are N sides with different lengths
* angles; // There are N angles with different sizes
long int no_of_sides; // The number of sides, N, of this polygon
public: aPolygon(long int _sides = 1);
/* It sets no_of_sides = _sides.*/
virtual void input () = 0; // input the derived polygon
virtual void display () = 0; // display the derived polygon
~aPolygon() {}
};
Write a complete C++ class implementation of the following derived class, aSquare, with the class interface::
class aSquare : public aPolygon
{
public:
aSquare(); /* It creates a square as a unit square */
~aSquare() {}
virtual void input(); /* It inputs the data for the square */
virtual void display(); /* It displays the square: angles, sides, perimeter and area */
long double perimeter(); /* It computes the perimeter of the square */
long double area(); /* It computes the area of the square: */
};
Writea c++program that would ask the user to enter their personal information: last name,first name, middle name, birthday, age, gender and permanent address