C++ (Qt)Выделить код
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
class group
{
char** family;
int** ball;
int max_i;
public:
group();
void set_family(char* s);
void set_balls(int* s, int i);
void get_list();
};
group::group()
{
group::max_i = 0;
group::family = new char* [255];
group::ball = new int* [255];
}
void group::set_family(char* s)
{
group::family[group::max_i] = new char[255];
group::family[group::max_i] = s;
}
void group::set_balls(int* s, int i)
{
group::ball[group::max_i] = new int[i + 1];
group::ball[group::max_i][0] = i;
for (int j = 1; j < i; j++)
group::ball[group::max_i][j] = s[j - 1];
group::max_i++;
}
void group::get_list()
{
int tmp = 0;
double buf = 0;
for (int i = 0; i < group::max_i; i++)
{
cout << group::family[i] << endl;
tmp = group::ball[i][0];
for (int j = 1; j < tmp; j++)
buf += group::ball[i][j];
buf /= tmp;
cout << buf << endl;
cout << "" << endl;
buf = 0;
tmp = 0;
}
}
int main()
{
cout << "Тут";
}
#include <stdio.h>
void viewbooks()
{
FILE *f;
char c, word[50]={0};
int k=0,i,n;
if((f=fopen("books.txt","r"))==NULL)
printf("error");
c=fgetc(f);
n=0;
for(;;)
{
c=fgetc(f);
if(c==EOF)
{
if(n==0)
{
printf("File is empty");
break;
}
printf("date: ");
for(i=0;i<k;i++)
printf("%c",word[i]);
break;
}
word[k]=c;
k++;
if(c=='"' || c==' ')
{
n++;
if(n==1)
printf("book 1:\n");
if(c=='"' && n%3!=0)
printf("name: ");
else if(n%3!=0)
printf("author: ");
if(n%3==0)
printf("date: ");
for(i=0;i<k-1;i++)
printf("%c",word[i]);
for(i=0;i<k;i++)
word[i]=0;
c=fgetc(f);
if(c==EOF)
break;
if(c==' ')
k=0;
else
{
word[0]=c;
k=1;
}
printf("\n");
if(n%3==0)
printf("book %d:\n",n/3+1);
}
}
fclose(f);
}
int main()
{
viewbooks();
return 0;
}
Пример входных данных(в файле books.txt):
"AAA" X.Y.Xyzf 1234
"Bb" A.V.Ytrewq 7777
"" P.M.Qwerty 1011
"" I.U.Qwerty 1113
Выходные данные:
book 1:
name: AAA
author: X.Y.Xyzf
date: 1234
book 2:
name: Bb
author: A.V.Ytrewq
date: 7777
book 3:
name:
author: P.M.Qwerty
date: 1011
book 4:
name:
author: I.U.Qwerty
date: 1113
Примечания:
В файле books.txt название книги должно быть в двойных кавычках. Название книги, автор и дата отделяются друг от друга только одним пробелом.