# Implement Person class with following operations
* Default constructor
* Parameterized Constructor
* Member function to compute age of the person as completed years by 1st July 2020.
* Let’s call the function name as computeAge
* Hint:-If month in DOB is between January – June consider completed years by 2020, else consider completed years by 2019
* Ex: if person is born on in May 1995 consider the age of 25 or if born in September 1995 consider the age of 24
* Member function to check if eligible for driving license or not, with consideration of minimum 18 years completion for the eligibility , let’s call function name as isEligibe
* Member finction to compute the insurance amount as per formula “5000 + (age/10) * 1000”, let’s call the function name as computeInsurance
* display function (part of skeleton) don’t change
* Don’t add any other cin,cout statement which will impact test cases.
* Also don’t change main function, focus class implementation only
Sample Input-1:-
1001
Richard
03 1992
Expected output:-
28
yes
1001,Richard,28
7000
Sample Input-2:-
1002
Stevens
10 1980
Expected output:-
39
yes
1002,Stevens,39
8000
Here is the code:
#include<iostream>
#include<string>
// Note: Don’t add any other cin,cout statement which will impact test cases.
using namespace std;
classPerson
{
//TODO: declare data members – uid, name, year of birth, gender
int uid;
string name;
int mm;
int yy;
int age=0;
public:
//TODO: default constructor
//TODO: parameterized constructor
Person(int a, string b, int c, int d){
uid = a;
name = b;
mm = c;
yy = d;
}
//TODO: member function to compute age of the person, let’s call it as computeAge
int computeAge(){
if(mm<=6){
age = 2020-yy;
return age;
}
else{
age = 2020-yy-1;
return age;
}
}
//TODO: member function to check if qualified for driving license as per criteria
int isEligible(){
if(age>=18){
return 1;
}
else
{
return 0;
}
}
//TODO: member function to compute insurance amount as per the formula
int computeInsurance(){
return (5000 + (age/10)*1000);
}
// Do not modify this function
void display() {
std::cout << uid << “,” << name << “,” << computeAge() << “\n”;
}
};
// Also don’t change main function, focus class implementation only
int main() {
int res;
int uid;
std::string name;
int mm;
int yy;
std::cin >> uid >> name >> mm >> yy;
Person p1(uid,name,mm,yy);
res = p1.computeAge();
std::cout << res << “\n”;
if(p1.isEligible())
std::cout << “yes\n”;
else
std::cout << “no\n”;
std::cout << p1.computeInsurance() << “\n”;
p1.display();
return 0;
}