Sunteți pe pagina 1din 3

Write a c++ program to read some characters from a file and display the no of bs

used.

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
void main()
{
clrscr();
int i,c=0;
char a[30];
ifstream fin("New.txt",ios::in);
fin.getline(a,30,'\n');
for(i=0;a[i]!=NULL;i++)
{
if(a[i]=='b')
c++;
}
cout<<"the no of b's are"<<c;
}

Write a c++ program to insert the names and balance of some persons in a file.

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdio.h>
struct customer{char name[30];
float balance;
} savac;
void main()
{
clrscr();
ofstream fout("input.txt",ios::out);
char ch='y';
while(ch=='y')
{
cout<<"enter customer name \n";
gets(savac.name);
cout<<"\n enter customer balance \n";
cin>>savac.balance;
fout.write((char*)&savac,sizeof (customer));
cout<<"will you continue...(y/n)\n ";
cin>>ch;
}
fout.close();
}

Write a c++ program to display the persons getting bonus by reading from the file
prepared in the previous program.

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdio.h>
struct cust{char name[30];
float balance;
}savac1;
void main()
{
clrscr();
int t;
ifstream fin("input.txt",ios::in);
cout<<"the people awarded with bonus \n";
while(!fin.eof())
{
t=0;
fin.read((char*)&savac1,sizeof (cust));
if(savac1.balance>=1000)
{
cout<<"name:"<<savac1.name<<"\n";
t=savac1.balance+(0.1* savac1.balance);
cout<<"new balance="<<t;
}
}
fin.close();
}

S-ar putea să vă placă și