Category: Programs in C++
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 #include<iostream.h> #include<conio.h> class Time { public: Time(int); Time(float); }; Time::Time(int b) { cout << “Time in seconds: ” << b*60*60 << “n”; } Time::Time(float b) { cout << “Time in Minutes: ” << int(b*60) << “n”; } void main() { clrscr(); int...
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 <<...
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 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...