Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
VHB C++ DE
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
VHB Cpp
VHB C++ DE
Commits
21213ad9
Commit
21213ad9
authored
7 months ago
by
Rudi Buss
Browse files
Options
Downloads
Patches
Plain Diff
Update Solution Exercise 1 - Farm.cpp
parent
e91858fa
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/8. Constructor, member initialization list, overloading, destructor, static member variables/Solutions/Solution Exercise 1 - Farm.cpp
+38
-46
38 additions, 46 deletions
...member variables/Solutions/Solution Exercise 1 - Farm.cpp
with
38 additions
and
46 deletions
Part 1/8. Constructor, member initialization list, overloading, destructor, static member variables/Solutions/Solution Exercise 1 - Farm.cpp
+
38
−
46
View file @
21213ad9
#include
<iostream>
#include
<iostream>
using
namespace
std
;
class
Animal
{
private:
float
Revenue
;
float
Weight
;
float
DailyPrice
;
public:
void
Request_data
()
//Declaration and definition of the member function Request_data
{
cout
<<
"How is the daily price?"
<<
endl
;
cin
>>
DailyPrice
;
cout
<<
"What is the weight of the animal? "
<<
endl
;
cin
>>
Weight
;
}
public
:
//Constructor
Animal
()
{
Request_data
();
};
Animal
(
float
w
,
float
p
)
:
Weight
(
w
),
DailyPrice
(
p
)
{
}
//Function
void
Calculate_revenue
()
//Declaration and definition of the member function Calculate_revenue
{
Revenue
=
Weight
*
DailyPrice
;
cout
<<
"Revenue: "
<<
Revenue
<<
endl
;
}
class
Animal
{
private:
float
Revenue
;
float
Weight
;
float
DailyPrice
;
public:
void
Request_data
()
// Declaration and definition of the member function Request_data
{
cout
<<
"How is the daily price?"
<<
endl
;
cin
>>
DailyPrice
;
cout
<<
"What is the weight of the animal? "
<<
endl
;
cin
>>
Weight
;
}
public
:
// Constructor
Animal
()
{
Request_data
();
};
Animal
(
float
w
,
float
p
)
:
Weight
(
w
),
DailyPrice
(
p
)
{}
// Function
void
Calculate_revenue
()
// Declaration and definition of the member function Calculate_revenue
{
Revenue
=
Weight
*
DailyPrice
;
cout
<<
"Revenue: "
<<
Revenue
<<
endl
;
}
};
int
main
()
{
Animal
pig
(
19
,
2.5
);
cout
<<
"Pig "
;
pig
.
Calculate_revenue
();
Animal
cow
;
cout
<<
"Cow "
;
cow
.
Calculate_revenue
();
cout
<<
endl
<<
endl
;
return
0
;
}
int
main
()
{
Animal
pig
(
19
,
2.5
);
cout
<<
"Pig "
;
pig
.
Calculate_revenue
();
Animal
cow
;
cout
<<
"Cow "
;
cow
.
Calculate_revenue
();
cout
<<
endl
<<
endl
;
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