Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CplusplusCourse - outdated
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Sebastien Ponce
CplusplusCourse - outdated
Merge requests
!15
Add some oo exercise
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add some oo exercise
chamont/cpluspluscourse:add-some-oo-exercise
into
master
Overview
4
Commits
12
Pipelines
0
Changes
6
Merged
David Chamont
requested to merge
chamont/cpluspluscourse:add-some-oo-exercise
into
master
4 years ago
Overview
4
Commits
12
Pipelines
0
Changes
6
Expand
0
0
Merge request reports
Compare
master
version 2
0528b7c0
4 years ago
version 1
a815adbf
4 years ago
master (base)
and
latest version
latest version
b3f1547a
12 commits,
4 years ago
version 2
0528b7c0
5 commits,
4 years ago
version 1
a815adbf
4 commits,
4 years ago
6 files
+
119
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
6
Search (e.g. *.vue) (Ctrl+P)
code/modern_oo/solution/particles.sol.cpp
0 → 100644
+
50
−
0
Options
#include
<cstdlib>
// pour std::rand()
#include
<iostream>
#include
<string>
class
Particle
{
public
:
Particle
(
double
mass
)
:
mass_
(
mass
)
{}
Particle
(
const
Particle
&
)
=
delete
;
virtual
~
Particle
()
=
default
;
double
mass
()
{
return
mass_
;
}
virtual
std
::
string
name
()
{
return
"Particle"
;
}
private
:
double
mass_
;
}
;
class
ChargedParticle
:
public
Particle
{
public
:
ChargedParticle
(
double
mass
,
double
charge
)
:
Particle
(
mass
),
charge_
(
charge
)
{}
double
charge
()
{
return
charge_
;
}
std
::
string
name
()
override
{
return
"ChargedParticle"
;
}
private
:
double
charge_
=
0.0
;
}
;
void
display
(
Particle
&
p
)
{
std
::
cout
<<
p
.
name
()
<<
std
::
endl
;
std
::
cout
<<
" mass = "
<<
p
.
mass
()
<<
std
::
endl
;
}
int
main
()
{
for
(
int
i
=
0
;
i
<
5
;
++
i
)
{
if
(
std
::
rand
()
<
(
0.5
*
double
(
RAND_MAX
))
)
{
Particle
p
(
2
)
;
display
(
p
)
;
}
else
{
ChargedParticle
p
(
1
,
1
)
;
display
(
p
)
;
std
::
cout
<<
" charge = "
<<
p
.
charge
()
<<
std
::
endl
;
}
}
}
\ No newline at end of file
Loading