C++ Programming Tutorial

 
 
 

Object Oriented Programming

Structures

Example of structures Passing structures to function Passing structure pointers to function Pointers and an array of structure Relationship between union and structure Array of structure Nested structures Self-referential structures Linked List

Classes

Classes with inline functions Classes without using inline functions Example of constructor in classes Passing values to constructor in classes Overloading of constructors in classes Example of destructor in classes Example of static class data Example of static member functions Constant objects, constant member functions Strings as member of classes Use of arrays as data items in classes Example of array of objects in classes Use of pointer this using header file this.h Obj initialize, assign by default member wise copy

Inheritance - Containership

Example of Inheritance Over riding base class member fn in derived Diff in public, protected, private inheritance Multi-level inheritance Multiple inheritance Example of containership

Virtual Functions - Polymorphism

Example of Polymorphism Example of Pure Virtual functions

Operator Overloading - Type Casting

Increment operator ++ overloading w/o return type Increment operator ++ overloading - return type Decrement operator -- overloading w/o return type Decrement operator -- overloading - return type Operator overloading for strings Comparision operator < overloading Binary operator + overloading creating new object Binary operator + overloading w/o creating object Binary operator - overloading creating object Binary operator - overloading w/o creating object Binary operator * overloading w/o creating object Stream insertion >> , extraction << operators Data conversion b/w built-in data types Data conversion - built-in, user defined data type Conversion- built-in, user defined data type- char Data conversion user defined data type - function Conversion user defined data type - constructor

Friend Functions and Classes

Use of friend functions Use of friend classes Operator overloading using friend function All Operator overloading using friend function Addition of 2 matrix using friend function Example of friend function of a class

Template Functions and Classes

Interchange value using function template Example of template classes Template based array input Template to find minimum value in an array Template of vector class

File Processing - Command Line Arguments

Open file File operation program - diff type of mode Read from one text file, writing in new text file File read, write, update and display operations Read decimal from file - convert into hexadecimal Read words from file and remove palindrome Read device data from text file and show extension Example of binary files

General Programs

Number of days b/w two given dates Capitalize first charcter of every word in string Copy n num of characters from one to another Word is palindrome or not using classes & pointers Simulation of the Solar System Add and Subtract functions on Big Number Class
 
 

Image

//MAKING FILE PROGRAM WITH USING ALL MODES

#include <iostream.h>
#include <fstream.h>
#include <conio.h>

static int totrec=0;    //totrec variable keep track for total variable entered
            //Initially Record scanned are Zero

void main()
{
int choice;
while(1)
{
clrscr();
cout<<\"Choose your choice\\nNOTE : one choice for one record(except viewing data)\\n\";
cout<<\"1) Scanning intial records\\n\";
cout<<\"2) Appending records\\n\";
cout<<\"3) Modifying or append records\\n\";
cout<<\"4) Viewing records\\n\";
cout<<\"5) Exit\\n\";
cout<<\"Enter your choice : \";
cin>>choice;
switch (choice)
{
  case 1 :   {
         ofstream outfile;
         outfile.open(\"emp\",ios::out);
         cout<<\"\\n\\nPlease enter the details as per demanded\\n\";
         cout<<\"\\nEnter the name : \";
         char name[20];
         cin>>name;
         outfile<<name<<endl;
         cout<<\"Enter Age : \";
         int age;
         cin>>age;
         outfile<<age<<endl;
         cout<<\"Enter programming language known by him\\her : \";
         char lang[25];
         cin>>lang;
         outfile<<lang<<endl;
         totrec= totrec + 1;
         outfile.close();
         }
         break;
  case 2 :   {
         ofstream outfile;
         outfile.open(\"emp\",ios::app);
         cout<<\"\\n\\nPlease enter the details as per demanded\\n\";
         cout<<\"\\nEnter the name : \";
         char name[20];
         cin>>name;
         outfile<<name<<endl;
         cout<<\"Enter Age : \";
         int age;
         cin>>age;
         outfile<<age<<endl;
         cout<<\"Enter programming language known by him : \";
         char lang[25];
         cin>>lang;
         outfile<<lang<<endl;
         totrec = totrec + 1;
         outfile.close();
         }
         break;
  case 3 :   {
         ofstream outfile;
         outfile.open(\"emp\",ios::ate);
         cout<<\"Are you interested in adding record\\nenter y or n\\n\";
         char ans;
         cin>>ans;
         if(ans==\'y\' || ans==\'Y\')
         {
         cout<<\"\\n\\nPlease enter the details as per demanded\\n\";
         cout<<\"\\nEnter the name : \";
         char name[20];
         cin>>name;
         outfile<<name<<endl;
         cout<<\"Enter Age : \";
         int age;
         cin>>age;
         outfile<<age<<endl;
         cout<<\"Enter programming language known by him : \";
         char lang[25];
         cin>>lang;
         outfile<<lang<<endl;
         totrec = totrec + 1;
         }
         outfile.close();
         }
         break;
  case 4 :   {
         ifstream infile;
         infile.open(\"emp\",ios::in);
         const int size=80;
         char line[size];
         int counter=totrec;
         while(counter > 0)
         {
         infile.getline(line,size);
         cout<<\"\\n\\nNAME     : \"<<line<<endl;
         infile.getline(line,size);
         cout<<\"AGE      : \"<<line<<endl;
         infile.getline(line,size);
         cout<<\"LANGUAGE : \"<<line<<endl;
         counter--;
         }
         infile.close();
         }
         getch();
         break;
  case 5  :  goto out;
  default :  cout<<\"\\nInvalid Choice\\nTRY AGAIN\\n\";
  }
}
out:
}

    Related Post:
  1. Program to illustrate the implementation of Reflection Transformation about the line y=x and y=-x

  2. Program to illusrate data conversion user defined data types using constructor

  3. Program to illustrate self-referential structures Linked List

  4. Program to show the implementation of Hashing with Insert, Delete and search functionality using double-ended Linked List

  5. Program of simple example of class and object

  6. Represent a polynomial in terms of a singly linked list and then add two three variables polynomials

  7. Program to show the use of Bitwise Operator XOR ( ^ )

  8. Program that prints odd numbers, even numbers and the numbers that are divisible by 5 b/w 0 to 50

  9. Program to calculate anybody\’s single digit lucky number

  10. Program that reads marks obtained by a student in a test of 100 marks and print pass if marks are greater than or equal to 50

  11. To parse a string using First and Follow algorithm and LL-1 parser

  12. Program to illustrate the implementation of linked list as a Stack

  13. Program to find whether a year is a leap year or not

  14. Program of declaration of default arguments during creation of function

  15. Program to illustrate unary operator(decrement operator) overloading without return type

  16. Write a program to read value from console and perform arithmetic operation

  17. Program that provides an example of return by reference from functions

  18. PROGRAM TO IMPLEMENT RECURSIVE DESCENT PARSER

  19. Program to read all words from a file and remove all words which are palindromes

  20. Program that reads a number ,coumputes and displays its factorial ( using for loop )

 
 
Didn't find what you were looking for? Find more on File Operation Program