C++ Programming Tutorial

C++ for Beginners: C++ Program to Store and Display Information Using Structure

Hits: 35 (C++ programming Example for Beginners) C++ Program to Store and Display Information Using Structure This program stores the information (name, roll and marks) of 10 students using structures. In this program, a structure, student is created. This structure has three members: name (string), roll (integer) and marks (float). Then, we created a structure array of size 10 to store information of …

C++ for Beginners: C++ Program to Calculate Difference Between Two Time Period

Hits: 23 (C++ programming Example for Beginners) C++ Program to Calculate Difference Between Two Time Period Example: Program to Time Difference // Computes time difference of two time period // Time periods are entered by the user #include <iostream> using namespace std; struct TIME { int seconds; int minutes; int hours; }; void computeTimeDifference(struct TIME, …

C++ for Beginners: C++ Program to Add Two Distances

Hits: 5 (C++ programming Example for Beginners) C++ Program to Add Two Distances (in inch-feet) System Using Structures This program takes two distances (in inch-feet system), adds them and displays the result on the screen. Example: Add Distances Using Structures #include <iostream> using namespace std; struct Distance{ int feet; float inch; }d1 , d2, sum; …

C++ for Beginners: C++ Program to Store Information of a Student in a Structure

Hits: 45 (C++ programming Example for Beginners) C++ Program to Store Information of a Student in a Structure This program stores the information (name, roll and marks entered by the user) of a student in a structure and displays it on the screen. In this program, a structure(student) is created which contains name, roll and …

C++ for Beginners: C++ Program to Copy Strings

Hits: 7 (C++ programming Example for Beginners) C++ Program to Copy Strings In this example, you will learn to copy strings (both string objects and C-style strings). You can simply copy string objects in C++ using = assignment operator. Example 1: Copy String Object #include <iostream> using namespace std; int main(){ string s1, s2; cout << “Enter …

C++ for Beginners: C++ Program to Concatenate Two Strings

Hits: 6 (C++ programming Example for Beginners) C++ Program to Concatenate Two Strings In this example, you will learn to concatenate (join) two strings (both string objects and C-style strings). You can concatenate two string objects in C++ using + operator. Example 1: Concatenate String Objects #include <iostream> using namespace std; int main(){ string s1, s2, result; …

C++ for Beginners: C++ Program to Find the Length of a String

Hits: 7 (C++ programming Example for Beginners) C++ Program to Find the Length of a String In this example, you will learn to compute the length (size) of a string (both string objects and C-style strings). You can get the length of a string object by using a size() function or a length() function. The size() and length() functions are just synonyms and …

C++ for Beginners: C++ Program to Find the Number of Vowels, Consonants, Digits and White Spaces in a String

Hits: 12 (C++ programming Example for Beginners) C++ Program to Find the Number of Vowels, Consonants, Digits and White Spaces in a String Example 1: From a C-style string This program takes a C-style string from the user and calculates the number of vowels, consonants, digits and white-spaces. #include <iostream> using namespace std; int main(){ …

C++ for Beginners: C++ Program to Swap Numbers in Cyclic Order Using Call by Reference

Hits: 21 (C++ programming Example for Beginners) C++ Program to Swap Numbers in Cyclic Order Using Call by Reference This program takes three integers from the user and swaps them in cyclic order using pointers. Three variables entered by the user are stored in variables a, b and c respectively. Then, these variables are passed to the function cyclicSwap(). Instead of …

C++ for Beginners: C++ Program to Find Transpose of a Matrix

Hits: 7 (C++ programming Example for Beginners) C++ Program to Find Transpose of a Matrix This program takes a matrix of order r*c from the user and computes the transpose of the matrix.   In this program, user is asked to entered the number of rows and columns. The value of rows and columns should be less than 10 …

C++ for Beginners: C++ Program to Add Two Matrix Using Multi-dimensional Arrays

Hits: 16 (C++ programming Example for Beginners) C++ Program to Add Two Matrix Using Multi-dimensional Arrays This program takes two matrices of order r*c and stores it in two-dimensional array. Then, the program adds these two matrices and displays it on the screen. In this program, user is asked to entered the number of rows r and …

C++ for Beginners: C++ Program to Calculate Standard Deviation

Hits: 34 (C++ programming Example for Beginners) C++ Program to Calculate Standard Deviation This program calculates the standard deviation of 10 data using arrays. This program calculates the standard deviation of a individual series using arrays. Visit this page to learn about Standard Deviation. To calculate the standard deviation, calculateSD() function is created. The array containing 10 elements …

C++ for Beginners: C++ Program to Find Largest Element of an Array

Hits: 5 (C++ programming Example for Beginners) C++ Program to Find Largest Element of an Array This program takes n number of element from user (where, n is specified by user) and stores data in an array. Then, this program displays the largest element of that array using loops. This program takes n number of element from …

C++ for Beginners: C++ Program to Calculate Average of Numbers Using Arrays

Hits: 50 (C++ programming Example for Beginners) C++ Program to Calculate Average of Numbers Using Arrays This program takes n number of element from user (where, n is specified by user), stores data in an array and calculates the average of those numbers. Example: Calculate Average of Numbers Using Arrays #include <iostream> using namespace std; …