Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
VHB C++ EN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package 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
Rudi Buss
VHB C++ EN
Commits
8a978688
Commit
8a978688
authored
7 months ago
by
Rudi Buss
Browse files
Options
Downloads
Patches
Plain Diff
Update Solution Exercise 1 - Animal.cpp
parent
f31ed2e1
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
Part 1/9. Inheritance/Solutions/Solution Exercise 1 - Animal.cpp
+31
-42
31 additions, 42 deletions
...9. Inheritance/Solutions/Solution Exercise 1 - Animal.cpp
with
31 additions
and
42 deletions
Part 1/9. Inheritance/Solutions/Solution Exercise 1 - Animal.cpp
+
31
−
42
View file @
8a978688
...
...
@@ -2,52 +2,41 @@
using
namespace
std
;
class
Animal
{
protected:
float
number
;
public:
Animal
(){};
//Default constructor
Animal
(
int
numb
)
:
number
(
numb
){};
//Constructor with member initialization list
class
Animal
{
protected:
float
number
;
public:
Animal
(){};
// Default constructor
Animal
(
int
numb
)
:
number
(
numb
){};
// Constructor with member initialization list
};
class
SlaughterCattle
:
public
Animal
{
private:
float
weight
;
public:
SlaughterCattle
(
int
numb
,
float
wei
)
:
Animal
(
numb
),
weight
(
wei
){};
void
displaydata
()
{
cout
<<
"There are "
<<
number
<<
" animals with "
<<
weight
<<
" kg each available"
<<
endl
;
}
class
SlaughterCattle
:
public
Animal
{
private:
float
weight
;
public:
SlaughterCattle
(
int
numb
,
float
wei
)
:
Animal
(
numb
),
weight
(
wei
){};
void
displaydata
()
{
cout
<<
"There are "
<<
number
<<
" animals with "
<<
weight
<<
" kg each available"
<<
endl
;
}
};
class
DairyCattle
:
public
Animal
{
private:
float
milkyield
;
public:
DairyCattle
(
int
numb
,
float
m_y
)
:
Animal
(
numb
),
milkyield
(
m_y
){};
void
displaydata
()
{
cout
<<
"There are "
<<
number
<<
" animals with an average milk yield of "
<<
milkyield
<<
" l available"
<<
endl
;
}
class
DairyCattle
:
public
Animal
{
private:
float
milkyield
;
public:
DairyCattle
(
int
numb
,
float
m_y
)
:
Animal
(
numb
),
milkyield
(
m_y
){};
void
displaydata
()
{
cout
<<
"There are "
<<
number
<<
" animals with an average milk yield of "
<<
milkyield
<<
" l available"
<<
endl
;
}
};
int
main
()
{
SlaughterCattle
Pig
(
100
,
50
);
Pig
.
displaydata
();
DairyCattle
Cow
(
25
,
5
);
Cow
.
displaydata
();
return
0
;
}
int
main
()
{
SlaughterCattle
Pig
(
100
,
50
);
Pig
.
displaydata
();
DairyCattle
Cow
(
25
,
5
);
Cow
.
displaydata
();
return
0
;
}
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