Answer to Question #243328 in C++ for vishal

Question #243328

Write a C++ program to check the duplicate mobile number by throwing a custom exception.

The class named ContactDetail with the following private member variables

Data typeVariable namestringmobilestringalternateMobilestringemail

In ContactDetail class include the following member function

Member FunctionDescriptionvoid display()  This function is used to display the contact details

 Create a class named ContactDetailBO with the following member function

Method nameDescriptionbool validate(ContactDetail cd) This method is used to validate whether the mobile number and alternate mobile number are not the same. If both are the same, then it throws DuplicateMobileNumber Exception. Otherwise, return true to print the details.Class named DuplicateMobileNumberException thatextends exception class and create

a method to return the following message "DuplicateMobileNumberException".





1
Expert's answer
2021-09-28T05:39:14-0400
#include <iostream>

class ContactDetail {
private:
    std::string mobileNumber;
    std::string alterMobileNumber;
    std::string email;
public:
    ContactDetail() {
    }
    ContactDetail(std::string mobileNumber, std::string alterMobileNumber, std::string email) {
        this->mobileNumber = mobileNumber;
        this->alterMobileNumber = alterMobileNumber;
        this->email = email;
    }
    void display() {
        std::cout << "mobile number:" << this->mobileNumber << std::endl;
        std::cout << "alternative mobile number:" << this->alterMobileNumber << std::endl;
        std::cout << "email:" << this->email << std::endl;
    }
    std::string getMobileNumber() {
        return this->mobileNumber;
    }
    std::string getAlternativeMobileNumber() {
        return this->alterMobileNumber;
    }
};

class ContactDetailBO : public ContactDetail {
public:
    bool validate(ContactDetail contactDetail) {
        if (contactDetail.getMobileNumber() == contactDetail.getAlternativeMobileNumber())
            throw "DuplicateMobileNumberException";
        else return true;
    }
};

class DuplicateMobileNumberException : public std::exception {
public:
    const char * what () const throw () {
        return "DuplicateMobileNumberException";
    }
};

int main() {

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS