[Solved] CSE241 PS 5

$25

File Name: CSE241_PS_5.zip
File Size: 103.62 KB

SKU: [Solved] CSE241 PS 5 Category: Tag:
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 integers 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 objects 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.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CSE241 PS 5
$25