Skip to main content

Posts

Showing posts from June, 2019

C++ program for store student detail in a file | File handling

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 ); cout << "\n E

C++ program to swap two variable using template function

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

C++ program for the list

C++ program for the list In this post i am going to write a program. The question for that program is: WAP to perform following actions on an array entered by the user: i) Print the even-valued elements  ii) Print the odd-valued elements  iii) Calculate and print the sum and average of the elements of array  iv) Print the maximum and minimum element of array  v) Remove the duplicate from the array  vi) Print the array in reverse order.  The program should present a menu to the userand ask for one of the options. The menu should also include options to re-enter array and to quit the program. #include<iostream> #include<cstdio> using namespace std; class List{ int list[30]; int i;  // for taking input public: void getlist(); void display(); void display_even(); void display_odd(); void display_sum(); void display_average(); void display_max(); void dispaly_min(); void remove_dublicates(); void

size and range of basic data types and modifing the basic types.

Size and range of basic data types:-   Modifying the basic types:-  Except for type void, the basic data types may have various modifiers preceding them.  You use a modifier to alter the meaning of the base type to fit various situations more  precisely. The list of modifiers is shown here: signed unsigned long short You can apply the modifiers signed, short, long, and unsigned to integer base  types. You can apply unsigned and signed to characters. You may also apply long to  double. The above  table shows all valid data type combinations, along with their minimal ranges and approximate bit widths. (These values also apply to a typical C++  implementation.) Remember, the table shows the minimum range that these types will  have as specified by Standard C/C++, not their typical range. For example, on  computers that use two's complement arithmetic (which is nearly all), an integer will have a range of at least 32,767 to –32,768. The use of signed on integers is al

Arithmetic operators and program on them

In the previous post, i was discussed about rules for the naming the variable, constants, data types and tokens. Today i am going to discus about some programs on the five basic data types. Before i start, let's me to introduce you with some  arithmetic operator.In the next post i will discus about operators of C++. Arithmetic operator are: 1. Addition operator: '+' is known as addition operator  and it is a used to add to numbers. In C++  we can also add two string by overloading  '+' operator. For example : consider two  string "Kunal" and "Kumar" after '+' operator  it will become  "Kunal Kumar" i.e two strings are concatenated. Latter, i will discus about operator overloading and concatenation of string.    2. Subtraction operator: '-' is known as subtraction operator and this is used to subtract two number and splitting strings. For example consider two string "Kunal Kumar" and "Kumar"

C++ tokens, rule for naming variable and rule for constructing integer constant, real constant and character constant

 C++ character set :- The following image shows the valid character that are used in C++.  C++ data types:- 1st of all we have to know that What is a data? Data is a raw material for constructing a information. For example, the following list are the data:- Ram,17, XII C. And from this data we can construct the information as Ram Aged 17 years is in class XII C. Data may be any number,words, amount,quantity. Now, Let's come on the topic: Latter i will discus about 'structure', 'Union', 'Class', Array', 'function','pointer','reference' for now there are five basic data types that are: 1. int(integer)  2. char(Character) 3. float 4. double  5. void  Now look at variable:  Variable is a entity whose value may change and in programming language it is used to store data. A integer type variable can hold a integer number(number must be a whole number either in positive or in negative but not in fraction),  a ch