Sie sind auf Seite 1von 40

INDEX

S.NO Particulars Sign

1 WAP that reads in two integers and determines and


prints if first is a multiple of second.

2 A mail order house sells five different products whose


retail prices one product1- 40.95/-, Prod 2- 99.15/-,
Prod 3- 127.50/-, Prod4- 265/-, Prod5- 796.10/-. WAP to
read a series of pairs of numbers i.e. Product no. ,
quantity sold for one day. Use Switch statement to
determine the retail price for each product. Program
should calculate and display the total retail value of all
products sold last week.

3 WAP to generate Fibonacci series using recursion.

4 WAP to implement function overloading using suitable


example.

5 WAP to implement inline function circlearea to prompt the


user for the radius of a circle and to calculate and print the
area of a circle.

6 WAP to show three functions which is used to triplicate the


value of num defined in main. One function accepts the
parameter with call by value, second through call by
reference and third by call by address.

7 WAP to read in 20 numbers, each of which is between 10


and 100 inclusive. As each read, print it only if it is not a
duplicate of a number already read. Provide for worst case
in which all 20 numbers are different.

8 WAP using recursion to return the smallest integer of


array.

9 WAP to count the number of occurrence of a character in a


string. Example in beautiful occurrence of u is 2.

10 WAP for following Problem.

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
A department store chain has m (<=10) stores and
each store has departments the weekly sales of the
chain are stored in m x n array sales.
a) Print the total weekly sales of each store.
b) Print the total weekly sales of each department.
c) Print the total weekly sales of each chain..
11 WAP for given matrix A of order m x n .WAP to find row
having the maximum number of negative elements.

12 Define a structure that contains three members name of


state, name of capital of state, name of CM of state. Using
this structure, WAP to handle the query
a) To print name of capital and CM on input of
name of state.
b) To print name of state and capital on input of
name of CM.
c) To print name of state and CM on input of capital.
13 WAP to create a class employee and compute bonus in
such a way if salary is<5000 then bonus 10% otherwise
15%.

14 WAP to create a class customer and Compute bill in


such a way:

Minimum Rs 200 for up to 100 calls.


Plus Rs 0.60 per call for next 50 calls.
Plus Rs 0.50 per call for next 50 calls.
Plus Rs 0.40 per call for any call beyond 200 calls

15 WAP to create student class and generate roll no with


help of static variable and display list of students as per
records.

16 WAP to create class inventory and arrange items in list


as per their attributes

17 WAP to create class date and create constructors


(default, parameterized, copy) to initialize data
members.

18 WAP to create class complex and perform addition and

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
subtraction (using objects as arguments).

19 WAP to implement friend function to compare the


result of two classes containing member as (Roll no,
Marks).

20 WAP to calculate interest on balance of saving a/c of


customer Using static data member and member
function for interest rate.

21 WAP to overload operators (+,-,*) to model a matrix


size m*n.

22 WAP to overload operators (<,>,<=,>=,==,!=) on string


class .

23 WAP to illustrate the need of destructor.

24 WAP to converting currency from one system to


another in different classes

25 WAP to illustrate data conversion (class to class)

26 WAP to illustrate data conversion (basic data type to


class)

27 WAP to illustrate data conversion (class to basic data


type)

28 WAP to demonstrate the use of pure virtual


functions.

29 WAP to Create a class named shape and define a


pure virtual function named draw().Create classes
named rectangle, square, circle and triangle that
inherit from shape class and provide the class
specific implementation of draw() in each of these
derived classes. Create objects of these derived
classes and store their addresses in an array of
type pointer to shape class. Write a polymorphic
program that walks through the array and involves
draw () method. This walk continues till user strikes

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
any key.

30 Assume that a bank maintains two types of Account


saving and current. The saving account provides
compound interest, cash deposit and cash withdrawal
facilities but no check book facility. The current
account provides no interest, no cash deposit and no
cash withdrawal facilities but provide check book
facility. However, the current account holder needs to
main certain minimum balance otherwise a service
charge is imposed. Create a class account with data
members account holders name, account number and
opening balance. From the account class, derive two
classes saving and current to model saving account
and current account respectively.

31 Assume that a publishing company markets a print


book and digital book. Create a class name publication
with data members named title, price and author
name. From publication class derive to classes named
book and e-book. The book class adds a page count
data member named p_count while e-book adds a
data member playing time named p_time. Each of
these classes must have member function get_data()
to read class specific data from keyboard and display
data() to output the class specific data to the computer
screen. Write a program to test these classes.

32 A small organization wish to maintain a database


of its employees. Following data the relationship
between classes representing employees of the
organization.

33 WAP that read some text from the keyboard and


write into a file. The program then read this file
and displays its contents on the computer screen.

34 WAP to copy the contents of one file byte by byte.

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
The names of files are taken as command line
argument.

35 WAP that prompts the user to input name of text


file read this file and output the number of vowels
and number of words in the text.

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
WAP that reads in two integers and determines and prints if first is a
multiple of second.

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
int r,s;
clrscr();
cout<<"Enter first number =";
cin>>r;
cout<<"Enter second number =";
cin>>s;
if((s%r==0))
cout<<r<<" is multiple of ="<<s<<endl;
else
cout<<r<<"is not multiple of = "<<s<<endl;
getch();
}

Output:

Enter first number =9


Enter second number =9999
9 is multiple of =9999

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
VISIT www.educationjockey.com for old papers, practical file samples.
This file is for reference purpose only.
A mail order house sells five different products whose retail prices one
product1- 40.95/-, Prod 2- 99.15/-, Prod 3- 127.50/-, Prod4- 265/-, Prod5-
796.10/-. WAP to read a series of pairs of numbers i.e. Product no. ,
quantity sold for one day. Use Switch statement to determine the retail
price for each product. Program should calculate and display the total
retail value of all products sold last week.

#include<iomanip.h>
#include<iostream.h>
#include<conio.h>
void main()
{
int n,q,c1,c2,c3,c4,c5;
float price,s1,s2,s3,s4,s5;
char ch;
float sum;
clrscr();
do
{
cout<<"product 1:Rs 40.95 \nproduct 2:Rs 99.15 \nproduct 3:Rs 127.50
\nproduct 4:Rs 265 \nproduct 5:Rs 796.10";
cout<<"\nenter product no:";
cin>>n;
cout<<"\nenter qty:";
cin>>q;
switch(n)
{
case 1:
c1++;
price=40.95;
s1=s1+(price*q);
break;
case 2:
c2++;
price=99.15;
s2=s2+(price*q);
break;
VISIT www.educationjockey.com for old papers, practical file samples.
This file is for reference purpose only.
case 3:
c3++;
price=127.50;
s3=s3+(price*q);
break;
case 4:
c4++;
price=265.00;
s4=s4+(price*q);
break;
case 5:
c5++;
price=796.10;
s5=s5+(price*q);
break;
}
cout<<"do u want to continue:";
cin>>ch;
}while(ch=='y' || ch=='Y');
sum=s1+s2+s3+s4+s5;
cout<<"total retail value:"<<sum;
getch();
}

Output:

product 1:Rs 40.95


product 2:Rs 99.15
product 3:Rs 127.50
product 4:Rs 265
product 5:Rs 796.10
enter product no:1

enter qty:25
do u want to continue:n
total retail value:1023.75

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
VISIT www.educationjockey.com for old papers, practical file samples.
This file is for reference purpose only.
WAP to generate fibonacci series using recursion

void fibo(int,int,int,int);
#include<conio.h>
#include<iomanip.h>
#include<iostream.h>
void main()
{
int n,a=0,b=1,i=3;
clrscr();
cout<<"\n enter no of terms u want to display:";
cin>>n;
cout<<"\n FABONACCI SERIES";
if(n==1)
cout<<"\n"<<a;
else
{
cout<<"\n"<<a<<"\n"<<b;
fibo(a,b,n,i);
}
getch();
}
void fibo(int a,int b,int n,int i)
{
int c;
if(i<=n)
{
c=a+b;
cout<<"\n"<<c;
a=b;
b=c;
i++;
fibo(a,b,n,i);

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
}
}
Output:

Enter the number of terms to be genrated:5


0 1 1 2 3 5

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
WAP to implement function overloading using suitable example

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void sqr(int);
void sqr(int,int);
void main()
{
int a,b;
clrscr();
cout<<"Enter first number = ";
cin>>a;
cout<<"Enter second number = ";
cin>>b;
sqr(a);
sqr(a,b);
getch();
}
void sqr(int x)
{
int y=x*x;
cout<<"square is = "<<y<<endl;
}
void sqr(int x,int y)
{
int z;
z=x*y;
cout<<"product is = "<<z;
}

Output:

Enter first number = 5


Enter second number = 25
square is = 25
VISIT www.educationjockey.com for old papers, practical file samples.
This file is for reference purpose only.
product is = 125
WAP to implement inline function circlearea to prompt the user for the
radius of a circle and to calculate and print the area of a circle.

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#define PI 3.14159
inline float circlearea(float r)
{
float area;
area=PI*r*r;
return(area);
}
void main()
{
float radius;
clrscr();
cout<<"Enter radius of circle";
cin>>radius;
cout<<"Area of circle is = "<<circlearea(radius);
getch();
}

Output:

Enter radius of circle = 25


Area of circle is = 1963.493774

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
WAP to show three functions which is used to triplicate the value of
num defined in main. One function accepts the parameter with call by
value , second through call by reference and third by call by address.

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
int value(int);
int adress(int*);
int reference(int&);
void main()
{
int a;
clrscr();
cout<<"Enter any number ";
cin>>a;
cout<<"triplicate value using call by value = "<<value(a)<<endl;
cout<<"triplicate value using call by adress = "<<adress(&a)<<endl;
cout<<"triplicate value using call by reference = "<<reference(a)<<endl;
getch();
}
int value(int a)
{
return(a*a*a);
}
int adress(int *a)
{
return((*a)*(*a)*(*a));
}
int reference(int &a)
{
return(a*a*a);
}

Output:
VISIT www.educationjockey.com for old papers, practical file samples.
This file is for reference purpose only.
Enter any number 25
triplicate value using call by value = 15625
triplicate value using call by adress = 15625
triplicate value using call by reference = 15625

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
WAP to read in 20 numbers, each of which is between 10 and 100
inclusive. As each read, print it only if it is not a duplicate of a number
already read. Provide for worst case in which all 20 numbers are
different

#include<iomanip.h>
#include<iostream.h>
#include<conio.h>
void main()
{
int arr[20],a[20];
clrscr();
int p=0;
int fl=0;
cout<<"Enter 20 nos(10-100)inclusive:";
for(int i=0;i<20;i++)
{
cin>>arr[i];
for(int j=0;j<i;j++)
{
if(arr[i]==arr[j])
{
fl=1;
break;
}
}
if(fl!=1)
a[p++]=arr[i];
}
cout<<"Elements are ";
for(i=0;i<p;i++)
{
cout<<endl<<a[i];
}
if(p==20)
{
cout<<"\nElements are unique";
}

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
getch();
}
Output:

Enter 20 nos(10-100)inclusive:55
54
52
58
59
57
65
64
62
63
67
12
22
23
30
47
85
99
97
11
Elements are
55
54
52
58
59
57
65
64
62
63
67
12
22

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
23
30
47
85
99
97
11

Elements are unique

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
WAP using recursion to return the smallest integer of array

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
int rec(int[],int);
void main()
{
int a[15],n,min,i;
clrscr();
cout<<"Enter the size of array";
cin>>n;
cout<<"Enter the element of array";
for(i=0;i<n;i++)
{
cin>>a[i];
}
min=rec(a,n);
cout<<"Minimum number is = "<<min;
getch();
}

int rec(int a[],int n)


{
int min;
if(n==1)
{
return(a[0]);
}
else
{
min=rec(a,n-1);
if(min<a[n-1])
{
return(min);
}
else
{

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
return(a[n-1]);
}
}
}

Output:

Enter the size of array = 5


Enter the element of array 46
49
12
55
65
Minimum number is = 12

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
WAP to count the number of occurrence of a character in a string.
Example in beautiful occurrence of u is 2.

#include<conio.h>
#include<iostream.h>
# include<string.h>
void main()
{
char str[50],ch;
int count=0;
int i,n;
clrscr();
cout<<"Enter any character :";
cin>>str;
cout<<endl;
n=strlen(str);
cout<<"Enter the chracter which you want to search: \n" ;
cin>>ch;
for(i=0;i<n;i++)
{
if(ch==str[i])
{
count++;
}
}
cout<<"The character "<<ch<<" occur "<<count<<" Times\n";
getch();
}

Output:

Enter any character :Neelam


Enter the chracter which you want to search: e
The character e occur 2 Times
VISIT www.educationjockey.com for old papers, practical file samples.
This file is for reference purpose only.
VISIT www.educationjockey.com for old papers, practical file samples.
This file is for reference purpose only.
WAP for following Problem.: A department store chain has m (<=10)
stores and each store has same n (<=15) departments the weekly sales of
the chain are stored in m x n array sales.

a) Print the total weekly sales of each store.


b) Print the total weekly sales of each department.
c) Print the total weekly sales of each chain.

#include<conio.h>
#include<iomanip.h>
#include<iostream.h>
void main()
{
int a[10][15],m,n,sum=0,sumc=0,sumr=0;
clrscr();
cout<<"\nenter no of stores in chain(<=10) and department in each
store(<=15):";
cin>>m>>n;
cout<<"enter weekly sales of each dept:";
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
cout<<"\nenter weekly sale of "<<i+1<<" store's"<<j+1<<"dept:";
cin>>a[i][j];
}
}
for(i=0;i<m;i++)
{
sumr=0;
for(int j=0;j<n;j++)
{
sum+=a[i][j];
sumr+=a[i][j];
}
cout<<"\ntotal weekly sales of "<<i+1<<" store: "<<sumr;

}
VISIT www.educationjockey.com for old papers, practical file samples.
This file is for reference purpose only.
for(int j=0;j<n;j++)
{
sumc=0;
for(int i=0;i<m;i++)
{
sumc+=a[i][j];
}
cout<<"\ntotal weekly sales of "<<j+1<<" dept: "<<sumc;
}
cout<<"\n total weekly sales of chain:"<<sum;
getch();
}

Output:

enter no of stores in chain(<=10) and department in each store(<=15):3


3
enter weekly sales of each dept:
enter weekly sale of 1 store's1dept:10
enter weekly sale of 1 store's2dept:11
enter weekly sale of 1 store's3dept:12
enter weekly sale of 2 store's1dept:10
enter weekly sale of 2 store's2dept:22
enter weekly sale of 2 store's3dept:23
enter weekly sale of 3 store's1dept:22
enter weekly sale of 3 store's2dept:23
enter weekly sale of 3 store's3dept:24

total weekly sales of 1 store: 33


total weekly sales of 2 store: 55
total weekly sales of 3 store: 69
total weekly sales of 1 dept: 42
total weekly sales of 2 dept: 56
total weekly sales of 3 dept: 59
total weekly sales of chain:157

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
WAP for given matrix A of order m x n .WAP to find row having the
maximum number of negative elements.

#include<conio.h>
#include<iomanip.h>
#include<iostream.h>
void main()
{
int a[20][20],m,n,count=0,c[20][20],max=0,max1=0;
clrscr();
cout<<"enter rows and columns of matrix:\n";
cin>>m>>n;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
cin>>a[i][j];
}
}
for(i=0;i<m;i++)
{
count=0;
for(int j=0;j<n;j++)
{
if(a[i][j]<0)
{
c[i][j]=++count;
}
if(max<count)
{
max=count;
max1=i+1;
}
}
cout<<"row containing no of negative terms"<<i+1<<":"<<count<<endl;
}

cout<<"row containing maximum no of negative elements:"<<max1;

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
getch();
}

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
Output:

enter rows and columns of matrix:


3
3
Matrix of order 3*3
1 2 -3
456
5 -1 -7
row containing no of negative terms1:1
row containing no of negative terms2:0
row containing no of negative terms3:2
row containing maximum no of negative elements:3

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
Define a structure that contains three members name of state, name
of capital of state, name of CM of state. Using this structure, WAP to
handle the query

a) To print name of capital and CM on input of name of state.


b) To print name of state and capital on input of name of CM.
c) To print name of state and CM on input of capital.

#include<conio.h>
#include<iomanip.h>
#include<iostream.h>
#include<string.h>
struct state
{
char name[20];
char cap[20];
char cm[20];
}s1;
void main()
{
int n;
clrscr();
cout<<"1.to know abt capital of state and its CM\n2.to know abt name of
state and its capital\n3.to know abt name of state and its CM\n";
cout<<"enter your choice\n";
cin>>n;
if(n==1)
{
cout<<"1.punjab\t2.haryana\t3.himachal pradesh\n";
cout<<"enter name of state:";
cin>>s1.name;
if(strcmpi(s1.name,"punjab")==0)
{
cout<<"capital=Chandigarh \t CM=Mr Prakash singh badal\n";
}
else if(strcmpi(s1.name,"haryana")==0)

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
{
cout<<"capital=Chandigarh \t CM=Mr Hooda\n";
}
else if(strcmpi(s1.name,"himachal")==0)
{
cout<<"capital=Shimla \t CM=Mr Dhoomal\n";
}
}
if(n==2)
{
cout<<"1.Mr Prakash singh badal\n2.Hooda\n3.Dhoomal\n";
cout<<"enter name of CM:";
cin>>s1.cm;
if(strcmpi(s1.cm,"Mr Prakash singh badal")==0)
{
cout<<"capital=Chandigarh\t State=Punjab\n";
}
else if(strcmpi(s1.cm,"Hooda")==0)
{
cout<<"capital=Chandigarh\t State=Haryana\n";
}
else if(strcmpi(s1.cm,"Dhoomal")==0)
{
cout<<"capital=Shimla\t State=Himachal Pardesh\n";
}
}
if(n==3)
{
cout<<"1.Chandigarh\n2.Chandigarh\n3.Shimla\n";
cout<<"enter name of Capital:";
cin>>s1.cap;
if(strcmpi(s1.cap,"Chandigarh")==0)
{
cout<<"State=Punjab\t CM=Mr Prakash singh badal\n";
}
else if(strcmpi(s1.cap,"Chandigarh")==0)
{
cout<<"State=Haryana CM=Mr Hooda\n";

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
}
else if(strcmpi(s1.cap,"Shimla")==0)
{
cout<<"State=Himachal Pardesh\t CM=Mr Dhoomal\n";
}
}

getch();
}

Output:

1.to know abt capital of state and its CM


2.to know abt name of state and its capital
3.to know abt name of state and its CM
enter your choice
1
1.punjab 2.haryana 3.himachal pradesh
enter name of state:haryana
capital=Chandigarh CM=Mr Hooda

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
WAP to create a class employee and compute bonus in such a way if
salary is<5000 then bonus 10% otherwise 15%.

#include<iostream.h>
#include<conio.h>
class employee
{
char name[17];
float salary;
float bonus;
public:
void input();
float computebonus(float);
void display();
};
void employee::input()
{
cout<<"\nEnter your name:";
cin>>name;
cout<<"\nEnter your salary:";
cin>>salary;
bonus=computebonus(salary);
}
float employee::computebonus(float a)
{
if(a<5000)
return(((a*10)/100));
else
return(((a*15)/100));
}
void employee::display()
{
cout<<"\nName:"<<name<<"\tSalary:"<<salary<<"\tBonus:"<<bonus;
}
void main()

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
Write A Program to illustrate the need of destructor

#include<conio.h>
#include<iostream.h>
#include<iomanip.h>
int count=0;
class sample
{
public:
sample()
{
count++;
cout<<"\n constructor invoked"<<"\n current object count="<<count<<endl;
}
~sample()
{
count--;
cout<<"\n destructor invoked"<<"\n current object count="<<count<<endl;
}
};
void main()
{
cout<<"\n main block";
sample s1,s2,s3;
{
cout<<"\n first nested block\n";
sample s4;
cout<<" leaving first block";
}
{
cout<<"\n second nested block\n";
sample s5;
cout<<"\n leaving second block";
}
cout<<"\nout of main block";
getch();
}
VISIT www.educationjockey.com for old papers, practical file samples.
This file is for reference purpose only.
Output:

main block
constructor invoked
current object count=1

constructor invoked
current object count=2

constructor invoked
current object count=3

first nested block

constructor invoked
current object count=4
leaving first block
destructor invoked
current object count=3

second nested block

constructor invoked
current object count=4

leaving second block


destructor invoked
current object count=3

out of main block


destructor invoked
current object count=2

destructor invoked
current object count=1

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
destructor invoked
current object count=0

WAP to illustrate data conversion (Basic data type to Class)

#include<iostream.h>
#include<conio.h>
class time
{
int hrs;
int mint;
public:
time()
{
hrs=0;
mint=0;
}
time(int h,int m)
{
hrs=h;
mint=m;
}
time(int m)
{
hrs=m/60;
mint=m%60;
}
void display()
{
cout<<"\nhours"<<hrs<<"\nmint"<<mint;
}
};
void main()
{
clrscr();
time t1,t2(4,65);

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
t1=90;
t1.display();
getch();
}
Output:
hours1
mint30

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
WAP to illustrate data conversion (Class to Basic data type)

#include<iostream.h>
#include<conio.h>
class time
{
int hrs;
int mint;
public:
time()
{
hrs=0;
mint=0;
}
time(int h,int m)
{
hrs=h;
mint=m;
}
operator int()
{
return((hrs*60)+mint);
}
void display()
{
cout<<"\nhours"<<hrs<<"\nmint"<<mint;
}
};
void main()
{
clrscr();
time t1,t2(1,30);
int m=t2;
cout<<m;
getch();
}
Output:
90

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
WAP that read some text from the keyboard and write into a file. The
program then read this file and displays its contents on the computer
screen.

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
void main()
{
clrscr();
fstream file;
file.open("seema.txt",ios::in,ios::out);
int n,i;
char ch[40];
cout<<"Enter number of chars you want to enter :";
cin>>n;
cout<<"\nEnter characters:";
for(i=0;i<n;i++)
{
cin>>ch[i];
file.put(ch[i]);
}
file.seekg(0);
cout<<"\nCharacter read from file:";
for(i=0;i<n;i++)
{
file.get(ch[i]);
cout<<ch[i];
}
getch();
}

Output:

Enter number of chars you want to enter :6

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
Enter characters:sachin

Character read from file:sachin

WAP to copy the contents of one file byte by byte. The names of files are
taken as command line argument.

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
void main(int argc,char *argv[])
{
char ch;
ifstream file1(argv[1],ios::binary);
ofstream file2(argv[2],ios::binary);
if(argc!=3)
cout<<"error in input";
else
while(!file1.eof())
{
file1.get(ch);
file2.put(ch);
}
getch();
}

Output:

D:\>copy sachin.txt sachin1.txt


1 file(s) copied.

D:\>type sachin1.txt
hi i am sachin.

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.
WAP that prompts the user to input name of text file read this file and
output the number of vowels and number of words in the text.

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
void main()
{
clrscr();
int i;
ifstream file("s.txt");
char ch;
cout<<"vowels:";
while(file)
{
file.get(ch);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
cout<<ch;
}
i=file.tellg();
cout<<"\ntotal number of characters"<<i;
getch();
}

Output:

vowels:i
total number of characters3

VISIT www.educationjockey.com for old papers, practical file samples.


This file is for reference purpose only.

Das könnte Ihnen auch gefallen