You are on page 1of 13

1

1
2#include <iostream>
3using namespace std;
4
5enum
6{
7
Star,
8
Normal
9};
10
11// =)
12int line(unsigned LineType)
13{
14
switch(LineType)
15
{
16
case Star:
17
{
18
cout << endl;
19
20
for(int i = 0; i < 50; i++) {
21
cout << '*'; }

22
23
cout << endl << endl;
24
}
25
case Normal:
26
{
27
cout << endl;
28
29
for(int i = 0; i < 50; i++) {
30
cout << '_'; }
31
32
cout << endl << endl;
33
}
34
}
35}
36
37int main()
38{
39
int n;
40
cout << "Razmer matritsi A (n): "; cin >> n;
41
42
line(Normal);
43
44
//
45
int A[n][n];
46
cout << "Zapolnite matritsu A[" << n << "][" << n << "]:" << endl;
47
48
line(Normal);
49
50
//
51
for(int i = 0; i < n; i++)
52
{
53
for(int j = 0; j < n; j++)
54
{
55
cout << "A[" << i + 1 << "][" << j + 1 << "] = "; cin >> A[i][j];
56
}
57
}
58
59
line(Star);
60
61
cout << "Polucennaea matritsa:" << endl;

1
2Laboratotul numarul 2

1
2
line(Normal);
3
4
//
5
for(int i = 0; i < n; i++)
6
{
7
for(int j = 0; j < n; j++)
8
{
9
cout << A[i][j] << " ";
10
}
11
cout << endl;
12
}
13
14
line(Star);
15
16
// ,
17
int x, y;
18
cout << "Vvedite koordinati dlea redactirovania (1 - " << n << ")" << endl;
19
cout << "Liniea (i): "; cin >> x; //
20
cout << "Kolona (j): "; cin >> y; // y
21
22
line(Normal);
23
24
if((x < 1 || x > n) || (y < 1 || y > n)) //,
25 !
26
{
27
cout << "Element matritsi A[" << x << "][" << y << "] otsutstvuet !" <<
28endl;
29
}
30
else
31
{
32
//
33
cout << "Element A[" << x << "][" << y << "] = " << A[x-1][y-1] << endl;
34
35
//
36
cout << "Vvidite novoe znacenie A[" << x << "][" << y << "] = "; cin >>
37A[x-1][y-1];
38
39
line(Star);
40
41
cout << "Polucennaea matritsa:" << endl;
42
43
line(Normal);
44
45
//
46
for(int i = 0; i < n; i++)
47
{
48
for(int j = 0; j < n; j++)
49
{
50
cout << A[i][j] << " ";
51
}
52
cout << endl;
53
}
54
}
55
56
cout << endl;
57
58
system("pause");
59}

1
2Laboratotul numarul 2

1
2
2#include <cstdlib>
3#include <iostream>
4
5using namespace std;
6
7enum
8{
9
Deni,
10
Meseats,
11
God,
12
Imea,
13
Familia,
14
Grupa,
15
16
TOTAL_NUM
17};
18
19struct student
20{
21
char StudentInfo[20][TOTAL_NUM]; // .
22};
23
24enum
25{
26
Star,
27
Normal,
28
29
TOTAL_LINE
30};
31
32// =)
33int line(unsigned LineType)
34{
35
switch(LineType)
36
{
37
case Star:
38
{
39
cout << endl;
40
41
for(int i = 0; i < 50; i++) {
42
cout << '*'; }
43
44
cout << endl << endl;
45
}
46
case Normal:
47
{
48
cout << endl;
49
50
for(int i = 0; i < 50; i++) {
51
cout << '_'; }
52
53
cout << endl << endl;
54
}
55
}
56}
57
58
59
60
61int main()

1
2Laboratotul numarul 2

1{
2
unsigned int n;
3
cout << "Vsego studenov (n): "; cin >> n;
4
5
line(Normal);
6
7
struct student Info[n];
8
cout << "Daite inf. o " << n << "-h" << " studentah." << endl;
9
10
line(Normal);
11
12
// .
13
for(int i = 0; i < n; i++)
14
{
15
cout << "Imea " << i + 1 << "-go studenta: "; cin >>
16Info[i].StudentInfo[Imea];
17
cout << "Familia " << i + 1 << "-go studenta: "; cin >>
18Info[i].StudentInfo[Familia];
19
cout << "Grupa " << i + 1 << "-go studenta: "; cin >>
20Info[i].StudentInfo[Grupa];
21
cout << "Deni rojdenia " << i + 1 << "-go studenta: "; cin >>
22Info[i].StudentInfo[Deni];
23
cout << "Meseats rojdenia " << i + 1 << "-go studenta: "; cin >>
24Info[i].StudentInfo[Meseats];
25
cout << "God rojdenia " << i + 1 << "-go studenta: "; cin >>
26Info[i].StudentInfo[God];
27
28
line(Normal);
29
}
30
31
line(Star);
32
33
//
34
for(int i = 0; i < n; i++)
35
{
36
for(int x = 0; x < TOTAL_NUM; x++)
37
{
38
cout << Info[i].StudentInfo[x];
39
40
if(x == God || x == Imea || x == Familia)
41
cout << " | ";
42
else if(x == TOTAL_NUM - 1)
43
cout << endl;
44
else
45
cout << "/";
46
}
47
48
line(Normal);
49
}
50
51
line(Star);
52
cout << "Vsego zapolneno inf. o " << n << "-h studentah." << endl;
53
line(Star);
54
55
//
56
int k;
57
cout << "Kakogo studenta redaktirovati? (n): "; cin >> k;
58
59
line(Normal);
60
61

1
2Laboratotul numarul 2

1
2
3
4
// .
5
cout << "Imea " << k << "-go studenta: "; cin >> Info[k-1].StudentInfo[Imea];
6
cout << "Familia " << k << "-go studenta: "; cin >> Info[k-1].StudentInfo[Familia];
7
cout << "Grupa " << k << "-go studenta: "; cin >> Info[k-1].StudentInfo[Grupa];
8
cout << "Deni rojdenia " << k << "-go studenta: "; cin >> Info[k91].StudentInfo[Deni];
10
cout << "Meseats rojdenia " << k << "-go studenta: "; cin >> Info[k111].StudentInfo[Meseats];
12
cout << "God rojdenia " << k << "-go studenta: "; cin >> Info[k-1].StudentInfo[God];
13
14
line(Normal);
15
16
// . , , .
17
for(int i = 0; i < n; i++)
18
{
19
for(int x = 0; x < TOTAL_NUM; x++)
20
{
21
cout << Info[i].StudentInfo[x];
22
23
if(x == God || x == Imea || x == Familia)
24
cout << " | ";
25
else if(x == TOTAL_NUM - 1)
26
cout << endl;
27
else
28
cout << "/";
29
}
30
31
line(Normal);
32
}
33
34
line(Star);
35
36
system("pause");
37}

1
2Laboratotul numarul 2

1
3
2#include <cstdlib>
3#include <iostream>
4
5using namespace std;
6
7enum
8{
9
Star,
10
Normal,
11
12
TOTAL_LINE
13};
14
15// =)
16int line(unsigned LineType)
17{
18
switch(LineType)
19
{
20
case Star:
21
{
22
cout << endl;
23
24
for(int i = 0; i < 50; i++) {
25
cout << '*'; }
26
cout << endl << endl;
27
}
28
case Normal:
29
{
30
cout << endl;
31
32
for(int i = 0; i < 50; i++) {
33
cout << '_'; }
34
cout << endl << endl;
35
}
36
}
37}
38
39class student
40{
41
private:
42
char nume[20];
43
char prenume[20];
44
char grupa[10];
45
int day;
46
int month;
47
int year;
48
public:
49
int Vvod(int a)
50
{
51
cout << "Imea " << a + 1 << "-go studenta: ";
cin >> nume;
52
cout << "Familia " << a + 1 << "-go studenta: ";
53
cin >> prenume;
54
cout << "Grupa " << a + 1 << "-go studenta: ";
cin >>
55grupa;
56
cout << "Deni rojdenia " << a + 1 << "-go studenta: ";
cin >>
57day;
58
cout << "Meseats rojdenia " << a + 1 << "-go studenta: ";
59
cin >> month;
60
cout << "God rojdenia " << a + 1 << "-go studenta: "; cin >>
61year;

1
2Laboratotul numarul 2

1
2
line(Normal);
3
}
4
5
int Vivod()
6
{
7
cout
8
<<
9
nume
10
<<
11
"|"
12
<<
13
prenume
14
<<
15
"|"
16
<<
17
grupa
18
<<
19
"|"
20
<<
21
day
22
<<
23
"/"
24
<<
25
month
26
<<
27
"/"
28
<<
29
year
30
<<
31
endl;
32
33
line(Normal);
34
}
35};
36
37int main()
38{
39
unsigned int n;
40
cout << "Vsego studenov (n): "; cin >> n;
41
42
line(Normal);
43
44
student Info[n];
45
cout << "Daite inf. o " << n << "-h" << " studentah." << endl;
46
47
line(Normal);
48
49
// .
50
for(int i = 0; i < n; i++)
51
{
52
Info[i].Vvod(i);
53
}
54
55
line(Star);
56
57
58
//
59
for(int i = 0; i < n; i++)
60
{
61
Info[i].Vivod();

1
2Laboratotul numarul 2

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}

}
line(Star);
cout << "Vsego zapolneno inf. o " << n << "-h studentah." << endl;
line(Star);
//
int k;
cout << "Kakogo studenta redaktirovati? (n): "; cin >> k;
line(Normal);
// .
Info[k-1].Vvod(k-1);
line(Normal);
// . , , .
for(int i = 0; i < n; i++)
{
Info[i].Vivod();
}
line(Star);
system("pause");

1
2Laboratotul numarul 2

1
4
2#include <iostream>
3
4using namespace std;
5
6enum
7{
8
Star,
9
Normal,
10
11
TOTAL_LINE
12};
13
14// =)
15int line(unsigned LineType)
16{
17
switch(LineType)
18
{
19
case Star:
20
{
21
cout << endl;
22
23
for(int i = 0; i < 50; i++) {
24
cout << '*'; }
25
26
cout << endl << endl;
27
}
28
case Normal:
29
{
30
cout << endl;
31
32
for(int i = 0; i < 50; i++) {
33
cout << '_'; }
34
35
cout << endl << endl;
36
}
37
}
38}
39
40int main()
41{
42
int n; cout << "Razmer matritsi A (n): "; cin >> n;
43
44
line(Normal);
45
46
//
47
int A[n][n];
48
cout << "Zapolnite matritsu A[" << n << "][" << n << "]:" << endl;
49
50
line(Normal);
51
52
//
53
for(int i = 0; i < n; i++)
54
{
55
for(int j = 0; j < n; j++) {
56
cout << "A[" << i + 1 << "][" << j + 1 << "] = "; cin >> A[i][j]; }
57
}
58
59
line(Star);
60
cout << "Polucennaea matritsa:" << endl;
61

1
2Laboratotul numarul 2

1
line(Normal);
2
3
//
4
for(int i = 0; i < n; i++)
5
{
6
for(int j = 0; j < n; j++)
7
{
8
cout << A[i][j] << " ";
9
}
10
cout << endl;
11
}
12
13
line(Star);
14
15
// ,
16
int x, y;
17
cout << "Vvedite koordinati dlea redactirovania (1 - " << n << ")" << endl;
18
cout << "Liniea (i): "; cin >> x; //
19
cout << "Kolona (j): "; cin >> y; // y
20
21
line(Normal);
22
23
if((x < 1 || x > n) || (y < 1 || y > n)) //,
24 !
25
cout << "Element matritsi A[" << x << "][" << y << "] otsutstvuet !" <<
26endl;
27
else
28
{
29
//
30
cout << "Element A[" << x << "][" << y << "] = ";
31
32
int *p;// (pointer)
33
p = &A[x-1][y-1];
34
35
cout << *p << endl;
36
37
//
38
cout << "Vvidite novoe znacenie A[" << x << "][" << y << "] = "; cin >> *p;
39
40
line(Star);
41
42
cout << "Polucennaea matritsa:" << endl;
43
44
line(Normal);
45
46
//
47
for(int i = 0; i < n; i++)
48
{
49
for(int j = 0; j < n; j++)
50
{
51
cout << A[i][j] << " ";
52
}
53
cout << endl;
54
}
55
}
56
57
cout << endl;
58
system("pause");
59}
60#include <iostream.h>
61#include <string.h>

1
2Laboratotul numarul 2

10

1#include <stdlib.h>
2
3/* */
4struct Student
5{
6 char Name[20]; //
7
char NameLast[30]; //
8 int Age; //
9 char School[30]; //
10
11 void Input(Student &student); //
12 Student *Next; //
13};
14class List
15{
16 Student *Head; //
17public:
18 List():Head(NULL){}; // (Head=NULL)
19 ~List();//
20 void Add(Student &student);
21 void Show();
22};
23
24/* */
25void Student::Input(Student &student)
26{
27 cout<<endl; //
28 cout<<": "; cin.getline(Name,20); //
29 cout<<": ";cin.getline(NameLast,30); //
30 cout<<" ";cin>>Age; //
31 cin.ignore(); //
32 cout<<" ";cin.getline(School,30); //
33}
34
35 List::~List() // List
36{
37
while (Head!=NULL) // -
38
{
39
Student *temp=Head->Next; //
40
41
delete Head; //
42
Head=temp; //
43
}
44}
45/* */
46 void List::Add(Student &student)
47 {
48
Student *temp=new Student; //
49
temp->Next=Head; //,
50
51// student
52
strcpy(temp->Name,student.Name);
53
strcpy(temp->NameLast,student.NameLast);
54
temp->Age=student.Age;
55
strcpy(temp->School,student.School);
56
57
Head=temp; //
58 }
59/* LIST */
60 void List::Show()
61 {

1
2Laboratotul numarul 2

11

1
Student *temp=Head; //
2
3
while (temp!=NULL) // -
4
{
5
//
6
cout<<temp->Name<<"tt"; //
7
cout<<temp->NameLast<<"tt"; //
8
cout<<temp->Age<<"tt"; //
9
cout<<temp->School<<endl; //
10
11
temp=temp->Next; //
12
}
13
cout<<endl;
14 }
15
16int main ()
17{
18 Student student; // ,
19 int N; // -
20 List lst; // .
21
22 cout<<"N = ";cin>>N; //
23 cin.ignore(); // Enter
24
25 for (int i=0;i<N;i++)
26 {
27
student.Input(student); //
28
lst.Add(student); //
29 }
30
31 cout<<endl;
32 lst.Show(); //
33 system("PAUSE");
34}
35
36

37http://ci-plus-plus-snachala.ru/?p=57

1
2Laboratotul numarul 2

12

1 2
2()
3
4
1. . .
5
()
6
, ,
7
(, ) .
8

9
. .
10
11
2. ( ),
12
:
13
;
14
;
15
, , ;
16
.
17
.
18

19
.
20
21
3. .
22
23
4. .
24

1
2Laboratotul numarul 2

13