C++ program to extract the elements in the odd positions of an array that are stored into an another array.
This is very easy to do.
#include<conio.h>
#include<iostream.h>
#include<stdio.h>
#include<string.h>
class extract
{
public: char sent[25],extd[25];
int l;
void get()
{
cout<<"\nType the sentance:\n"<<endl;
gets(sent);
cout<<"OK"<<endl<<endl;
}
int filter();
void disp(int r);
};
int extract::filter()
{
int i,j;
l=strlen(sent);
for(j=0,i=0;i<l;i=i+2,j++)
{
extd[j]=sent[i];
}
return j;
};
void extract::disp(int r)
{
int i;
for(i=0;i<r;i++)
cout<<extd[i];
};
void main()
{
clrscr();
extract t;
t.get();
int g=t.filter();
t.disp(g);
getch();
}
__________________________________________________
try this and share it!
Comments
Post a Comment