[SOLVED] CSE241 PS 5

30.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon ps-5-bvgg5z.zip (311.3 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
5/5 - (1 vote)

1)

Write the definition for a class named Vector2D that stores information about a two-dimensional vector. The class should have functions to get and set the x and y components, where x and y are integers. Next, overload the * operator so that it returns the dot product of two vectors. The dot product of two-dimensional vectors A and B is equal to

 

(A x * B x ) + (A y * B y ).

Finally, write a main subroutine that tests the * operation.

 

2)

Define a class named MyInteger that stores an integer and has functions to get and set the integer’s value. Then, overload the [] operator so that the index returns the digit in position i , where i = 0 is the least-significant digit. If no such digit exists then –1 should be returned.

For example, if x is of type MyInteger and is set to 418, then x [0] should return 8, x [1] should return 1, x [2] should return 4, and x [3] should return –1.

 

3)

Define a class named PrimeNumber that stores a prime number. The default constructor should set the prime number to 1. Add another constructor that allows the caller to set the prime number. Also, add a function to get the prime number. Finally, overload the prefix and postfix ++ and — operators so they return a PrimeNumber object that is the next largest prime number (for ++) and the next smallest prime number (for –). For example, if the object’s prime number is set to 13, then invoking ++ should return a PrimeNumber object whose prime number is set to 17. Create an appropriate test program for the class.

 

  • ps-5-bvgg5z.zip