Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
98 views2 pages

Arrays

The document describes two programming assignments involving classes and arrays: 1. Create a Matrix class with overloaded constructors and a 2D array to store elements. Include functions to set elements, transpose the matrix, and print it. 2. Create a Polynomial class with an array of Term objects to store terms. Include a constructor, SetTerm function with validations, Sort function, and print function.

Uploaded by

srikannan_89
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views2 pages

Arrays

The document describes two programming assignments involving classes and arrays: 1. Create a Matrix class with overloaded constructors and a 2D array to store elements. Include functions to set elements, transpose the matrix, and print it. 2. Create a Polynomial class with an array of Term objects to store terms. Include a constructor, SetTerm function with validations, Sort function, and print function.

Uploaded by

srikannan_89
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Assignments

Concept: Overloaded constructors , Composition and Arrays


Objective: At the end of the assignments, participants will be able to create a class
• with more than one constructor,
• that has an object of another class as one of the members (composition)
• that uses Arrays

1. Create a class Matrix. Internal representation of this class will be a two dimensional array of
size 10 by 10. In addition, the class should have following data members and member functions:
Data members:
Int rows
Int columns
Member functions
Constructors
The default constructor
Matrix()
This should set each of the array element to zero.

Overloaded constructor
Matrix(int, int)
This constructor should call the default constructor first. It should then assign the value of first
parameter to rows, and the value of the second parameter to columns. You can assume that the
values of both the parameters will be less than or equal to 10.

Void SetElement(int r, int c, int value)


This function should set the array element at row r and column c to the value val. This
assignment should be done only if
• val is positive
• r and c are valid
else the element should be set to zero.

Matrix Transpose ()
This function should transpose the matrix. Transpose of a matrix is another matrix where the
elements in rows of the first matrix become elements of the corresponding columns in the new
matrix.

Provide a function to print a Matrix object.

2. Create a class Term. This class represents a term of a polynomial such as 2x4 where 2 is
coefficient and 4 is exponent of the term. There should be two data members; coefficient, and
exponent respectively representing coefficient and exponent of a polynomial term.

Create another class Polynomial. The internal representation of a polynomial is an array of


Terms. The size of this array should be defined with #define.

Provide a constructor for this class that will set all terms of a polynomial object as zero (coefficient
0, exponent 0).
Provide following functions:
SetTerm(int, int) – Setting a term of a polynomial object. Each successive call of this function
should set next term of the polynomial object. It should do the following validations.
• whether the exponent of the term being set is already used.
• whether the array size limit is exceeded.
• Whether the exponent is negative.
In all the cases it should not set the term and display an appropriate message.

Sort() – to arrange the terms in ascending order of exponents.

Provide a function to print a polynomial object

You might also like