C++ Programming Example

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

Hits: 56 (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: 29 (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: 9 (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: 48 (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: 7 (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: 10 (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: 24 (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: 22 (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 …