C++ program for store student detail in a file:- In this post i am going to write a C++ program that illustrate the use of file handling in C++. File handling requires when we want to save data for in future, if the data require then we can easily get them. Since, the life of a variables which we make in a program less than the life of the program. As soon as the program end the variables also vanished. The following program construct a structure student containing the field for Roll no., Name, Class, Year and total marks. Let's begin the program:- #include <iostream> #include <fstream> using namespace std ; struct student { int RollNo ; char Name [ 30 ]; int year ; char class1 [ 30 ]; float total_marks ; }; void ReadStudent ( student & TempStud ) { cout << "\n Enter roll no.: " ; cin >> TempStud.RollNo ; cin . clear (); fflush ( stdin ); ...
C++ program to swap two variable using template function Today i am going to swap to variable's contents using template function. The below is the C++ program that swap two variable's contents. // C++ program to swap two variable contants // Using template function #include<iostream> using namespace std ; template < typename t > // defining template function void swap ( t * var , t * var1 ){ t var2 ; var2 = * var ; //swaping the contents * var =* var1 ; * var1 = var2 ; } int main (){ // displaying the menu to the user cout << "1. Swap two integer numbers:" ; cout << "\n2. Swap two float numbers:" ; cout << "\n3. Swap two characters:" ; cout << "\n Enter your choice:" ; short i ; cin >> i ; // storing the choice of the user switch ( i ){ case 1 : { int a , b ; cout << "\n Enter 1st nu...