HackerRank Cpp

Vector-Sort in C++ – Hacker Rank Solution

Problem You are given N integers. Sort the N integers and print the sorted order.Store the N integers in a vector. Vectors are sequence containers representing arrays that can change in size. Declaration : vector<int>v; (creates an empty vector of integers) Size : int size=v.size(); Pushing an integer into a vector : v.push_back(x);(where x is an integer.The size increases by 1 …

Vector-Sort in C++ – Hacker Rank Solution Read More »

Abstract Classes – Polymorphism in C++ – Hacker Rank Solution

Problem Abstract base classes in C++ can only be used as base classes. Thus, they are allowed to have virtual member functions without definitions.A cache is a component that stores data so future requests for that data can be served faster. The data stored in a cache might be the results of an earlier computation, …

Abstract Classes – Polymorphism in C++ – Hacker Rank Solution Read More »

Virtual Functions in C++ – Hacker Rank Solution

Problem This problem is to get you familiar with virtual functions. Create three classes Person, Professor and Student. The class Person should have data members name and age. The classes Professor and Student should inherit from the class Person.The class Professor should have two integer members: publications and cur_id. There will be two member functions: …

Virtual Functions in C++ – Hacker Rank Solution Read More »

Exceptional Server in C++ – Hacker Rank Solution

Problem Your friend set up a small computational server that performs complex calculations.It has a function that takes 2 large numbers as its input and returns a numeric result. Unfortunately, there are various exceptions that may occur during execution. Complete the code in your editor so that it prints appropriate error messages, should anything go wrong. The …

Exceptional Server in C++ – Hacker Rank Solution Read More »

Inherited Code in C++ – Hacker Rank Solution

Problem You inherited a piece of code that performs username validation for your company’s website. The existing function works reasonably well, but it throws an exception when the username is too short. Upon review, you realize that nobody ever defined the exception. The inherited code is provided for you in the locked section of your …

Inherited Code in C++ – Hacker Rank Solution Read More »

Box it! – Hacker Rank Solution

Problem Design a class named Box whose dimensions are integers and private to the class. The dimensions are labelled: length l, breadth b, and height h.The default constructor of the class should initialize l, b, and h to 0.The parameterized constructor Box(int length, int breadth, int height) should initialize Box’s l, b and h to length, breadth and height.The copy constructor Box (Box B) should set l, b and h to B‘s l, b and h, respectively. Apart from …

Box it! – Hacker Rank Solution Read More »