C++ Helpdesk

Go Back to website

C++ PROGRAMMING LANGUAGE

ASSIGNMENTS OF C++

Constructor & Destructor

  1.     
    #include<iostream.h>
    #include<conio.h>
    class Rectangle
    {
    private:
    int length;
    int breadth;
    public:
    Rectangle()
    {
    length=10;
    breadth=20;
     cout<<"The length of the rectangle is"<<length;
     cout<<"\n";
     cout<<"The breadth of the rectangle is"<<breadth;
     }};
    void main()
    {
    Rectangle rect;
    getch();
    }
        

  •     
    #include<iostream.h>
    #include<conio.h>
    class Rectangle
    {
    private:
    int length;
    int breadth;
    int rect;
    public:
    Rectangle(int l,int b)
    {
    length=l;
    breadth=b;
    }
    void area()
    {
    rect=length*breadth;
    cout<<"The area of the rectangle is:"<<rect;
    }};
    void main()
    {
    Rectangle rect(10,10);
    rect.area();
    getch();
    } 
    

  •     
    #include<iostream.h>
    #include<conio.h>
    class Rectangle
    {
    private:
    int length;
    int breadth;
    int rect;
    public:
    Rectangle()
    {
    length=100;
    breadth=200;
    cout<<"This is the length and breadth of the default constructer";
    cout<<"\n";
    cout<<"The length of the rectangle is:"<<length;
    cout<<"\n";
    cout<<"The breadth of the rectangle is:"<<breadth;
    cout<<"\n";
    cout<<"\n";
    }
    Rectangle(int l,int b)
    {
    length=l;
    breadth=b;
    rect=length*breadth;
    cout<<"This is parameterized constructure";
    cout<<"\n";
    cout<<"The area of the rectangle is:"<<rect;
    }};
    void main()
    {
    Rectangle r;
    Rectangle r1(10,10);
    getch();
    }
    


    Function Overloading

  •     
    #include<iostream.h>
    #include<conio.h>
    class Math
    {
    private:
    int num1;
    int num2;
    int num3;
    float n1,n2,n3;
    public:
    /*void sum(int a1,int a2)
    {
    num1=a1;
    num2=a2;
    num3=num1+num2;
    cout<<"The sum of two number is:"<<num3;
    } 
    void sum(float f1,float f2)
    {
    n1=f1;
    n2=f2;
    n3=n1+n2;
    cout<<"The sum of two number is:"<<n3;
    }
    };
    void main()
    {
    Math m1;
    m1.sum(10,20);
    m1.sum(10.1,20.1);
    getch();
    }

  •     
    #include<iostream.h>
    #include<conio.h>
    class Area
    {
    private:
    int length;
    int breadth;
    int ar;
    int side;
    public:
    void area(int l,int b)
    {
    length=l;
    breadth=b;
    ar=length*breadth;
    cout<<"The area of the rectangle is:";
    cout<<ar;
    cout<<"\n";
    }
    void area(int s)
    {
    side=s;
    ar=side*side;
    cout<<"The area of the square is:";
    cout<<ar;
    }
    };
    void main()
    {
    Area a1;
    a1.area(10,10);
    a1.area(12);
    getch();
    }
    

    INHERITANCE

  •   include<iostream>
    using namespace std;
    class Student
    {
    private:
    int rollno;
    char name[20];
    public:
    void get_data();
    void show_data();
    };
    void Student::get_data()
    {
    cout<<"Enter the rollno. of the student:";
    cin>>rollno;
    cout<<"Enter the name of the student:";
    cin>>name;
    }
    void Student::show_data()
    {
    cout<<"\nThe rollno of the student: "<<rollno;
    cout<<"\nThe name of the student: "<<name;
    }
    class Marks:public Student
    {
    private:
    float marks[5];
    public:
    void get_marks();
    void percentage();
    };
    void Marks::get_marks()
    {
    int i;
    cout<<"\nEnter marks : ";
    for(i=0;i<5;i++)
    {
    cin>>marks[i];
    }}
    void Marks::percentage()
    {
    int sum=0;
    int i;
    int pctage;
    for(i=0;i<5;i++)
    {
    cout<<endl<<"Marks are: "<<marks[i];
    sum=sum+marks[i];
    }
    pctage=sum/5;
    cout<<endl<<"Percentage is "<<pctage<<"%";
    }
    int main()
    {
    Marks m1;
    m1.get_data();
    m1.show_data();
    m1.get_marks();
    m1.percentage();

    }

    Answer the following:
    i.If Marks also have the same name function as that of class Student then which function will be invoked by the object of class Marks.
    ii.What is the syntax of calling the base class function if both the derived class and base class have same name function.

  • #include<iostream>
    using namespace std;
    class Student
    {
    private:
    int rollno;
    char name[20];
    public:
    void get_data()
    {
    cout<<"Enter the roll no of the student";
    cin>>rollno;
    cout<<"Enter the name of the student";
    cin>>name;
    }
    void show_data()
    {
    cout<<"\nThe roll no of the student is:";
    cout<<rollno;
    cout<<"\nThe name of the student is";
    cout<<name;
    cout<<"\n\n";
    }
    };//end of class student
    class Teacher
    {
    private:
    char name[20];
    float salary;
    char sub[10];
    public:
    void get_data1()
    {
    cout<<"Enter the name of the teacher";
    cin>>name;
    cout<<"Enter the salary of the teacher";
    cin>>salary;
    cout<<"Enter the subject of the teacher";
    cin>>sub;
    }
    void show_data1()
    {
    cout<<"\nThe name of the teacher is:";
    cout<<name;
    cout<<"\nThe salary of the teacher is:";
    cout<<salary;
    cout<<"\nThe subject of the teacher is:";
    cout<<sub;
    cout<<"\n";
    }
    };
    class School:public Student,public Teacher
    {
    private:
    int no_of_student;
    int no_of_teacher;
    public:
    void get_data2()
    {
    cout<<"Enter the no. of student";
    cin>>no_of_student;
    cout<<"\n";
    cout<<"Enter the no. of the teacher";
    cin>>no_of_teacher;
    }
    void show_data2()
    {
    cout<<"\nThe no. of the students are:";
    cout<<no_of_student;
    cout<<"\nThe no. of the teachers are:";
    cout<<no_of_teacher;
    }
    };
    int main()
    {
    School s1;
    s1.get_data();
    s1.show_data();
    s1.get_data1();
    s1.show_data1();
    s1.get_data2();
    s1.show_data2();
    return 0;
    }
    Answer the following: i.If both the classes 'Student' and 'School' have the default constructor then which constructor will be called first? ii.If both the classes 'Teacher' and 'School' have the default constructor as well as parameterized constructor then what is the order of constructor call? iii.How can we call the base class parameterized constructor before the derived class parameterized constructor?

  •     
    #include<iostream.h>
    #include<conio.h>
    class Student
    {
    private:
    int rollno;
    char name[20];
    public:
    void get_data()
    {
    cout<<"Enter the roll no of the student";
    cin>>rollno;
    cout<<"Enter the name of the student";
    cin>>name;
    }
    void show_data()
    {
    cout<<"The roll no of the student is:";
    cout<<rollno;
    cout<<"\n";
    cout<<"The name of the student is";
    cout<<name;
    cout<<"\n\n";
    }
    };
    class Attendance:public Student
    {
    protected:
    int no_of_absentees;
    public:
    void get_data()
    {
    cout<<"Enter the no. of absentees:";
    cin>>no_of_absentees;
    }
    void show_data()
    {
    cout<<"The no.of absentees are:";
    cout<<no_of_absentees;
    }
    };
    class Accounts:public Attendance
    {
    private:
    float fees;
    float bal;
    public:
    void get_data()
    {
    cout<<"\n";
    cout<<"Enter the fees of the student is";
    cin>>fees;
    cout<<"Enter the bal of the student is:";
    cin>>bal;
    }
    void cal_total_amt()
    {
    int total_fees;
    total_fees=fees-bal;
    cout<<"The total fees of the student is:";
    cout<<total_fees;
    }
    };
    void main()
    {
    Accounts a1;
    a1.Student::get_data();
    a1.Student::show_data();
    a1.Attendance::get_data();
    a1.Attendance::show_data();
    a1.Accounts::get_data();
    a1.cal_total_amt();
    getch();
    }
     

  •     
    #include<iostream.h>
    #include<conio.h>
    class Student
    {
    protected:
    int rollno;
    char name[20];
    public:
    void get_data()
    {
    cout<<"Enter the roll no of the student";
    cin>>rollno;
    cout<<"Enter the name of the student";
    cin>>name;
    }
    void show_data()
    {
    cout<<"The roll no of the student is:";
    cout<<rollno;
    cout<<"\n";
    cout<<"The name of the student is";
    cout<<name;
    cout<<"\n\n";
    }
    };
    class Marks:public Student
    {
    private:
    float marks[5];
    public:
    void get_marks();
    void percentage();
    };
    void Marks::get_marks()
    {
    int i;
    cout<<"Enter the marks of the student:";
    for(i=0;i<5;i++)
    {
    cin>>marks[i];
    }}
    void Marks::percentage()
    {
    int sum=0;
    int i;
    int pctage;
    for(i=0;i<5;i++)
    {
    cout<<marks[i];
    sum=sum+marks[i];
    }
    pctage=sum/5;
    cout<<"\n";
    cout<<"The percentage of the student is:";
    cout<<pctage;
    cout<<"\n\n";
    };
    class  Sports:public Student
    {
    private:
    char game_name[10];
    float score;
    public:
    void get_score()
    {
    cout<<"Enter the name of the game:";
    cin>>game_name;
    cout<<"\n";
    cout<<"Enter the score of the game:";
    cin>>score;
    cout<<"\n";
    }
    void show_score()
    {
    cout<<"The name of the game is:";
    cout<<game_name;
    cout<<"\n";
    cout<<"The score of the game  is:";
    cout<<score;
    }};
    void main()
    {
    Marks m1;
    Sports s1;
    m1.get_data();
    m1.show_data();
    m1.get_marks();
    m1.percentage();
    s1.get_data();
    s1.show_data();
    s1.get_score();
    s1.show_score();
    getch();
    }
    

  •     
    #include<iostream.h>
    #include<conio.h>
    class Student
    {
    protected:
    int rollno;
    char name[20];
    public:
    void get_data()
    {
    cout<<"Enter the roll no of the student";
    cin>>rollno;
    cout<<"Enter the name of the student";
    cin>>name;
    }
    void show_data()
    {
    cout<<"The roll no of the student is:";
    cout<<rollno;
    cout<<"\n";
    cout<<"The name of the student is";
    cout<<name;
    cout<<"\n\n";
    }
    };
    class Test:public Student
    {
    protected:
    float marks[5];
    public:
    void gettest();
    void showtest();
    };
    void Test::gettest()
    {
    int i;
    for(i=0;i<5;i++)
    {
    cout<<"Enter the marks of the students:";
    cin>>marks[i];
    //cout<<"\n";
    }}
    void Test::showtest()
    {
     int i;
     cout<<"The marks of the student: ";
     for(i=0;i<5;i++)
     {
    
     cout<<endl<<marks[i];
    } }
    
    class Address
    {
    private:
    char city[10];
    public:
    void get_add()
    {
    cout<<"\n\nEnter the name of the city";
    cin>>city;
    }
    void show_add()
    {
    cout<<"\nThe name of the city is:";
    cout<<city;
    }
    };
    
    class Result:public Test,public Address
    {
    private:
    float total;
    float avg;
    public:
    Result()
    {
     total=0;
    }
    void get_result();
    void show_result()
    {
    cout<<"\nThe total marks of the student:";
    cout<<total;
    cout<<"\n";
    cout<<"The avg of the student is:";
    cout<<avg;
    }};
    void Result::get_result()
    {
    int i;
     for(i=0;i<5;i++)
     {
    total=total+marks[i];
    }
    avg= total/5;
    }
    void main()
    {
    Result r1;
    r1.get_data();
    r1.show_data();
    r1.gettest();
    r1.showtest();
    r1.get_result();
    r1.show_result();
    r1.get_add();
    r1.show_add();
    getch();
    }

  •     
    #include<iostream.h>
    #include<conio.h>
    class A
    {
    public:
    void show()
    {
    cout<<"\nHere is the base class";
    }
    };
    class B:virtual public A
    {
      public:
    void show1()
    {
      cout<<"\nHere is the show1 function of B class";
    }};
    class C:virtual public A
    {
    public:
    void show2()
    {
    cout<<"\nHere is the show2 function of c class";
    }
    };
    class D:public B,public C
    {
    public:
    void show3()
    {
    cout<<"\nHere is the show3 fuction of d class";
    }
    };
    void main()
    {
    D d1;
    d1.show();
    d1.show1();
    d1.show2();
    d1.show3();
    getch();
    }

    Friend Function Friend Class

  •     
    #include<iostream.h>
    #include<conio.h>
    class Rectangle
    class Demo
          {
            int num1;
            int num2;
            friend void usedata();
            public:
            void input()
            {
             cout<<"Enter first number:  ";
             cin>>num1;
             cout<<"Enter second number:  ";
             cin>>num2;
            }
            void display()
            {
             cout<<"num1= "<<num1<<"   num2= "<<num2;
            }
          };
    
          void usedata()
          {
           Demo d1;
           d1.num1=100;
           d1.num2=200;
           cout<<"\n\n\n The values of num1 & num2 in usedata function are: ";
           cout<<endl<<"num1= "<<d1.num1<<" num2= "<<d1.num2;
          }
    
          void main()
          {
           Demo d;
           d.input();
           d.display();
           usedata();// This function is only the friend        function not
                      // the member function of class        Demo.So, it will
                      // not be called with an object of a        class Demo.
           getch();
          }
    

  •     
    #include<iostream.h>
    #include<conio.h>
    class Demo
          {
            int num1;
            int num2;
            friend void sum();
            public:
            void input()
            {
             cout<<"Enter first number:  ";
             cin>>num1;
             cout<<"Enter second number:  ";
             cin>>num2;
            }
            void output()
            {
             cout<<"num1= "<<num1<<"   num2= "<<num2;
            }
          };
    
          void sum()
          {
           Demo d1;
           int res;
           d1.input();
           res=d1.num1+d1.num2;
           cout<<"\n\n\n The sum of num1 & num2 in sum function is: "<<res;
         }
    
          void main()
          {
           Demo d;
           d.input();
           d.output();
           cout<<endl<<endl;
           sum();
           getch();
          }          
    

  •     
    #include<iostream.h>
    #include<conio.h>
     
           class Demo1
           {
             int num1;
             public:
             friend void sum();
             void input1()
             {
              cout<<"Enter the value for num1 in Demo1 class ";
              cin>>num1;
             }
           };
            class Demo2
           {
             int num2;
             public:
             friend void sum();
             void input2()
             {
              cout<<"Enter the value for num2 in Demo2 class ";
              cin>>num2;
             }
           };
           void sum()
           {
            Demo1 d1;
            Demo2 d2;
            int res;
            d1.input1();
            d2.input2();
            res=d1.num1+d2.num2;
            cout<<"\n Sum of Demo1-:num1 & Demo2-:num2 is: "<<res;
    
           }
    
           void main()
           {
            sum();
            getch();
           }      
    

  •     
    #include<iostream.h>
    #include<conio.h>
     class Test1
           {
             int num1;
             public:
             friend void greater();
             void input1()
             {
              cout<<"Enter the value for num1 in Test1 class ";
              cin>>num1;
             }
           };
            class Test2
           {
             int num2;
             public:
             friend void greater();
             void input2()
             {
              cout<<"Enter the value for num2 in Test2 class ";
              cin>>num2;
             }
           };
           void greater()
           {
            Test1 t1;
            Test2 t2;
            t1.input1();
            t2.input2();
            if(t1.num1>t2.num2)
            {
             cout<<"\n Test1 class num1 is greater "<<t1.num1;
            }
            else
            {
             cout<<"\n Test2 class num2 is greater "<<t2.num2;
            }
    
           }
    
           void main()
           {
           greater();
            getch();
           }     
    

  •     
    #include<iostream.h>
    #include<conio.h>
    class Maths1
           {
             int num1;
             public:
             friend class Maths3;
             void input1()
             {
              cout<<"Enter the value for num1 in Maths1 class ";
              cin>>num1;
              cout<<endl;
             }
           };
            class Maths2
           {
             int num2;
             public:
             friend class Maths3;
             void input2()
             {
              cout<<"Enter the value for num2 in Maths2 class ";
              cin>>num2;
              cout<<endl;
             }
           };
            class Maths3
            {
              Maths1 m1;
              Maths2 m2;
              public:
              void swap()
              {
               m1.input1();
               m2.input2();
               int temp;
               cout<<"\n Values of Maths1 class num1 & Maths2 class num2 before swapping are : \n";
               cout<<"Maths1 num1= "<<m1.num1;
               cout<<"\nMaths2 num2= "<<m2.num2;
               cout<<endl<<endl;
               temp=m1.num1;
               m1.num1=m2.num2;
               m2.num2=temp;
               cout<<"\n Values of Maths1 class num1 & Maths2 class num2 after swapping are : \n";
               cout<<"Maths1 num1= "<<m1.num1;
               cout<<"\nMaths2 num2= "<<m2.num2;
              }
            };
            void main()
            {
            Maths3 m3;
            m3.swap();
             getch();
            }
    

    Static Function

  •     
    #include<iostream.h>
    #include<conio.h>
    	class Sample
    	{
    	 static int n;
    	  public:
    	  Sample()
    	  {
    		n++;
    		cout<<"\nObject "<<nlt;<" created";
    	  }
    
    	};
    	int Sample::n=0;
    	void main()
    	{
    	Sample s1,s2,s3;
    		 getch();
    		 }
    		 

  •     
    #include<iostream.h>
    #include<conio.h>
    class Rectangle
    		{
    		  static int n;
    		  int length;
    		  int breadth;
    		  int ar;
    		  public:
    		  Rectangle()
    		  {
    			n++;
    		  cout<<"\n"<<n<<" rectangles are created";
    		  }
    		  void input()
    		  {
    			 cout<<"\n\nEnter the length and breadth of Rectangle   ";
    			cin>>length>>breadth;
    		  }
    		  void area()
    		  {
    			ar=length*breadth;
    			cout<<"\n Area of rectangle is "<<ar;
    		  }
    			};int Rectangle::n;
    
    		void main()
    		{
    		Rectangle r1,r2,r3;
    		r1.input();
    		r1.area();
    		 getch();
    		}
    		

  •     
    #include<iostream.h>
    #include<conio.h>	
    class Rectangle
    		{
    		  static int n;
    		  int length;
    		  int breadth;
    		  int ar;
    		  public:
    		  void init()
    		  {
    		 // n=0;
    			n++;
    		  cout<<"\n"<<n<<" rectangles are created";
    		  cout<<"\n\nEnter the length and breadth of Rectangle   ";
    			cin>>length>>breadth;
    		  }
    		  void area()
    		  {
    			ar=length*breadth;
    			cout<<"\n Area of rectangle is "<<ar;
    		  }
    			};
    			 int Rectangle::n;
    
    		void main()
    		{
    		Rectangle r1,r2,r3;
    		r1.init();
    		r1.area();
    		r2.init();
    		r2.area();
    		r3.init();
    		r3.area();
    		 getch();
    		}	

    Polymorphism
    Virtul and Pure Virtual Function

  •     
    #include<iostream.h>
    #include<conio.h>	
    class base
          {
            public:
           virtual void show()
            {
             cout<<" \n show function of base class ";
            }
          };
    
          class derived:public base
          {
            public:
            void show()
            {
             cout<<" \n show function of derived class ";
            }
          };
    
          void main()
          {
           derived d;
           base *bptr;
           bptr=&d;
           bptr->show();
           getch();
          }

  •     
    #include<iostream.h>
    #include<conio.h>	
    class Shape
          {
            virtual void area()=0;
            virtual void perimeter()=0;
          };
    
          class  Rectangle:public Shape
          {
          int length,breadth,ar,per;
            public:
            Rectangle()
            {
             cout<<"Enter length and breadth of rectangle: ";
             cin>>length>>breadth;
            }
            void area()
            {
             ar=length*breadth;
             cout<<"\n Area of rectangle is "<<ar;
            }
            void perimeter()
            {
             per=2*(length+breadth);
             cout<<"\n Perimeter of rectangle is "<<per;
            }
          };
    
          class  Square:public Shape
          {
          int side,ar,per;
            public:
            Square()
            {
             cout<<"Enter side of square: ";
             cin>>side;
            }
            void area()
            {
             ar=side*side;
             cout<<"\n Area of square is "<<ar;
            }
            void perimeter()
            {
             per=4*side;
             cout<<"\n Perimeter of squaree is "<<per;
            }
          };
          void main()
          {
          Rectangle rect;
          Square sq;
          rect.area();
          rect.perimeter();
          sq.area();
          sq.perimeter();
           getch();
          }	

    File Handling

  •     
    #include<iostream.h>
    
        #include<conio.h>
    
    
        #include<fstream.h>
            
    void main() { int num; ofstream fout; fout.open("e:/website/cplusassignments/abc.txt"); cout<<"Enter any number "; cin>>num; fout<<num; cout<<"Data saved "; fout.close(); getch(); }

  •     
    #include<iostream.h>
    #include<conio.h>
    #include<fstream.h>
            void main()
            {
    		
             int num1,num2;
             ofstream fout;
             fout.open("e:/website/cplusassignments/abc.txt");
             cout<<"Enter first number ";
             cin>>num1;
             cout<<"Enter second number ";
             cin>>num2;
             fout<<num1<<"\t"<<num2;
             cout<<"Data saved ";
             fout.close();
             getch();
            }

  •     
    #include<iostream.h>
    #include<conio.h>
    #include<fstream.h>
            void main()
            {	
    		 int rollno;
             char name[20];
             ofstream fout("e:/website/cplusassignments/first.txt");
             //fout.open("e:/website/cplusassignments/abc.txt");
             cout<<"Enter name ";
             cin.getline(name,20);
             cout<<"Enter rollno ";
             cin>>rollno;
             fout<<rollno<<"\t"<<name;
             cout<<"Data saved ";
             fout.close();
             getch();
            }

  •     
    #include<iostream.h>
    #include<conio.h>
    #include<fstream.h>
            void main()
            {
    		int num;
             ifstream fin("e:/website/cplusassignments/abc.txt");
             fin>>num;
             cout<<"\n Number is "<<num;
             fin.close();
             getch();
             }
            

  •     
    #include<iostream.h>
    #include<conio.h>
    #include<fstream.h>
            void main()
    		{
    		int rollno;
             char name[30];
             fstream finout("e:/website/cplusassignments/first.txt",ios::in);
             finout>>rollno;
             finout.getline(name,20);
             cout<<"\n Rollno is "<<rollno;
             cout<<"\n Name is "<<name;
             finout.close();
             getch();
    		 }

  •     
    #include<iostream.h>
    #include<conio.h>
    #include<fstream.h>
            void main()
    		{
    		char str[40];
             int i=1,n=3;
             fstream finout;
             //cout<<"Enter the lines to be enter ";
             //cin>>n;
             while(i<=n)
             {
             finout.open("e:/website/cplusassignments/second.txt",ios::app);
             cout<<"Enter a string ";
             cin.getline(str,40);
             finout<<str<<endl;
             i++;
             }
             finout.close();
             getch();
             }
    		 

  •     
    #include<iostream.h>
    #include<conio.h>
    #include<fstream.h>
            void main()
    		{
    		 int num;
             char str[20];
             fstream finout("e:/website/cplusassignments/first.txt",ios::out);
             cout<<"Enter number and a string ";
             cin>>num>>str;
             finout<<num<<" "<<str;
             cout<<"\n Data saved ";
             finout.close();
             finout.open("e:/website/cplusassignments/first.txt",ios::in);
             finout>>num>>str;
             finout.close();
             finout.open("e:/website/cplusassignments/second.txt",ios::out);
             finout<<num<<" "<<str;
             cout<<"Number is "<<num;
             cout<<"\n string is "<<str;
             finout.close();
             getch();
             }
    		 

  •     
    #include<iostream.h>
    #include<conio.h>
    #include<fstream.h>
            void main()
    		{
    		 int num,n;
             fstream finout("e:/website/cplusassignments/forth.txt",ios::out);
             cout<<"Enter a number ";
             cin>>num;
             finout<<num;
             cout<<"Data saved ";
             finout.close();
             finout.open("e:/website/cplusassignments/forth.txt",ios::in);
             finout>>n;
             cout<<"\n Number is "<<n;
             finout.close();
             getch();
             }
    		 

  •     
    #include<iostream.h>
    #include<conio.h>
    #include<fstream.h>
             class File
            {
              int rollno;
              char name[10];
              public:
              void input()
              {
               cout<<"Enter name ";
               cin.getline(name,20);
               cout<<"Enter rollno ";
               cin>>rollno;
              }
              void write()
              {
               ofstream fout("e:/website/cplusassignments/third.txt");
                fout<<rollno<<"\t"<<name;
                cout<<"Data saved ";
                fout.close();
              }
            };
            void main()
            {
             File f;
             f.input();
             f.write();
            getch();
            }
    		 

  •     
    #include<iostream.h>
    #include<conio.h>
    #include<fstream.h>
           class File
            {
              int rollno;
              char name[10];
              public:
             void read()
              {
               ifstream fin("e:/website/cplusassignments/third.txt");
                fin>>rollno>>name;
                cout<<"Rollno is : "<<rollno;
                cout<<"\nName is : "<<name;
                fin.close();
              }
            };
            void main()
            {
             File f;
             f.read();
            getch();
            }
            

  •     
    #include<iostream.h>
    #include<conio.h>
    #include<fstream.h>
           void main()
            {
            int num;
            fstream finout("e:/website/cplusassignments/abc.txt",ios::app);
            cout<<"Enter any number ";
            cin>>num;
            finout<<"\t"<<num;
            cout<<"\n Data saved ";
            finout.close();
             getch();
            }