C++ Programming Tutorial

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

(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 10 students. …

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

(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, struct TIME, …

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

(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; int main(){ …

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

(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 marks as …

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

(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 string s1: …

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

(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; cout << …

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

(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 they both …

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

(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(){ char line[150]; …

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

(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 passing the …

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

(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 in this …

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

(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 columns c. The …

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

(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 is passed …