Thursday, 27 June 2019

programe

Write a C++ program to write number 1 to 100 in a data file NOTES.TXT.
#include <iostream>
#include <conio.h>
#include <fstream>
using namespace std;
int   main()
{
   ofstream fout;
 fout.open("KAT.TXT");
 for(int i=1;i<=100;i++)
  fout<<i<<endl;
 fout.close();
 return 0;
   
} 
simple program to write in text file 
#include <iostream>
#include <fstream>      // std::fstream
using namespace std;
int main () {

  fstream fs;
  fs.open ("test.txt");

  fs << " this line will store in test.txt  file and we can display it on console";

  fs.close();

  return 0;
}
#include <iostream>
#include <conio.h>
#include <fstream>
using namespace std;// read program from all what store in KA1T.TXT file
int   main()
{
   char ch;
   string line; 
   ifstream fin;
 fin.open("KA1T.TXT");
 
 while (fin) { 

          getline(fin, line); 
 
        cout << line << endl; 
}
  fin.close();

  return 0;
  
} 
Write a C++ program, which initializes a string variable to the content "Time is a great teacher but unfortunately it kills all its pupils. Berlioz" and outputs the string to the disk file OUT.TXT. you have to include all the header files if required.
#include<fstream.h>

int main()
{
 ofstream fout;
 fout.open("out.txt");
 char str[300]="Time is a great teacher but unfortunately it kills
  all its pupils. Berlioz";
 fout<<str;
 fout.close();
 return 0;
}
Write a user-defined function in C++ to read the content from a text file OUT.TXT, count and display the number of alphabets present in it.

void alphabets()
{
 ifstream fin;
 fin.open("out.txt");
 char ch;
 int count=0;
 while(!fin.eof())
 {
  fin.get(ch);
  if(isalpha(ch))
   count++;
 }
 cout<<"Number of alphabets in file are "<<count;
 fin.close();
}

Write a function to count the number of blank present in a text file named "OUT.TXT"

void blankspace()
{
 ifstream fin;
 fin.open("out.txt");
 char ch;
 int count=0;
 while(!fin.eof())
 {
  fin.get(ch);
  if(ch==' ')
   count++;
 }
 cout<<"Number of blank spaces in file are "<<count;
 fin.close();
}

No comments:

Post a Comment

Directory implementation

The selection of directory-allocation and directory-management algorithms significantly affects the efficiency, performance, and reliabil...