Create a class Student with data members age and marks, both of type integer. Provide a parameterized constructor and a set member function to set the data members. The age should be a positive number between 15 and 40 while the marks should be between 0 and 100. Create a class InvalidRange as exception handler of the Student class. Add two private data members (a string and an integer) to theclass InvalidRange. Provide appropriate constructor and get methods for the data members. The string should store the name of the function throwing the exception while the integer should store the invalid value the user has supplied. The student class should throw an exception if any of its member functions attempts to assign an invalid value to the data members. In the main program, create objects of class student, assign valid/invalid values to the data members and catch the exceptions accordingly. Extend the program to have two separate classes for exception handling, InvalidMarks and InvalidAge.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
i will upvotes unique answer plzz
(Use language OOP in c++)
Create a class Student with data members age and marks, both of type integer. Provide a parameterized constructor and a set member function to set the data members. The age should be a positive number between 15 and 40 while the marks should be between 0 and 100. Create a class InvalidRange as exception handler of the Student class. Add two private data members (a string and an integer) to theclass InvalidRange. Provide appropriate constructor and get methods for the data members.
The string should store the name of the function throwing the exception while the integer should store the invalid value the user has supplied. The student class should throw an exception if any of its member functions attempts to assign an invalid value to the data members.
In the main
Extend the program to have two separate classes for exception handling, InvalidMarks and InvalidAge.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images