Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wektor_cpp
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
wektor_cpp
Commits
88c368b2
Commit
88c368b2
authored
Apr 29, 2026
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
typedef aby w jednym miejscu określić typ
parent
010aee55
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
17 deletions
+21
-17
program.cpp
program.cpp
+1
-1
wektor.cpp
wektor.cpp
+9
-9
wektor.h
wektor.h
+11
-7
No files found.
program.cpp
View file @
88c368b2
...
@@ -10,7 +10,7 @@ int main() {
...
@@ -10,7 +10,7 @@ int main() {
w
.
push_back
(
12
);
w
.
push_back
(
12
);
std
::
cout
<<
"Element nr 0: "
<<
w
.
get
(
0
)
<<
'\n'
;
std
::
cout
<<
"Element nr 0: "
<<
w
.
get
(
0
)
<<
'\n'
;
std
::
cout
<<
"Element nr 2: "
<<
w
.
get
(
2
)
<<
'\n'
;
std
::
cout
<<
"Element nr 2: "
<<
w
.
get
(
2
)
<<
'\n'
;
w
.
set
(
2
,
22
2
);
w
.
set
(
2
,
22
);
std
::
cout
<<
"Element nr 2: "
<<
w
.
get
(
2
)
<<
'\n'
;
std
::
cout
<<
"Element nr 2: "
<<
w
.
get
(
2
)
<<
'\n'
;
std
::
cout
<<
"size: "
<<
w
.
size
()
<<
'\n'
;
std
::
cout
<<
"size: "
<<
w
.
size
()
<<
'\n'
;
std
::
cout
<<
'\n'
;
std
::
cout
<<
'\n'
;
...
...
wektor.cpp
View file @
88c368b2
#include <iostream>
#include <iostream>
#include "wektor.h"
#include "wektor.h"
const
int
startowy_rozmiar_tablicy
=
8
;
const
TypIndeksu
startowy_rozmiar_tablicy
=
8
;
Wektor
::
Wektor
()
Wektor
::
Wektor
()
:
rozmiar_tablicy
{
startowy_rozmiar_tablicy
},
:
rozmiar_tablicy
{
startowy_rozmiar_tablicy
},
liczba_elementow
{
0
}
liczba_elementow
{
0
}
{
{
t
=
new
int
[
rozmiar_tablicy
];
t
=
new
TypWartosci
[
rozmiar_tablicy
];
}
}
Wektor
::~
Wektor
()
{
Wektor
::~
Wektor
()
{
delete
[]
t
;
delete
[]
t
;
}
}
int
Wektor
::
size
()
const
{
TypIndeksu
Wektor
::
size
()
const
{
return
liczba_elementow
;
return
liczba_elementow
;
}
}
void
Wektor
::
push_back
(
int
e
)
{
void
Wektor
::
push_back
(
TypWartosci
e
)
{
if
(
liczba_elementow
==
rozmiar_tablicy
)
{
if
(
liczba_elementow
==
rozmiar_tablicy
)
{
// przerzuć elementy do większej tablicy
// przerzuć elementy do większej tablicy
rozmiar_tablicy
=
2
*
rozmiar_tablicy
;
rozmiar_tablicy
=
2
*
rozmiar_tablicy
;
int
*
nt
=
new
int
[
rozmiar_tablicy
];
TypWartosci
*
nt
=
new
TypWartosci
[
rozmiar_tablicy
];
for
(
int
i
=
0
;
i
<
liczba_elementow
;
i
++
)
{
for
(
TypIndeksu
i
=
0
;
i
<
liczba_elementow
;
i
++
)
{
nt
[
i
]
=
t
[
i
];
nt
[
i
]
=
t
[
i
];
}
}
delete
[]
t
;
delete
[]
t
;
...
@@ -32,14 +32,14 @@ void Wektor::push_back(int e) {
...
@@ -32,14 +32,14 @@ void Wektor::push_back(int e) {
t
[
liczba_elementow
++
]
=
e
;
t
[
liczba_elementow
++
]
=
e
;
}
}
void
Wektor
::
set
(
int
idx
,
int
e
)
{
void
Wektor
::
set
(
TypIndeksu
idx
,
TypWartosci
e
)
{
if
(
idx
<
0
||
idx
>=
liczba_elementow
)
{
if
(
idx
<
0
||
idx
>=
liczba_elementow
)
{
throw
"indeks poza zakresem"
;
throw
"indeks poza zakresem"
;
}
}
t
[
idx
]
=
e
;
t
[
idx
]
=
e
;
}
}
int
Wektor
::
get
(
int
idx
)
{
TypWartosci
Wektor
::
get
(
TypIndeksu
idx
)
{
if
(
idx
<
0
||
idx
>=
liczba_elementow
)
{
if
(
idx
<
0
||
idx
>=
liczba_elementow
)
{
throw
"indeks poza zakresem"
;
throw
"indeks poza zakresem"
;
}
}
...
@@ -48,7 +48,7 @@ int Wektor::get(int idx) {
...
@@ -48,7 +48,7 @@ int Wektor::get(int idx) {
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
Wektor
&
w
)
{
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
Wektor
&
w
)
{
out
<<
'['
;
out
<<
'['
;
for
(
int
i
=
0
;
i
<
w
.
liczba_elementow
;
i
++
)
{
for
(
TypIndeksu
i
=
0
;
i
<
w
.
liczba_elementow
;
i
++
)
{
out
<<
w
.
t
[
i
]
<<
", "
;
out
<<
w
.
t
[
i
]
<<
", "
;
}
}
out
<<
']'
;
out
<<
']'
;
...
...
wektor.h
View file @
88c368b2
...
@@ -3,31 +3,35 @@
...
@@ -3,31 +3,35 @@
#include <iostream>
#include <iostream>
typedef
int
TypWartosci
;
typedef
unsigned
int
TypIndeksu
;
/** Tablica zmiennej długości zawierająca wartości int. */
/** Tablica zmiennej długości zawierająca wartości int. */
class
Wektor
{
class
Wektor
{
int
*
t
;
TypWartosci
*
t
;
// fizyczny rozmiar wewnętrznej tablicy
// fizyczny rozmiar wewnętrznej tablicy
int
rozmiar_tablicy
;
TypIndeksu
rozmiar_tablicy
;
// logiczny rozmiar wektora = ile pozycji w tablicy jest zajętych = indeks pierwszej wolnej pozycji
// logiczny rozmiar wektora = ile pozycji w tablicy jest zajętych = indeks pierwszej wolnej pozycji
int
liczba_elementow
;
TypIndeksu
liczba_elementow
;
// powinno być liczba_elementow <= rozmiar_tablicy
public
:
public
:
Wektor
();
Wektor
();
~
Wektor
();
~
Wektor
();
int
size
()
const
;
TypIndeksu
size
()
const
;
/** Dodanie nowego elementu na końcu. */
/** Dodanie nowego elementu na końcu. */
void
push_back
(
int
e
);
void
push_back
(
TypWartosci
e
);
/** Przypisanie nowej wartości na podanej pozycji. */
/** Przypisanie nowej wartości na podanej pozycji. */
void
set
(
int
idx
,
int
e
);
void
set
(
TypIndeksu
idx
,
TypWartosci
e
);
/** Odczyt wartości spod podanej pozycji. */
/** Odczyt wartości spod podanej pozycji. */
int
get
(
int
idx
);
TypWartosci
get
(
TypIndeksu
idx
);
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
Wektor
&
);
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
Wektor
&
);
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment