Skip to main content

Posts

Showing posts from October, 2013

A program closely resembles to the one used by Adobe Reader

Ultimately, this is a program for searching strings.This program enables us to give a key string to be searched in given set of sentences. The output will be the position at which the given string is present.This can be improved in the C++ platform to exactly mention the string as selected. 
//A Search program closely resembles to the one used by Adobe Reader.

#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<string.h>
class para
{
public:char ckey,skey[10],sent[40];
int i;
void get()
{
cout<<"Type the paragraph of maximum 40 characters, press enter to finish:\n------------------------"<<endl;
gets(sent);
cout<<"---------------------------------------------\nput the letter to be searched:";
cin>>ckey;
cout<<"type the string to be searched:";
gets(skey);
cout<<"processing...\n";
}
void check();

};
void para::check()
{
int l=strlen(sent);
cout<<"\n-------------------------------------\n…

C++ program to extract the elements in the odd positions of an array

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. 
//program to extract elements in the odd positions

#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!

C++ [cpp] Program to find largest and smallest among 3 nnumbers.

Q) Write a C++ [cpp] program to find the largest and smallest among 3 numbers using the concepts of class, object, scope resolution operator & functions.ANSWER_____________________________________________

//find largest & smallest among 3 no:
#include<conio.h>
#include<iostream.h>

class domain
{
public:
int a[3],large,small;
void get();
void check();
void disp()
{
cout<<"\n  largest= "<<large<<endl<<"  smallest= "<<small<<endl<<"\nBYE!";
}
};
void domain::get()
{
int i;
cout<<"Enter 3 numbers:"<<endl;
for(i=0;i<3;i++)
cin>>a[i];
cout<<"OK\n";
};
void domain::check()
{
int i;
large=a[0];
small=a[0];
for(i=0;i<3;i++)
{
if(a[i]>large) large=a[i];
if(a[i]<small) small=a[i];
}
};
void main()
{
clrscr();
domain obj;
obj.get();
obj.check();
obj.disp();
getch();
}
__________________________________________________


Having trouble in executing the program? Suggestions? helps / need help? Shar…

Enumerated Datatypes AND #define

Ooops..! yes, this is an another post related to OOP.
I feel this is some thing nice. There are situations where we want to introduce new data variables. That's why enumerated data types are used. haha, but this is not like u expect! Enumerated DatatypesThese are user defined datatypesthe key-word enum is usedsyntax is enum var_name{var1,vae2,...,varn};what happens is : var1=0, var2=1, var3=2, var4=3,...try the prog. below in ur cpp compiler.#define#define key-word is used.Eg: #define x valueNo ";" is usedadvantage: for a large program, if we want to alter a constant that is repeatedly used throughout the programme.meaning x can be used insted of value.For the perfect understanding, please work on the example below. (Shhhh... it is very simple!) _____________________________________________
// using enumerated data types, #define

#include<conio.h>
#include<iostream.h>
#define num 60
#define name 0

void main()
{
clrscr();

enum b{q,w,e};

cout<<"num ="<<…