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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
| #include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
//------------GLOBAL PARAMETRI-----------------------------
FILE *f,*f1,*f2;
int k;
int a[30][30], i, j, r;
//------------------FUNCTIONS------------------------------
void menu();
void create();
void view();
void read();
//------------------------------------------------
void main()
{
menu();
}
//------------------MENU-----------------------------------
void menu()
{
int c;
clrscr();
cout<<"||==============================||"<<endl;
cout<<"|| MENU ||"<<endl;
cout<<"||==============================||"<<endl;
cout<<"|| 1.Create file ||"<<endl;
cout<<"|| 2.Read ||"<<endl;
cout<<"|| 3.Prosmotr ||"<<endl;
cout<<"|| 4.Exit ||"<<endl;
cout<<"||==============================||"<<endl;
cout<<"\nViberite deistvie: ";
do
{
c=getch();
switch(c)
{
case 49: create();
case 50: read();
case 51: view();
case 52: exit(0);
}
}
while((c<49)||(c>52));
}
//--------------------READING-----------------------------
void read()
{
char fname1[10], fname2[10];
clrscr();
cout<<"Vvedite imya faila dlya read: ";
gets(fname1);
f1=fopen(fname1, "r");
cout<<"Vvedite imya faila dlya zapisi: ";
gets(fname2);
f2=fopen(fname2, "w");
fscanf(f1, "%d", &k);
for(i=0; i<k; i++)
for(j=0; j<k; j++)
fscanf(f1, "%d", &a[i][j]);
for(j=0; j<k; j++)
{
r=a[i][j];
a[i][j]=a[j][i];
a[j][i]=r;
}
cout<<"\nTransponirovannaya matrica:\n\n";
for(i=0; i<k; i++)
for(j=0; j<k; j++)
fprintf(f2, "%d", a[j][i]);
cout<<"\nKONEC";
fclose(f1);
fclose(f2);
getch();
menu();
}
//----------------ZAPIS----------------------------
void create()
{
char fname1[10];
clrscr();
cout<<"Vvedite imya faila: ";
gets(fname1);
f1=fopen(fname1, "w");
randomize();
cout<<"Razmernost matrici: k=";
cin>>k;
fprintf(f1, "%d ", k);
for(i=0; i<k; i++)
for(j=0; j<k; j++)
{
a[i][j]=random(30);
fprintf(f1, "%d ", a[i][j]);
}
cout<<endl<<"Zapisano v fail!";
fclose(f1);
getch();
menu();
}
//-----------------------------------------------
void view()
{
char fname[10];
clrscr();
cout<<"Vvedite imya faila dlya read: ";
gets(fname);
f=fopen(fname, "r");
fscanf(f, "%d", &k);
cout << "k=" << k << endl;
for(i=0; i<k; i++)
for(j=0; j<k; j++)
fscanf(f, "%d", &a[i][j]);
fclose(f);
cout<<" matrica:"<<endl;
for(i=0; i<k; i++)
{
for(j=0; j<k; j++)
cout << a[i][j] << " ";
cout << endl;
}
cout<<"\nKONEC";
getch();
menu();
} |