ОБРОБКА СИМВОЛЬНИХ РЯДКІВ. РОБОТА З ФАЙЛАМИ

Інформація про навчальний заклад

ВУЗ:
Національний університет Львівська політехніка
Інститут:
ІКТА
Факультет:
КН
Кафедра:
Не вказано

Інформація про роботу

Рік:
2017
Тип роботи:
Звіт до лабораторної роботи
Предмет:
Програмування

Частина тексту файла (без зображень, графіків і формул):

МІНІСТЕРСТВО ОСВІТИ І НАУКИ УКРАЇНИ НАЦІОНАЛЬНИЙ УНІВЕРСИТЕТ «ЛЬВІВСЬКА ПОЛІТЕХНІКА» ІКТА кафедра КБ З В І Т до лабораторної роботи №4 з курсу: «Технології програмування» на тему: «ОБРОБКА СИМВОЛЬНИХ РЯДКІВ. РОБОТА З ФАЙЛАМИ» Варіант № 22 Мета роботи – вивчити елементи мови Сі, рядки, рядкові константи, принципи потокового вводу-виводу, стандартні файли і функції для роботи з ними. 1. Завдання 1. Ознайомитися з організацією роботи вводу-виводу в мові Cі. 2. Ознайомитися з потоковим вводом, відкриттям і закриттям потоку в мові Cі. 3. Ознайомитися з стандартними функціями для роботи з файлами в мові Cі. 4. Дано текстовий файл, в якому міститься програма мовою С (Лабораторна робота №3). Скласти блок-схеми алгоритмів та програму мовою С для обробки текстового файлу з використанням розроблених функцій для роботи зі стрічками. Оформити виконання одного із завдань у вигляді підпрограми. Словами є слова в коментарях, назви ідентифікаторів, зарезервовані слова, які розділяються між собою згідно із синтаксисом мови С. Дані для роботи беруться з табл.1 за вказівкою викладача.. 2. Блок-схема алгоритму програми   3. Список ідентифікаторів констант, змінних, функцій, використаних у блок-схемі алгоритму і програмі, та їх пояснення fopen()-функція,яка відкриває файл; fgets()-функція зчитує символи з потоку і зберігає їх у вигляді рядка; i++-збільшення індексу масиву(інкремент); i,n,m,-змінні у функції; strcpy()-функція для копіювання рядків(стрічок); strcat()-функція для обєднання рядків; printf()-функція виведення даних; scanf()-функція введення даних; puts()-функція для виводу рядка на екран; tM-кількість малих букв в рядку; tV-кількість великих букв в рядку; if-умовний оператор; while-оператор циклу з передумовою; for-оператор покрокового циклу; do while-оператор циклу з післяумовою. 4. Текст програми #include <stdio.h> #include <stdlib.h> #include <string.h> int main () { int i,n, m = 0, tM, tV; char str[256][100], temp[100]; char * ptr; FILE *filePtr; if ((filePtr = fopen("input.txt", "r")) == NULL) { printf("File could be not opened.\n"); return 0; } i = 0; while (!feof (filePtr)) { fgets (str[i], 100, filePtr); i++; } n = i; tM = 0; tV = 0; for (i = 0; i < n; i ++) { ptr = str[i]; for (; *ptr; ptr++) { if (*ptr >= 'A' && *ptr <= 'Z') tV++; if (*ptr >= 'a' && *ptr <= 'z') tM++; } tM|tV ? printf ("Line %s has %d small letters and %d big letters\n\n", str[i], tM, tV) : 0 ; tM = 0; tV = 0; } for (i = 0; i < n; i ++) { ptr = str[i]; for (; *ptr; ptr++) { if (*ptr == ';') { strcpy (temp, ptr+1); *ptr = '\0'; strcat (str[i], "END_LINE"); strcat (str[i], temp); } } puts (str[i]); } return 0; } 5. Результати роботи програми Line #include <stdio.h> has 13 small letters and 0 big letters Line #include <stdlib.h> has 14 small letters and 0 big letters Line #include <math.h> has 12 small letters and 0 big letters Line #define n 5 has 7 small letters and 0 big letters Line void sort(int a[n][n]); has 14 small letters and 0 big letters Line void serar(int a[n][n]); has 15 small letters and 0 big letters Line void middleValue(int a[n][n],double b[n]); has 28 small letters and 1 big letters Line void seredHeometrical(double a[n]); has 27 small letters and 1 big letters Line main(void){ has 8 small letters and 0 big letters Line int i,j,k; has 6 small letters and 0 big letters Line int a[n][n]; has 6 small letters and 0 big letters Line double b[n]; has 8 small letters and 0 big letters Line system("cls"); has 9 small letters and 0 big letters Line for(i=0;i<n;i++){ has 7 small letters and 0 big letters Line for(j=0;j<n;j++){ has 7 small letters and 0 big letters Line printf("a[%d][%d]=",i+1,j+1); has 11 small letters and 0 big letters Line scanf("%d",&a[i][j]); has 9 small letters and 0 big letters Line system("cls"); has 9 small letters and 0 big letters Line printf("old array\n"); has 15 small letters and 0 big letters Line for(i=0;i<n;i++){ has 7 small letters and 0 big letters Line for(j=0;j<n;j++){ has 7 small letters and 0 big letters Line printf("%5d",a[i][j]); has 10 small letters and 0 big letters Line printf("\n"); has 7 small letters and 0 big letters Line sort(a); has 5 small letters and 0 big letters Line printf("\nnew array\n"); has 16 small letters and 0 big letters Line for(i=0;i<n;i++){ has 7 small letters and 0 big letters Line for(j=0;j<n;j++){ has 7 small letters and 0 big letters Line printf("%5d",a[i][j]); has 10 small letters and 0 big letters Line printf("\n"); has 7 small letters and 0 big letters Line printf("\n"); has 7 small letters and 0 big letters Line middleValue(a,b); has 12 small letters and 1 big letters Line seredHeometrical(b); has 16 small letters and 1 big letters Line void sort(int a[n][n]){ has 14 small letters and 0 big letters Line int i,k,j,c; has 7 small letters and 0 big letters Line for(i=0;i<n;i++){ has 7 small letters and 0 big letters Line for(k=n-1;k>=0;k--){ has 7 small letters and 0 big letters Line for(j=0;j<k;j++) { has 7 small letters and 0 big letters Line if(a[i][j]<a[i][j+1]){ has 8 small letters and 0 big letters Line c =a[i][j]; has 4 small letters and 0 big letters Line a[i][j]=a[i][j+1]; has 6 small letters and 0 big letters Line a[i][j+1]=c; has 4 small letters and 0 big letters Line void middleValue(int a[n][n],double b[n]){ has 28 small letters and 1 big letters Line int i,j; has 5 small letters and 0 big letters Line double numb = 0; has 10 small letters and 0 big letters Line printf("\n Seredne arifmetuchne \n"); has 26 small letters and 1 big letters Line for (j = 0; j < n; j++) { has 7 small letters and 0 big letters Line for (i = 0; i < n; i++) { has 7 small letters and 0 big letters Line numb+=a[i][j]; has 7 small letters and 0 big letters Line b[j] =numb/n; has 7 small letters and 0 big letters Line numb=0; has 4 small letters and 0 big letters Line for (j = 0; j < n; j++) { has 7 small letters and 0 big letters Line printf("%12lf",b[j]); has 10 small letters and 0 big letters Line void seredHeometrical(double a[n]){ has 27 small letters and 1 big letters Line printf("\n seredne heometruchne \n"); has 27 small letters and 0 big letters Line double number=1.0; has 12 small letters and 0 big letters Line int i; has 4 small letters and 0 big letters Line for (i = 0; i < n; i++) { has 7 small letters and 0 big letters Line number=number*(double)a[i]; has 20 small letters and 0 big letters Line number=pow(fabs(number),1.0/n); has 20 small letters and 0 big letters Line printf("%lf",number); has 14 small letters and 0 big letters #include <stdio.h> #include <stdlib.h> #include <math.h> #define n 5 void sort(int a[n][n])END_LINE void serar(int a[n][n])END_LINE void middleValue(int a[n][n],double b[n])END_LINE void seredHeometrical(double a[n])END_LINE main(void){ int i,j,kEND_LINE int a[n][n]END_LINE double b[n]END_LINE system("cls")END_LINE for(i=0END_LINEi<nEND_LINEi++){ for(j=0END_LINEj<nEND_LINEj++){ printf("a[%d][%d]=",i+1,j+1)END_LINE scanf("%d",&a[i][j])END_LINE } } system("cls")END_LINE printf("old array\n")END_LINE for(i=0END_LINEi<nEND_LINEi++){ for(j=0END_LINEj<nEND_LINEj++){ printf("%5d",a[i][j])END_LINE } printf("\n")END_LINE } sort(a)END_LINE printf("\nnew array\n")END_LINE for(i=0END_LINEi<nEND_LINEi++){ for(j=0END_LINEj<nEND_LINEj++){ printf("%5d",a[i][j])END_LINE } printf("\n")END_LINE } printf("\n")END_LINE middleValue(a,b)END_LINE seredHeometrical(b)END_LINE } void sort(int a[n][n]){ int i,k,j,cEND_LINE for(i=0END_LINEi<nEND_LINEi++){ for(k=n-1END_LINEk>=0END_LINEk--){ for(j=0END_LINEj<kEND_LINEj++) { if(a[i][j]<a[i][j+1]){ c =a[i][j]END_LINE a[i][j]=a[i][j+1]END_LINE a[i][j+1]=cEND_LINE } } } } } void middleValue(int a[n][n],double b[n]){ int i,jEND_LINE double numb = 0END_LINE printf("\n Seredne arifmetuchne \n")END_LINE for (j = 0END_LINE j < nEND_LINE j++) { for (i = 0END_LINE i < nEND_LINE i++) { numb+=a[i][j]END_LINE } b[j] =numb/nEND_LINE numb=0END_LINE } for (j = 0END_LINE j < nEND_LINE j++) { printf("%12lf",b[j])END_LINE } } void seredHeometrical(double a[n]){ printf("\n seredne heometruchne \n")END_LINE double number=1.0END_LINE int iEND_LINE for (i = 0END_LINE i < nEND_LINE i++) { number=number*(double)a[i]END_LINE } number=pow(fabs(number),1.0/n)END_LINE printf("%lf",number)END_LINE } -------------------------------- Process exited after 0.08112 seconds with return value 0 Press any key to continue . . .
Антиботан аватар за замовчуванням

23.01.2017 01:01

Коментарі

Ви не можете залишити коментар. Для цього, будь ласка, увійдіть або зареєструйтесь.

Ділись своїми роботами та отримуй миттєві бонуси!

Нічого не вибрано
0%

Оголошення від адміністратора

Антиботан аватар за замовчуванням

Подякувати Студентському архіву довільною сумою

Admin

26.02.2023 12:38

Дякуємо, що користуєтесь нашим архівом!