Tuesday 31 March 2015

Write a program that asks user to enter two values between 0 and 100 now print the values from first number to second number.

#include<stdio.h>
#include<conio.h>
void main (void

{
int num;
printf("enter number");
scanf("%d",&d);

if(a<0&&a>100);
for(i=0;i<100;i++)
{
printf("value=%d",i);
}

else
printf("not a valid value");

}

Friday 3 October 2014

Student (D) (OOP)

# include<iostream.h>
class Student
{
    private:
        int rollNo;
        int semNo;
    public:
        Student()
        {
            rollNo=0;
            semNo=0;
        }
        Student(int r,int s)
        {
            rollNo=r;
            semNo=s;
        }
        void setRollNo(int r)
        {
            if(r>0)
            {
                rollNo=r;
            }
            else
            {
                cout<<"Sorry, not properly initialized";
            }
        }
        int getRollNo()
        {
            return rollNo;
        }
        void setSemNo(int s)
        {
            semNo=s;
        }
        int getSemNo()
        {
            return semNo;
        }

        void input()
        {
            cout<<"Enter the value of RollNo: ";
            int r;
            cin>>r;
            setRollNo(r);

            cout<<"Enter the value of SemesterNo: ";
            int s;
            cin>>s;
            setSemNo(s);
        }
        void display()
        {
            cout<<"the value of RollNo:  ";
            cout<<getRollNo();
            cout<<endl;
            cout<<"the value of SemesterNo:  ";
            cout<<getSemNo();

            cout<<endl;
        }
};


void main()
{
    Student amir;
    Student ali;
    amir.input();
    amir.display();
    cout<<endl;
    cout<<"***********"<<endl;
    ali.input();
    ali.display();



}

Student (Class ) with constructor destructor c++

# include<iostream.h>

class Student
{
    public:
        char *name;
        int rollNo;
        int semNo;
   
    public:
        Student()
        {
            name=new char[20];
            rollNo=0;
            semNo=0;
        }
       
        Student(char *n,int r,int s)
        {
            name=new char[20];
            name=n;
            rollNo=r;
            semNo=s;
        }

        void setName(char *n)
        {
            if(n!=NULL)
            {
                name=n;
            }
        }
        char* getName()
        {
            return name;
        }
        void setRollNo(int r)
        {
            rollNo=r;
        }

        int getRollNo()
        {
            return rollNo;
        }

};

void main()
{
    Student obj;


    Student obj1("pakistan",43,2);
    cout<<obj1.getName()<<endl;
    cout<<obj1.getRollNo()<<endl;
    //cout<<obj1.ge


    //obj.name="amir";
    //cout<<*(&obj.name)<<endl;
   
    //cout<<obj.name[2];
    //obj.setName("amir");
    //cout<<obj.getName();
}

Example of static member function (OOP)

 # include <iostream>
 using namespace std;

////////  Example of static member function  /////////

class StaticFunction
{
      
      public:
            
             static void show()    // static member function
             {
                  cout<<"Welcome to static member function"<<endl;
             }         
};
int main()
{
    StaticFunction::show();      // call a static member function
    system("pause");
}