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

Programming PDF 1

The document outlines practice problems related to object-oriented programming, focusing on class definitions and their methods. It includes specifications for four classes: Composite for generating composite numbers, SumSeries for calculating a mathematical series, DayNum for determining the day number of a date, and Trans for finding the transpose of a matrix. Each class description includes data members, constructors, and methods, along with instructions to define a main function for object creation and method invocation.

Uploaded by

Tazar Aftab
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Programming PDF 1

The document outlines practice problems related to object-oriented programming, focusing on class definitions and their methods. It includes specifications for four classes: Composite for generating composite numbers, SumSeries for calculating a mathematical series, DayNum for determining the day number of a date, and Trans for finding the transpose of a matrix. Each class description includes data members, constructors, and methods, along with instructions to define a main function for object creation and method invocation.

Uploaded by

Tazar Aftab
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CHAPTER PRACTICE PROBLEMS

Objects, Classes, Functions (Chap 3, 7, 9,10)

Question 1
A class Composite has been defined to fill an array of order m x n (where the maximum value
of both m and n is 20) with the first m x n composite numbers in column wise. Some of the
members of the class are:
Class name Composite
Data members/instance variables:
arr[ ][ ] stores the composite numbers column wise
m,n integer to store number of rows, number of columns
Member function/methods:
Composite (int mm, int nn) to initialize the size of the matrix m=mm and n=nn
int isComposite (int p) returns 1 if p is composite, otherwise returns 0
void fill( ) to fill the array with the first [m x n] composite
numbers in column wise
void display( ) to display the array in matrix form.

Specify the class Composite giving details of the constructor and methods. Also define the
main ( ) function to create an object and call the methods accordingly. [ISC SQP 2020]

Question 2
A class SumSeries has been defined to find the sum of the following series:

x2 x3 x4 x(n + 1)
Sum = _ __ + __ _ __ + ........__
1! 2! 3! n!

Some of the other members of the class are:


Class name SumSeries
Data members/instance variables:
x to store an integer.
n to store number of terms
sum double variable to the sum of the series

Member functions/methods:
SumSeries (int xx, int nn) constructor to assign x = xx and n = nn
double fact(int m) returns m!
void calculate( ) calculates the sum of the series
void display( ) displays the sum of the series

Specify the class SumSeries giving the details of the constructor and all the member functions.
Define the main ( ) function to create an object and call the function accordingly to enable the
task.

CPP XII – SR Page 1


Question 3
A class DayNum has been defined to find the day number from a give date of a particular year.
For e.g. if date is March 6, 2019, then the corresponding day number would be 65 (31+28+6).
Some of the other members of the class are:
Class name DayNum
Data members/instance variables:
d, m, y integers to store the day, month and year of the date
dnum stores the day number
Member functions/methods:
DayNum (int nd, int nm, int ny) constructor to initialize the day, month and year
int isLeap( ) returns 1, if year is leap otherwise returns 0
void dateToDay( ) converts the date to its corresponding day number in
dnum

void display( ) displays the date and day number

Specify the class DayNum giving details of the constructors and methods. Define the main ( )
function also.

Question 4
A class Trans is defined to find the transpose of a square matrix. A transpose of a matrix is
obtained by interchanging the elements of the rows and columns. For e.g. if size of the matrix =
3, then

ORIGINAL TRANSPOSE
11 5 7 11 8 1
8 13 9 5 13 6
1 6 20 7 9 20
Some of the members of the class are given below:

Class name Trans


Data members/instance variables:
arr[ ][ ] to store integers in the matrix
m integer to store the size of the matrix
Member function/methods:
Trans (int mm) constructor to initialize the size of the array
void fillarray( ) to enter integer elements in the matrix
void transpose( ) to create the transpose of the given matrix
void display( ) displays the original matrix and the transposed
matrix by invoking the method transpose( )

Specify the class Trans giving details of the constructors and methods. Define the main ( )
function to create an object and call the functions accordingly to enable the task. [ISC 2K23]

CPP XII – SR Page 2

You might also like