Ввод-Вывод файлов В С++

Автор работы: Пользователь скрыл имя, 10 Декабря 2011 в 01:48, лабораторная работа

Описание

Изучение реализации в языке С++ возможностей ввода-вывода файлов.

Работа состоит из  1 файл

kursovoy.doc

— 1.29 Мб (Скачать документ)

Министрерство образования и науки Украины 
 
 
 

Кафедра  
 
 

ОТЧЕТ

по лабораторной работе №4

по дисциплине: «Объектно-ориентированное программирование»

тема: ВВОД-ВЫВОД ФАЙЛОВ В С++ 
 
 
 
 
 

Выполнил:                                                                                                     Проверил: 
 
 
 
 
 

Харьков 2011

     1 Цель лабораторной работы:

Изучение реализации в языке С++ возможностей ввода-вывода файлов. 

     2 Задание лабораторной работы:

Дан файл с текстом. Определить, сколько слов состоит из одинаковых букв. 

     4 Текст программы:

#include "stdafx.h"

#include "iostream"

#include "fstream"

#include "conio.h"

using namespace std; 

char B[10000];

int k,i,p,d; 

int _tmain(int argc, _TCHAR* argv[])

{

      setlocale(LC_CTYPE, "");

      ifstream f("d:\\1234.txt");

      if(!f) cout<<"Невозможно открыть файл";

      f.get(B,10000,'EOF'); 

      while(B[i]!=false)

      {

            cout<<B[i];

            i++;

      }

      cout<<endl<<endl;

      i=0;

      while(B[i]!=false&&B[i-1]!=true)

      {

            if(B[i]!='.'&&B[i]!=','&&B[i]!=' '&&B[i]!='!'&&B[i]!='?'&&B[i]!='('&&

         B[i]!=')'&&B[i]!=':'&&B[i]!='-'&&B[i]!=';'&&B[i]!='"'&&B[i]!='['&&

         B[i]!=']'&&B[i]!='{'&&B[i]!='}'&&B[i]!='«'&&B[i]!='»'&&B[i]!='1'&&

            B[i]!='2'&&B[i]!='3'&&B[i]!='4'&&B[i]!='5'&&B[i]!='6'&&B[i]!='7'&&

            B[i]!='8'&&B[i]!='9'&&B[i]!='0'&&B[i]!='--')

            {

                  k++;   

            }

            else

            {

                  switch(k)

                  {

                        case 1:

                              p++;

                              k=0;

                              continue; 

                        case 2:

                              if(B[i-1]==B[i-2])

                                    p++;

                              k=0;

                              continue; 

                        case 3:

                              if(B[i-1]==B[i-2]&&B[i-2]==B[i-3])

                                    p++;

                              k=0;

                              continue; 

                        case 4:

                              if(B[i-1]==B[i-2]&&B[i-2]==B[i-3]&&B[i-3]==B[i-4])

                                    p++;

                              k=0;

                              continue; 

                        case 5:

                              if(B[i-1]==B[i-2]&&B[i-2]==B[i-3]&&B[i-3]==B[i-4]&&

                  B[i-4]==B[i-5])

                                    p++;

                              k=0;

                              continue; 

                        case 6:

                              if(B[i-1]==B[i-2]&&B[i-2]==B[i-3]&&B[i-3]==B[i-4]&&

               B[i-4]==B[i-5]&&B[i-5]==B[i-6])

                                    p++;

                              k=0;

                              continue; 

                        case 7:

                              if(B[i-1]==B[i-2]&&B[i-2]==B[i-3]&&B[i-3]==B[i-4]&&

               B[i-4]==B[i-5]&&B[i-5]==B[i-6]&&B[i-6]==B[i-7])

                                    p++;

                              k=0;

                              continue; 

                        case 8:

                              if(B[i-1]==B[i-2]&&B[i-2]==B[i-3]&&B[i-3]==B[i-4]&&

                                     B[i-4]==B[i-5]&&B[i-5]==B[i-6]&&B[i-6]==B[i-7]&&

                                 B[i-7]==B[i-8])

                                    p++;

                              k=0;

                              continue; 

                        case 9:

                              if(B[i-1]==B[i-2]&&B[i-2]==B[i-3]&&B[i-3]==B[i-4]&&

                                     B[i-4]==B[i-5]&&B[i-5]==B[i-6]&&B[i-6]==B[i-7]&&

                                 B[i-7]==B[i-8]&&B[i-8]==B[i-9])

                                    p++;

                              k=0;

                              continue; 

                        case 10:

                              if(B[i-1]==B[i-2]&&B[i-2]==B[i-3]&&B[i-3]==B[i-4]&&

                                     B[i-4]==B[i-5]&&B[i-5]==B[i-6]&&B[i-6]==B[i-7]&&

                                 B[i-7]==B[i-8]&&B[i-8]==B[i-9]&&B[i-9]==B[i-10])

                                    p++;

                              k=0;

                              continue; 

                        case 11:

                              if(B[i-1]==B[i-2]&&B[i-2]==B[i-3]&&B[i-3]==B[i-4]&&

                                     B[i-4]==B[i-5]&&B[i-5]==B[i-6]&&B[i-6]==B[i-7]&&

                                 B[i-7]==B[i-8]&&B[i-8]==B[i-9]&&B[i-9]==B[i-10]&&

                                     B[i-10]==B[i-11])

                                    p++;

                              k=0;

                              continue; 

                        case 12:

                              if(B[i-1]==B[i-2]&&B[i-2]==B[i-3]&&B[i-3]==B[i-4]&&

                                     B[i-4]==B[i-5]&&B[i-5]==B[i-6]&&B[i-6]==B[i-7]&&

                                 B[i-7]==B[i-8]&&B[i-8]==B[i-9]&&B[i-9]==B[i-10]&&

                                     B[i-10]==B[i-11]&&B[i-11]==B[i-12])

                                    p++;

                              k=0;

                              continue; 

                        case 13:

                              if(B[i-1]==B[i-2]&&B[i-2]==B[i-3]&&B[i-3]==B[i-4]&&

                                     B[i-4]==B[i-5]&&B[i-5]==B[i-6]&&B[i-6]==B[i-7]&&

                                 B[i-7]==B[i-8]&&B[i-8]==B[i-9]&&B[i-9]==B[i-10]&&

                                     B[i-10]==B[i-11]&&B[i-11]==B[i-12]&&B[i-12]==B[i-13])

                                    p++;

                              k=0;

                              continue; 

                        case 14:

                              if(B[i-1]==B[i-2]&&B[i-2]==B[i-3]&&B[i-3]==B[i-4]&&

                                     B[i-4]==B[i-5]&&B[i-5]==B[i-6]&&B[i-6]==B[i-7]&&

Информация о работе Ввод-Вывод файлов В С++