Category: C++
C++ Program to Calculate Arithmetic Mean
Problem Write a program in C++ to calculate arithmetic mean for the numbers entered by the user. Solution We have a formula to find the arithmetic mean if there are n sets of numbers: am = (n1+n2+n3+…+nn)/n The letters am stand for arithmetic mean, whereas n1, n2, n3, and nn stand for first, second, third, and fourth numbers, respectively. Here’s a sample code snippet demonstrating…
C++ Program to Find if a Number is Odd or Even
Problem Write a program in C++ language to find if the given number is odd or even. Solution A number is even if it is a positive number and if it is fully divisible by 2. Here’s a sample code snippet demonstrating how to find out if the number is odd or even in C++. Output
Top XML Parsers for C++ Developers
Below are the list of some of the top XML parsers for C++ developers. Top XML Parsers for C++ Developers TiCPP It is another name for TinyXML++ and uses some of the powerful C++ features like templates etc. pugixml pugixml is one of the light weight C++ XML processing library which is portable and easy to use and integrate. RapidXML It is one of the…
C++ Program to Generate Random Numbers between 0 and 100
Problem Write a C++ Program to Generate Random Numbers between 0 and 100. Solution Below is a sample code snippet demonstrating how you can generate random numbers between 0 and 100 in C++. Output
C++ Program to find Square Root of a number
Problem Write a program in C++ to find the square root of a number in C++. Solution To find the square root of a number in C++, you can use the sqrt() function. The sqrt() function defined in the math.h header file can be used to calculate the square root in C++. This function takes a number as an argument and returns its square root….
C++ Program to Calculate Compound Interest
Problem Write a program in C++ programming language to Calculate Compound Interest. Solution Interest on interest is the process of adding interest to the principal amount of a loan or deposit. It is the outcome of reinvesting interest rather than paying it out, so that interest is received on the principle amount plus previously collected interest in the next period. Here’s a sample code snippet…
C++ Program to Find Quotient and Remainder
Problem Write a C++ Program to Find Quotient and Remainder. Solution This program asks the user to enter two integers (divisor and dividend) and computes the quotient and remainder. To compute the quotient and remainder, both the divisor and the dividend must be integers. Here’s a simple C++ program for calculating the quotient and remainder in the C++ programming language. Output
C++ Program to Calculate Multiplication of two Numbers
Problem Write a C++ Program to Multiply two Numbers. Solution The user is prompted to enter two numbers in this program. The product of those two numbers is then stored in a variable and shown on the screen. Here’s a sample code snippet demonstrating how to calculate Calculate Multiplication of two Numbers in C++. Output
C++ Program to add two integers
Problem Write a program in C++ to add two integers and display the result on the screen. C++ Program to add two integers Output Enter first number : 8 Enter second number : 2 8 + 2 = 10
C++ Program to Display ASCII Value of a Character
Problem Write a C++ Program to Display ASCII Value of a Character. Solution In C programming, a character variable stores an ASCII value (an integer between 0 and 127) rather than the character itself. For example, ASCII value of ‘B’ is 66. This means that if you assign ‘B’ to a character variable, 66, rather than ‘B,’ is stored in that variable. Here’s a sample…
C++ Program to Swap Two Numbers without using third variable
Problem Write a C++ Program to Swap Two Numbers without using third variable. Solution Below is sample source code in C++ to Swap Two Numbers without using third variable. Output Enter 1st number:Enter 2nd number:Before swapping, Numbers are:a = 2, b = 1 After swapping, Numbers are:a = 1, b = 2
C++ Program to display "Hello, World!"
Problem Write a program in C++ to display “Hello, World!” on the screen. C++ Program to display “Hello, World!” in Console Window. This is a simple C++ program that displays “Hello, World!” on the console window. This program provides a quick insight on to the syntax of the C++ language for the beginners. Output Hello, World! The C++ programs starts with the main() function. The…
C++ Program to Convert Days Into Years Weeks and Days
Problem Write a Program in C++ programming language to Convert Days Into Years Weeks and Days. Solution Here’s a sample code snippet showing how to Convert Days Into Years Weeks and Days in C++. Output
C++ Program to Find Cube of Number using macros
Problem Write a C++ program to Find Cube of Number using Macros. Solution Here’s a sample code snippet demonstrating how you can find the cube of a number in C++ using macros. Output
C++ Program to Find the Sum of First N Natural Numbers
Problem Write a program in C++ to find the sum of first “N” natural numbers and display it on the console. Solution Here’s a sample code snippet demonstrating how you display the sum of N natural numbers in C++. Output
C++ Program to Find Size of Int Float Double and Char Data types
Problem Write a C++ Program to Find Size of Int Float Double and Char data type. Solution The sizeof operator is used to determine the size of a variable Here’s the sample code snippet showing how to find the size of Int Float Double and Char data types in C++ programming language. Output Size of char: 1 byteSize of int: 4 bytesSize of float: 4 bytesSize…
C++ Program #1
What is the output of the following C++ program? Output Compiler Error in first line of main(), i.e., “Point p1;” Since you have a custom constructor, the compiler will not create a default constructor. If I remove the copy constructor from the Point class, the program works fine and prints the output.