Learn C++ Online

Interested in learning C Programming? Click here...



Introduction to Inheritance 0

Introduction to Inheritance in C++

Let me introduce you to the concept of Inheritance in C++. Reusability is yet another important feature of C++. It is always nice if we could reuse something that already exists rather than trying to create the same all over again. It would not only save the time and money but also reduce frustration and increase readability. For instance, the reuse of a class that has already been tested, debugged and used many time can save us the effort of developing and testing the same again. Fortunately, C++ strongly supports the concept of reusability.The C++ classes can be reused in...

sizeof operator in cpp 0

sizeof operator in C++

sizeof operator in C++ is an unary operator which can be used to find the size of the data-type or expression or a variable. It returns the size of the memory allocated (in Bytes) by the compiler. Lets say, we want to find the size of the memory allocated to the data-type int. We can find it by using sizeof operator as shown in the below code:

Output:

As you can see, the above code calculated the size of int data type and displayed the result in C++.

Cpp Program 0

C++ program using two constructor to calculate minutes and seconds with hour as input from user

Write a class with name Time. Make a constructor which calculates the given time in minutes {if input time is 1hr, then the constructor should return 60minutes. }. Make another constructor which calculates the time in seconds. { if the input time is 1hr, then the constructor should return 60*60=3600 seconds}. Display the contents of both the constructors

Output

Program-in-cpp-to-find-weekday-based-on-weekday-number 0

Program in C++ to find weekday based on weekday number

The below program in C++ will find out weekday based on the weekday number input. We will be following the below logic. 1 -> Sunday 2 -> Monday 3 -> Tuesday 4 -> Wednesday 5 -> Thursday 6 -> Friday 7 -> Saturday Here we are accepting the week day number as input from the user and use switch statement to display the weekday. Below is the program in C++.

Output