title-img


Structs C++

struct is a way to combine multiple fields to represent a composite data structure, which further lays the foundation for Object Oriented Programming. For example, we can store details related to a student in a struct consisting of his age (int), first_name (string), last_name (string) and standard (int). struct can be represented as struct NewType { type1 value1; type2 value2; . . . typeN valueN; }; You have to create a struct, named Student, representing

View Solution →

Class C++

Classes in C++ are user defined types declared with keyword class that has data and functions . Although classes and structures have the same type of functionality, there are some basic differences. The data members of a class are private by default and the members of a structure are public by default. Along with storing multiple data in a common block, it also assigns some functions (known as methods) to manipulate/access them. It serves as the building block of Object Oriented Programming.

View Solution →

Classes and Objects C++

A class defines a blueprint for an object. We use the same syntax to declare objects of a class as we use to declare variables of other basic types. For example: Box box1; // Declares variable box1 of type Box Box box2; // Declare variable box2 of type Box Kristen is a contender for valedictorian of her high school. She wants to know how many students (if any) have scored higher than her in the 5 exams given during this semester. Create a class named Student with the

View Solution →

Box It! C++

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 the above, the class should h

View Solution →

Inherited Code C++

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 editor. Complete the code so that, when an exception is thrown, it prints Too short: n (where n is the length of the given username). Input Format The first line

View Solution →