Posts

Showing posts from December, 2014

File handling in C++

File handling  Common operations on files are open,read , write and close. Below mentioned code snippet exhibits these operations;  #include <fstream> #include <iostream> using namespace std; int main () {      char data[100];    // open a file in write mode.    ofstream outfile;    outfile.open("umar.txt");    cout << "\nWriting to the file\n";    cout << "Enter your name: ";    cin.getline(data, 100);    // write inputted data into the file.    outfile << data << endl;    cout << "\n Enter your RollNumber: ";    cin >> data;    cin.ignore();      // again write inputted data into the file.    outfile << data << endl;    // close the opened file.    outfile.close();    // open a file in read mode....

Inheritance in C++

Inheritance "Student is a type of a person " is inheritance by nature. T o implement this relationship code snippet is as under; #include<iostream.h> class Person{       private:               char* name;               int Age;               public:                                            Person(){                                                              name="";                               Age=0;                            ...