• Nie Znaleziono Wyników

Implement the following public methods of the structure

N/A
N/A
Protected

Academic year: 2021

Share "Implement the following public methods of the structure"

Copied!
1
0
0

Pełen tekst

(1)

1. Define the Fraction structure representing vulgar fractions. Implement the following public methods of the structure:

• the default constructor creating the fraction being the zero value,

• the constructor with two parameters for the nominator and the denominator of the fraction (the denominator should have a default value),

• the printing method,

• the comparison operators <, <=, >, >=, == and !=,

• the arithmetic operators +, - (unary and binary) , * and /,

• the method converting the fraction to a real value.

Write a program which tests all the structure capabilities.

2. Define and implement two structures – the Point and the Line being geometric structures in two-dimensional space. The structure Point should contain at least the following public methods:

• the default constructor assigning zero to all the coordinates of the point,

• the constructor with two parameters for the coordinates of the point,

• getX – returning the x-coordinate of the point,

• getY – returning the y-coordinate of the point,

• setX – setting the x-coordinate of the point,

• setY – setting the y-coordinate of the point,

• distance - computing the distance between this point and the second one given as the parameter.

The structure Line should contain at least the following public methods:

• the default constructor assigning zero to all the coefficients of the line,

• the constructor with two parameters for the directional (a) and the free coefficient (b) of the line in form of y=ax+b,

• the constructor with two points as the parameters,

• distance – computing the distance between the line and a point given as the parameter,

• isOnLine – checking wheter a point given as the parameter belongs to the line,

• orthogonalLine – returning a new line orthogonal to this line and containing a point given as the parameter.

Write the testing program which should create at least two points and one line given by the user and test all the capabilities of the structures.

3. Define the Matrix structure implementing a square matrix (2-dimensional array) of real numbers with the following public methods:

• the constructor with two parameters – the number of rows/colums and the value to be assigned to each cell of the matrix (0 by default),

• the method for reading from the standard input and filling the content of the matrix,

• the method for printing the content of the matrix,

• the arithmetic operators + and *.

Write a program which creates (after reading the value N being a positive integer) two NxN square matrices of real values. The program (using the methods provided) reads the values to be stored in the matrices, prints them, and then calculates and prints matrices beeing the sum and the product of the given ones.

Cytaty

Powiązane dokumenty

[r]

[r]

.], whose entries are almost all zero;... Find eigenvalues and eigenvectors

(Row go horizontal and columns go up and down.) We locate entries in a matrix by specifying its row and column entry1. In the next two probelms you will develop some of the

[r]

The factorization has been completed, but the factor U is exactly singular, and division by zero will occur if it is used to solve a system of equations... The leading dimensions

Marking, Points and Grades For the Reading Comprehension, Language Elements and Listening Comprehension parts of the examination, compare the learners’ answers with the answer

Marking, Points and Grades For the Reading Comprehension, Language Elements and Listening Comprehension parts of the examination, compare the learners’ answers with the answer key