Помогите объединить все эти часту в одну рабочую программу. В кратце о проге: она должна считывать информацию с файла, редактировать ее, часть удалять, искать по фамилии и сохранять обратно в файл по завершении работы.
C++ |
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
| #include <stdio.h>
#include <iostream.h>
#include <conio.h>
#include <fstream.h>
#include <string.h>
# define n 3
//using namespace std;
struct FIO
{
char name [20];
char fam [20];
char ot [20];
};
struct student
{
char name [50];
char adress [50];
int age;
int group;
struct FIO f1;
};
void main()
{
struct student a[3];
clrscr();
int i, j, ind;
char first [20];
ifstream in;
in.open ("c:\\Base_o.txt");
if (in.bad())
{
cout<<"Error";
return;
}
// ofstream out ("c:\\Base_o.txt");
//poisk po familii
for(i=0;i<3;i++)
{
in>>a[i].f1.fam;
in>>a[i].f1.name;
in>>a[i].f1.ot;
in>>a[i].adress;
in>>a[i].age;
in>>a[i].group;
cout<<a[i].f1.fam<<"\t"<<a[i].f1.name<<"\t"<<a[i].f1.ot<<"\t"<<a[i].adress<<"\t"<<a[i].age<<"\t"<<a[i].group<<endl;
}
cout<<"vvedite familiyu dlya poiska\n";
scanf("%s", first);
j=0;
for(i=0;i<n;i++)
if(strcmp (a[i].f1.fam, first)==0)
{
cout<<"\n FIO:\n "<<a[i].f1.fam<<" "<<a[i].f1.name<<" "<<a[i].f1.ot<<"\n age="<<a[i].age<<"\n adress="<<a[i].adress<<"\n group - "<<a[i].group;
j=1;
}
if(j==0)
cout<<"\n zapisey net";
getch();
} |
|
C++ |
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
| #include <iostream>
#include <iterator>
#include <algorithm>
#include <set>
#include <string>
struct FIO
{
char name [20];
char fam [20];
char ot [20];
};
std::istream& operator >> (std::istream &in, FIO &value) {
in >> value.name >> value.fam >> value.ot;
return in;
}
std::ostream &operator << (std::ostream &out, const FIO &value) {
out << value.name << " " << value.fam << " " << value.ot << std::endl;
return out;
}
struct student
{
char name [50];
char adress [50];
int age;
int group;
struct FIO f1;
};
std::istream& operator >> (std::istream &in, student &value) {
in >> value.name >> value.adress >> value.age >> value.group >> value.f1;
return in;
}
std::ostream &operator << (std::ostream &out, const student &value) {
out << value.name << " " << value.adress << " " << value.age
<< " " << value.group << " " << value.f1
<< std::endl;
return out;
}
int main(int argc, char *argv[])
{
student s;
std::cin >> s;
std::cout << s;
return EXIT_SUCCESS;
} |
|
C++ |
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
| #include <iostream>
#include <fstream>
#include <cstdlib>
struct FIO
{
char name [20];
char fam [20];
char ot [20];
void read(std::istream &in) {
in >> name >> fam >> ot;
}
void write(std::ostream &out) {
out << name << " " << fam << " " << ot << std::endl;
}
};
struct student
{
char name [50];
char adress [50];
int age;
int group;
struct FIO f1;
void read(std::istream &in) {
in >> name >> adress >> age >> group;
f1.read(in);
}
void write(std::ostream &out) {
out << name << " " << adress << " " << age << " " << group << " ";
f1.write(out);
out << std::endl;
}
};
int main(int argc, char *argv[])
{
student s;
s.read(std::cin);
s.write(std::cout);
return EXIT_SUCCESS;
} |
|
C++ |
1
2
3
4
5
6
7
8
9
| int main(int argc, char *argv[])
{
student s;
std::ifstream in("input.txt");
s.read(in);
s.write(std::cout);
return EXIT_SUCCESS;
} |
|
Добавлено через 2 минуты
П.с. У меня вышло такое, но оно не очень правильно работает:
C++ |
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
| #include <stdio.h>
#include <iostream>
#include <conio.h>
#include <fstream>
#include <string.h>
#include <fstream>
#include <cstdlib>
# define n 3
using namespace std;
struct FIO
{
char id [20];
char fam [20];
char ot [20];
void read(std::istream &in)
{
in >> id >> fam >> ot;
}
void write(std::ostream &out)
{
out << id << " " << fam << " " << ot << std::endl;
}
};
struct student
{
char name[50];
char adress [50];
int age;
int group;
struct FIO f1;
void read(std::istream &in)
{
cout<<"\n vvedite studenta";
in >> name >> adress >> age >> group;
f1.read(in);
}
void write(std::ostream &out)
{
cout<<"\n vvedite studenta";
out << name << " " << adress << " " << age << " " << group << " ";
f1.write(out);
out << std::endl;
}
};
int ab(int argc, char *argv[])
{
student s;
std::ifstream in("h:\\Base_o1.txt");
s.read(std::cin);
s.write(std::cout);
return EXIT_SUCCESS;
}
/*int main(int argc, char *argv[])
{
student s;
std::ifstream in("h:\\Base_o1.txt");
s.read(in);
s.write(std::cout);
return;
}*/
void main()
{
struct student a[3];
//clrscr();
int i, j, ind;
char first [20];
ifstream in;
in.open ("h:\\Base_o.txt");
if (in.bad())
{
cout<<"Error";
return;
}
// ofstream out ("c:\\Base_o.txt");
int ab(int argc, char *argv[]);
//poisk po familii
for(i=0;i<3;i++)
{
in>>a[i].f1.fam;
in>>a[i].f1.id;
in>>a[i].f1.ot;
in>>a[i].adress;
in>>a[i].age;
in>>a[i].group;
cout<<a[i].f1.fam<<"\t"<<a[i].f1.id<<"\t"<<a[i].f1.ot<<"\t"<<a[i].adress<<"\t"<<a[i].age<<"\t"<<a[i].group<<endl;
}
cout<<"vvedite familiyu dlya poiska\n";
cin>>first;
j=0;
for(i=0;i<n;i++)
if(strcmp (a[i].f1.fam, first)==0)
{
cout<<"\n FIO:\n "<<a[i].f1.fam<<" "<<a[i].f1.id<<" "<<a[i].f1.ot<<"\n age="<<a[i].age<<"\n adress="<<a[i].adress<<"\n group - "<<a[i].group;
j=1;
}
if(j==0)
cout<<"\n zapisey net";
//getch();
} |
|
Добавлено через 2 часа 57 минут
Народ, помогите!
Добавлено через 14 часов 11 минут
еще актуально