Total Pageviews

PRASO's Solution for EMBETRONIX & ROBOTIX

SOLUTION PROVIDER OF ANY SORT OF PROBLEMS RELATED TO ELECTRONICS AND TELECOMMUNICATION

Monday, February 28, 2011

EMBETRONIX AND ROBOTIX: All the features of C++ are Demonstrated in One Program

All the features of C++ are Demonstrated in One Program

All the features of C++ are Demonstrated in One Program

#include"iostream"
using namespace std;

class Height
{
    private:
        int feet, inches;
    public:
        /* Default Constructor */

        Height()
        {
            feet=0;
            inches=0;
        }
       
        /* Parametrized Constructor */

        Height(int temp)
        {
            feet=temp;
            inches=temp;
        }

        /*Parametrized Constructor */

        Height(int a, int b)
        {
            feet=a;
            inches=b;
        }
       
        /* Copy Constructor */
       
        Height(const Height &ht)
        {
            feet=ht.feet;
            inches=ht.inches;
        }

        /* Member Function to set Values */

        void setValues()
        {
            cout<<"Enter dimension in feet";
            cin>>feet;
            cout<<"Enter dimension in inches";
            cin>>inches;
           
        }

        /* Overloaded Member Function to set values e:g: if the dimension is 2 feet 5 inches*/

        void setValues(int a, int b)
        {
            feet=a;
            inches=b;
        }

        /* Overloaded Member Function to set values e:g: if the dimension is 5 feet 5 inches*/

        void setValues(int a)
        {
            feet=a;
            inches=a;
        }

        /* Member Function to print the Dimension */
       
        void print()
        {
            cout<<<" feet "<<<" inches "<
        }

        /* '+' Operator Overloading */

        Height operator + (Height x)
        {
            Height sum;
            inches = (feet*12) + inches;
            x.inches = (x.feet*12) + x.inches;
            sum.feet = (inches + x.inches)/12;
            sum.inches = (inches + x.inches)%12;
            return sum;
        }
       
        /* '-' Operator Overloading */

        Height operator - (Height x)
        {
            Height gap;
            inches = (feet*12) + inches;
            x.inches = (x.feet*12) + x.inches;
            gap.feet = absolute((inches - x.inches))/12;
            gap.inches = absolute((inches - x.inches))%12;
            return gap;
        }

        /* function Which will operate as Modulo Operator */
       
        int absolute (int num)
        {
            if(num<0)
                return (-num);
            else
                return (num);
        }       
};


int main()
{

Height Ant;
cout<<"Height of Ant is:"<
Ant.print();

Height table(2,8);
cout<<"Height of Table is:"<
table.print();

Height ku;
ku = table + Ant;
cout<<"Height of ku is:"<
ku.print();

Height stick(2);
cout<<"Height of Stick is:"<
stick.print();

Height dog;
dog = table-stick;
cout<<"Height of dog is:"<
dog.print();

Height RosePlant;
RosePlant.setValues(1,4);
cout<<"Height of RosePlant is:"<
RosePlant.print();

Height HebiscusPlant;
HebiscusPlant = RosePlant + stick - Ant + dog;
cout<<"Height of HebiscusPlant is:"<
HebiscusPlant.print();

Height cosmos=RosePlant;
cout<<"Height of cosmos is:"<
cosmos.print();

return 0;
}




OUTPUT:

somanath@ubuntu:~/programs/CPP/28feb$ g++ Height.cpp
somanath@ubuntu:~/programs/CPP/28feb$ ./a.out
Height of Ant is:
0 feet 0 inches
Height of Table is:
2 feet 8 inches
Height of ku is:
2 feet 8 inches
Height of Stick is:
2 feet 2 inches
Height of dog is:
2 feet 6 inches
Height of RosePlant is:
1 feet 4 inches
Height of HebiscusPlant is:
6 feet 0 inches
Height of cosmos is:
1 feet 16 inches

Sunday, February 27, 2011

Copy the contents of source file to TARGET file using command line argument in C

#include"stdio.h"
main(int argc, char **argv)
{
FILE *s_ptr , *t_ptr;
char ch,c;

    if(argc!=3)
    {
        printf("ERROR: Invalid no. of Arguments\n");
        printf("Usage: copy \n");
        return;
    }

s_ptr = fopen(argv[1],"r");
   
    if(s_ptr==NULL)
    {       
        printf("Source File not Found\n");
        return;
    }

t_ptr = fopen(argv[2],"r+");
   
    if(t_ptr==NULL)
    {       
        printf("Target File not Found\n");
        printf("Do you want to create it (Y/N):\n");
        scanf(" %c",&ch);
        if(ch=='y' || ch=='Y')
        {
            t_ptr = fopen(argv[2],"w");
            while((c=fgetc(s_ptr))!=EOF)       
                    fputc(c,t_ptr);
        }
        else
            return;
    }
fclose(s_ptr);
fclose(t_ptr);
}

Renaming a File Using command Line Argument in 'C'

#include
main(int argc, char **argv)
{
FILE *s_ptr , *t_ptr;
char ch,c;

    if(argc!=3)
    {
        printf("ERROR: Invalid no. of Arguments\n");
        printf("Usage: copy \n");
        return;
    }

s_ptr = fopen(argv[1],"r");
   
    if(s_ptr==NULL)
    {       
        printf("Source File not Found\n");
        return;
    }

t_ptr = fopen(argv[2],"r+");
   
    if(t_ptr==NULL)
    {       
            t_ptr = fopen(argv[2],"w");
            while((c=fgetc(s_ptr))!=EOF)       
                    fputc(c,t_ptr);
    }
       
fclose(s_ptr);
fclose(t_ptr);\   
remove(argv[1]);
}

EMBETRONIX AND ROBOTIX: Enter Date Month Year and get the Exact Day...

EMBETRONIX AND ROBOTIX: Enter Date Month Year and get the Exact Day...

Enter Date Month Year and get the Exact Day...

This is the C Program....................  Calender.c  ................... Run it and check it out... If there is any fault, then in4m..... Comments are welcome....

#include
#include
main()
{
int date, month, year, days, nyear;
int x,y,k,weeks,new, remainder;
int odd_days, total_odd_days,leap_odd_days,leapyear_odd_days;
printf("Enter date-month-year");
scanf("%d%d%d",&date,&month,&year);

nyear=year-1;
x=nyear%100;
new=nyear-x;
remainder=new%400;

if(remainder%400==0)
leap_odd_days=0;
if(remainder%400==100)
leap_odd_days=5;
if(remainder%400==200)
leap_odd_days=3;
if(remainder%400==300)
leap_odd_days=1;

y=x/4;
k=(y+x)%7;

leapyear_odd_days=k+leap_odd_days;


    if(month==1)
        days=date;
    else if(month==2)
        days=31+date;
    else if(month==3)
    {
        if(year%4==0)
            days=31+29+date;
        else
            days=31+28+date;
    }

    else if(month==4)
    {
        if(year%4==0)
            days=31+29+31+date;
        else
            days=31+28+31+date;
    }

    else if(month==5)
    {
        if(year%4==0)       
            days=31+29+31+30+date;
        else
            days=31+28+31+30+date;
    }

    else if(month==6)
    {
        if(year%4==0)
            days=31+29+31+30+31+date;
        else
            days=31+28+31+30+31+date;
    }

    else if(month==7)
    {
        if(year%4==0)
            days=31+29+31+30+31+30+date;
        else
            days=31+28+31+30+31+30+date;
    }

    else if(month==8)
    {
        if(year%4==0)
            days=31+29+31+30+31+30+31+date;
        else
            days=31+28+31+30+31+30+31+date;
    }

    else if(month==9)
    {
        if(year%4==0)
            days=31+29+31+30+31+30+31+31+date;
        else
            days=31+28+31+30+31+30+31+31+date;
    }

    else if(month==10)
    {
        if(year%4==0)
            days=31+29+31+30+31+30+31+31+30+date;
        else
            days=31+28+31+30+31+30+31+31+30+date;
    }

    else if(month==11)
    {
        if(year%4==0)
            days=31+29+31+30+31+30+31+31+30+31+date;
        else
            days=31+28+31+30+31+30+31+31+30+31+date;
    }           

    else if(month==12)
    {
        if(year%4==0)
            days=31+29+31+30+31+30+31+31+30+31+30+date;
        else
            days=31+28+31+30+31+30+31+31+30+31+30+date;
    }

weeks=days/7;
odd_days=days%7;

total_odd_days=leapyear_odd_days + odd_days;

if((total_odd_days % 7 )== 0)
printf("\nSUNDAY");

if((total_odd_days % 7 )== 1)
printf("\nMONDAY");

if((total_odd_days % 7 )== 2)
printf("\nTUESDAY");

if((total_odd_days % 7 )== 3)
printf("\nWEDNESDAY");

if((total_odd_days % 7 )== 4)
printf("\nTHURSDAY");

if((total_odd_days % 7 )== 5)
printf("\nFRIDAY");

if((total_odd_days % 7 )== 6)
printf("\nSATURDAY");

printf("\n");
}

555 Timer Pulse generation

The simplest 555 oscillator takes output pin 3 to capacitor C1 via resistor R1. When the circuit is turned on, C1 is uncharged and output pin 3 is HIGH. C1 charges via R1 and when Pin 6 detects 2/3 rail voltage, output pin 3 goes LOW. R1 now discharges capacitor C1 and when pin 2 detects 1/3 rail voltage, output pin 3 goes HIGH to repeat the cycle.
The amount of time when the output is HIGH is called the MARK and the time when the output is LOW is called the SPACE. In the diagram the mark is the same length as the space and this is called 1:1 or 50%:50%. If a resistor and capacitor (or electrolytic) is placed on the output, the result is very similar to a sinewave.