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
ceaa48ec
Commit
ceaa48ec
authored
Apr 29, 2026
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Klasa wyjątku IndexOutOfBounds
parent
01002383
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
4 deletions
+30
-4
program.cpp
program.cpp
+2
-2
wektor.cpp
wektor.cpp
+17
-2
wektor.h
wektor.h
+11
-0
No files found.
program.cpp
View file @
ceaa48ec
...
@@ -40,8 +40,8 @@ int main() {
...
@@ -40,8 +40,8 @@ int main() {
try
{
try
{
w
[
50
]
=
5050
;
w
[
50
]
=
5050
;
std
::
cout
<<
"udało się ustawić element 50
\n
"
;
std
::
cout
<<
"udało się ustawić element 50
\n
"
;
}
catch
(
const
char
*
exn
)
{
}
catch
(
IndexOutOfBounds
&
exn
)
{
std
::
cout
<<
"wyjątek "
<<
exn
<<
'\n'
;
std
::
cout
<<
"wyjątek "
<<
exn
.
what
()
<<
'\n'
;
}
}
std
::
cout
<<
"
\n
suma wynosi: "
<<
suma
(
w
)
<<
"
\n\n
"
;
std
::
cout
<<
"
\n
suma wynosi: "
<<
suma
(
w
)
<<
"
\n\n
"
;
...
...
wektor.cpp
View file @
ceaa48ec
#include <iostream>
#include <iostream>
#include <sstream>
#include "wektor.h"
#include "wektor.h"
// Implementacja klasy IndexOutOfBounds
IndexOutOfBounds
::
IndexOutOfBounds
(
TypIndeksu
requested_size
,
TypIndeksu
actual_size
)
:
requested_size
{
requested_size
},
actual_size
{
actual_size
}
{
}
std
::
string
IndexOutOfBounds
::
what
()
{
std
::
stringstream
s
;
s
<<
"Index "
<<
requested_size
<<
" out of bounds ("
<<
actual_size
<<
")"
;
return
s
.
str
();
}
// Implementacja klasy Wektor
// Dla klas, które same zarządzają pamięcią, istotne jest zdefiniowanie
// Dla klas, które same zarządzają pamięcią, istotne jest zdefiniowanie
// w spójny sposób takich elementów klasy, jak:
// w spójny sposób takich elementów klasy, jak:
// - konstruktor kopiujący
// - konstruktor kopiujący
...
@@ -74,14 +89,14 @@ void Wektor::push_back(TypWartosci e) {
...
@@ -74,14 +89,14 @@ void Wektor::push_back(TypWartosci e) {
TypWartosci
Wektor
::
operator
[](
TypIndeksu
idx
)
const
{
TypWartosci
Wektor
::
operator
[](
TypIndeksu
idx
)
const
{
if
(
idx
<
0
||
idx
>=
liczba_elementow
)
{
if
(
idx
<
0
||
idx
>=
liczba_elementow
)
{
throw
"indeks poza zakresem"
;
throw
IndexOutOfBounds
{
idx
,
liczba_elementow
}
;
}
}
return
t
[
idx
];
return
t
[
idx
];
}
}
TypWartosci
&
Wektor
::
operator
[](
TypIndeksu
idx
)
{
TypWartosci
&
Wektor
::
operator
[](
TypIndeksu
idx
)
{
if
(
idx
<
0
||
idx
>=
liczba_elementow
)
{
if
(
idx
<
0
||
idx
>=
liczba_elementow
)
{
throw
"indeks poza zakresem"
;
throw
IndexOutOfBounds
{
idx
,
liczba_elementow
}
;
}
}
return
t
[
idx
];
return
t
[
idx
];
}
}
...
...
wektor.h
View file @
ceaa48ec
...
@@ -2,10 +2,21 @@
...
@@ -2,10 +2,21 @@
#define _WEKTOR_H_
#define _WEKTOR_H_
#include <iostream>
#include <iostream>
#include <exception>
typedef
int
TypWartosci
;
typedef
int
TypWartosci
;
typedef
unsigned
int
TypIndeksu
;
typedef
unsigned
int
TypIndeksu
;
class
IndexOutOfBounds
:
public
std
::
exception
{
public
:
const
TypIndeksu
requested_size
,
actual_size
;
IndexOutOfBounds
(
TypIndeksu
requested_size
,
TypIndeksu
actual_size
);
std
::
string
what
();
};
/** Tablica zmiennej długości zawierająca wartości int. */
/** Tablica zmiennej długości zawierająca wartości int. */
class
Wektor
{
class
Wektor
{
TypWartosci
*
t
;
TypWartosci
*
t
;
...
...
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