Author: learncpponline

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++. #include<iostream.h> #include #include void main(){ int day; clrscr(); cout << “Enter the day number: “; cin >> day; switch(day){ case 1: cout << “nIts Sunday”; break; case 2: cout <<...

this pointer in Cpp 1

this pointer in C++

C++ uses a unique keyword called this to represent an object that invokes a member function. this pointer in C++ is a pointer that points to the object for which this function was called. For example, the function call: A.max() will set the pointer this to the address of the object A. The starting address is the same as the address of the first variable in the class structure. This unique pointer is automatically passed to a member function when it is called. The pointer this acts as an implicit argument to all the member functions. Consider the following simple...

Program in Cpp to find sum of first n natural numbers 1

Program in C++ to find sum of first “n” natural numbers

The below program will accept the number “n” from the user and calculates the sum of first “n” natural numbers. For example, if the input provided by the user is 5 then it will calculate the sum of first 5 natural numbers i.e., 1+2+3+4+5 /* Program Name: Program in C++ to find sum of first “n” natural numbers Author: LearnCPPOnline.com */ #include #include “conio.h” using namespace std; void main() { int sum, digit, n; sum = 0; digit = 1; cout << “Enter a number n: “; cin >> n; while(digit <= n) { sum = sum + digit; digit++;...

Program in cpp to display the name of the day in a week 1

Program in C++ to display the name of the day in a week

Program in C++ to display the name of the day in a week, depending upon the number entered through the keyboard. The program will accept integer value between 1 and 7. Depending on the number entered, the program will display the name of the day as follows: 1 => “Monday” 2 => “Tuesday” 3 => “Wednesday” 4 => “Thursday” 5 => “Friday” 6 => “Saturday” 7 => “Sunday” /* Program Name: Program in C++ to display the name of the day in a week, depending upon the numberentered through the keyboard Author: LearnCPPOnline.com */ #include <iostream> #include “conio.h” using namespace...