Write the definition of the non parameterized constructor


Objective: Learn to define a class, its member functions, constructor, constructor overloading, constant member functions, and constant member of the class and how to use a reference as the function arguments.

1. Consider the definition of the following class:

class Point{
private:
 int x;
 int y;
public:
 Sample(); //Constructor 1
 Sample(int); //Constructor 2
 Sample(int, int); //Constructor 3
 void show() ;
 double calculateDistance();
};

i. Write the definition of the Non parameterized constructor (constructor1) so that the private member variables are initialized to 0.

ii. Write the definition of the parameterized constructor (constructor 2) so that the private member variable x is initialized according to the value of the parameter, and the private member variable y is initialized to 0.

iii. Write the definition of the parameterized constructor (constructors 3) so that the private member variables are initialized according to the values of the parameters.

iv. The show function is used to print the x and y value of an object.

v. The calculateDistance function is used to calculate the distance of the point from the origin.

2. Implement a class for stack of numbers using the array. Please note the operations defined for a Stack data structure are as follows:

a) Function name: push Return type: void

Purpose: It places an element in the Stack. Before place an element in the Stack you should check whether stack is full or not.

b) Function name: Pop

Return type: void

Purpose: It removes an element from the Stack. Before remove an element from the Stack you should check whether stack is empty or not.

c) Function name: isEmpty

Return type: boolean

Purpose: This function just check whether the stack is empty or not.

d) Function name: isFull

e) Return type: boolean

f) Purpose: This function just check whether the stack is full or not.

Write the main function to demonstrate all operations involving the Stack.

3. Create a class Student. Student class has the following attributes:

Student Name (character type pointer) : stRoll,
Student Roll (integer type) : stName,
Marks obtained by Student (integer type) :stMarks
and Student Year(character type pointer). :stYear

Initialize the attributes using the constructor (use the constructor overloading).

The non parameterized Constructor initialized the attributes with the following values:

Name and year is initialized with NULL. Roll and Marks is initialized by 0 and -1.

The parameterized Constructor initializes the attributes with the given value as arguments.The other functions are:

Function name: display
Return type: void.

Purpose: It displays the attributes of the object and each information is printed in the new line. The function declaration should assure that it does not change any attributes.

Function Name: displayRollName
Return type: Student

Purpose: It prints the roll and name of the student.

Function Name: find Max
Return type: Student

Purpose: It identifies the student who scored the highest marks.

You may add any other functions in your representation as required.

Create a Student Object using Non parameterized Constructor.

Create the two student using parameterized Constructor and then print the student name and roll number who scored highest marks 

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Write the definition of the non parameterized constructor
Reference No:- TGS01286608

Now Priced at $20 (50% Discount)

Recommended (96%)

Rated (4.8/5)