Category: Programs in C++

Interested in learning C Programming? Click here...


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


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

Output

Note: The above program is written and tested using Microsoft Visual Studio 2008

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”

Output:

Note: The above program is written and tested using Microsoft Visual Studio 2008