Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PPC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tomáš Pachman
PPC
Commits
56de65d9
Commit
56de65d9
authored
2 weeks ago
by
Tomáš Pachman
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
0de3d380
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cviceni/class.cpp
+99
-0
99 additions, 0 deletions
cviceni/class.cpp
with
99 additions
and
0 deletions
cviceni/class.cpp
0 → 100644
+
99
−
0
View file @
56de65d9
#include
<iostream>
#include
<sstream>
#include
<ctime>
#define LEN 20
class
MyRandom
{
private:
int
seed
;
int
state
;
static
int
pocet_objektu
;
public:
int
rand
();
static
int
getObjNum
(){
return
pocet_objektu
;
}
//*konstruktor
MyRandom
();
MyRandom
(
int
seed
);
//*destruktor
///vsechno uvolni
~
MyRandom
(){
std
::
cerr
<<
"zavolan destruktor"
<<
std
::
endl
;
pocet_objektu
--
;
};
};
int
MyRandom
::
pocet_objektu
=
0
;
//*definice defaultniho konstruktoru
MyRandom
::
MyRandom
(){
pocet_objektu
++
;
seed
=
time
(
NULL
);
state
=
seed
;
std
::
cerr
<<
"zavolan defautni konstruktor"
<<
std
::
endl
;
}
//*parametrizovany konstruktor
MyRandom
::
MyRandom
(
int
seed
){
pocet_objektu
++
;
seed
=
seed
;
state
=
seed
;
std
::
cerr
<<
"zavolam parametrizovany konstruktor"
<<
std
::
endl
;
}
//*musim pridat namespace (MyRadom) abych se dostal ke clenske funkci
int
MyRandom
::
rand
(
void
){
state
=
(
state
*
1103515245
+
12345
)
&
((
1U
<<
31
)
-
1
);
//*vracim hornich 16 bitu->15bit cislo
return
state
>>
16
;
//+0...32767
}
int
main
(
int
argc
,
char
*
argv
[]){
int
*
parr
=
new
int
[
LEN
];
if
(
parr
==
NULL
){
std
::
cerr
<<
"alokace se nepovedla"
<<
std
::
endl
;
return
1
;
}
int
seed
=
time
(
NULL
);
if
(
argc
>
1
){
std
::
istringstream
iss
(
argv
[
1
]);
iss
>>
seed
;
//if(!iss.good())
if
(
!
iss
){
std
::
cerr
<<
"chyba argumentu"
<<
std
::
endl
;
std
::
cerr
<<
"pouziti:"
<<
argv
[
0
]
<<
" [seed]"
<<
std
::
endl
;
delete
[]
parr
;
return
2
;
}
}
std
::
cerr
<<
"pocet instanci MyRandom:"
<<
MyRandom
::
getObjNum
()
<<
std
::
endl
;
MyRandom
rnd
;
std
::
cerr
<<
"pocet instanci MyRandom:"
<<
MyRandom
::
getObjNum
()
<<
std
::
endl
;
MyRandom
rnd2
(
seed
);
std
::
cerr
<<
"pocet instanci MyRandom:"
<<
MyRandom
::
getObjNum
()
<<
std
::
endl
;
MyRandom
*
prnd
=
new
MyRandom
(
seed
);
std
::
cerr
<<
"pocet instanci MyRandom:"
<<
MyRandom
::
getObjNum
()
<<
std
::
endl
;
for
(
int
idx
=
0
;
idx
<
LEN
;
idx
++
){
//parr[idx]=rnd.rand() %30;
parr
[
idx
]
=
rnd2
.
rand
()
%
30
;
//parr[idx]=rand() & (32-1);
std
::
cout
<<
parr
[
idx
]
<<
", "
;
}
std
::
cout
<<
std
::
endl
;
delete
prnd
;
std
::
cerr
<<
"pocet instanci MyRandom:"
<<
MyRandom
::
getObjNum
()
<<
std
::
endl
;
delete
[]
parr
;
//+uvolnime co jsme vzali
return
0
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment