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");
}

Thursday, 2 October 2014

Example of static data members (OOP)

 # include <iostream>
 using namespace std;

////////  Example of static data members  /////////

//int Static::x=100;        if u declared static data member before class it will give you error

class Static
{
      //static int x;       u can also write static data member in private section
      public:
      static int x;       // static data member
             void show()
             {
                  cout<<x++<<endl;
             }          
};
int Static::x=100;
int main()
{
    Static s[5];
    for(int i=0; i<5;i++)
    {
            s[i].show();
    }
    system("pause");
}

Implemention of Lists Slides (DS)

Tuesday, 30 September 2014

Write a program to make the class of a student to enter name and roll no using constructor.

#include<iostream>
using namespace std;
class student
{
private:
char name[20];
int roll;
public:
student(char b[20] , int s)
{
name[20]=b[20];
roll=s;
}
int set()
{
cout<<“enter the name”<<endl;
gets(name);
cout<<“enter the roll”<<endl;
cin>>roll;
}
int get()
{
cout<<“name is: “<<name<<endl;
cout<<“roll is: “<<roll<<endl;
}
};
int main()
{
student std(“shahroz”,49);
std.set();
std.get();
system(“pause”);
}
 

Wednesday, 24 September 2014

OOP PROGRAM

#include<iostream>
using namespace std;

class Time{
      private:
      int Hours, Minutes, Seconds;
public:
      Time();
      void setHours(int Hours_value);
      int getHours();
      void setMinutes(int Minutes_value);
      int getMinutes();
      void setSeconds(int Seconds_value);
      int getSeconds();
      void UniversalPrint();
};

Time::Time()
{
                  Hours=0;
                  Minutes=0;
                  Seconds=0;
}

void Time::setHours(int Hours_value)
{
     if(0>=Hours_value||Hours_value>=24)
     {
                         cout<<"Wrong Input"<<endl;
                         Hours=0;
     }
     else
     {    
                   Hours=Hours_value;
     }
}
int Time::getHours()
{
                return Hours;
}

void Time::setMinutes(int Minutes_value)
{
     if(0>=Minutes_value||Minutes_value>60)
     {
                         cout<<"Wrong Input"<<endl;
                         Minutes=0;
     }
     else
     {    
                   Minutes=Minutes_value;
     }                      
}

int Time::getMinutes()
{
    return Minutes;
}

void Time::setSeconds(int Seconds_value)
{
     if(0>=Seconds_value||Seconds_value>=60)
     {
                         cout<<"Wrong Input"<<endl;
                         Seconds=0;
     }
     else
     {    
                   Seconds=Seconds_value;
     }
}
int Time::getSeconds()
{
    return Seconds;
}

void Time::UniversalPrint()
{
        cout<<getHours()<<":"<<getMinutes()<<":"<<getSeconds();
}


int main()
{
    Time my;
    int Hours_value, Minutes_value, Seconds_value;
    cout<<"Enter Hours: "<<endl;
    cin>>Hours_value;
    my.setHours(Hours_value);
   
   
    cout<<"Enter Minutes: "<<endl;
    cin>>Minutes_value;
    my.setMinutes(Minutes_value);

   
    cout<<"Enter Seconds: "<<endl;
    cin>>Seconds_value;
    my.setSeconds(Seconds_value);

   
   
   
    my.UniversalPrint();
   
    system("pause");
   
     
}

Sunday, 11 May 2014

calculater Programe in C


·         #include <stdio.h>
·         #include <conio.h>
·         int main ()
·         {
·          
·          char c;
·          int a, b, res,d;
·         printf("Select one of era-thematic operation "
"to perfume the following operations: \n+\n-\n*\n/\"
"nEnter you's choice: ");
scanf("%c",&c);

switch(c)
{
case '+' :
 printf("Enter 1st Number:");
 scanf("%d",&a);
 printf("\nEnter 2nd Number:");
 scanf("%d",&b);
 res=a+b;
 printf("%d + %d= %d",a,b,res);

break;

 case '-':
 printf("Enter 1st Number:");
    scanf("%d",&a);
 printf("\nEnter 2nd Number:");
 scanf("%d",&b);
 res=a-b;
 printf("%d - %d= %d",a,b,res);
break;

case '*':
 printf("Enter 1st Number:");
 scanf("%d",&a);
 printf("\nEnter 2nd Number:");
 scanf("%d",&b);
 res=a*b;
 printf("%d * %d= %d",a,b,res);
break;

case '/':
 printf("Enter 1st Number:");
 scanf("%d",&a);
 printf("\nEnter 2nd Number:");
 scanf("%d",&b);
 res=a/b;
 printf("%d / %d= %d",a,b,res);
break;

default:
  printf("Invalid Entry");
}


getch();
return 0;



}