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;



}