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
c02116cc
Commit
c02116cc
authored
6 months ago
by
Rudi Buss
Browse files
Options
Downloads
Patches
Plain Diff
Update Solution Exercise 5 - Farm.cpp
parent
f995593e
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/4. Control structures/Solutions/Solution Exercise 5 - Farm.cpp
+21
-72
21 additions, 72 deletions
...ntrol structures/Solutions/Solution Exercise 5 - Farm.cpp
with
21 additions
and
72 deletions
Part 1/4. Control structures/Solutions/Solution Exercise 5 - Farm.cpp
+
21
−
72
View file @
c02116cc
#include
<stdlib.h>
#include
<iostream>
using
namespace
std
;
// Declaration of three global variables
int
number
=
0
;
string
type
;
int
weight
=
0
;
float
dailyPrice
=
0
;
float
revenue
=
0
;
bool
inStock
;
// Prototypes
void
Create_Animal
();
void
Show_Animal
();
void
Sell_Animal
();
// Function to create
void
Create_Animal
()
{
cout
<<
"Please type in the number of the animal: "
;
cin
>>
number
;
cout
<<
endl
;
cout
<<
"Please type in the type of the animal: "
;
cin
>>
type
;
cout
<<
endl
;
cout
<<
"Please type in the weight of the animal: "
;
cin
>>
weight
;
cout
<<
endl
;
inStock
=
true
;
//Tier ist im Bestand
void
Data_query
();
void
Calculate_revenue
();
void
Data_output
();
// Function to input the weight and price
void
Data_query
()
{
cout
<<
"What is the weight? "
<<
endl
;
cin
>>
weight
;
cout
<<
"What is the daily price? "
<<
endl
;
cin
>>
dailyPrice
;
}
// Function to show the data
void
Show_Animal
()
{
cout
<<
"Animal number: "
<<
number
<<
endl
;
cout
<<
"Animal type: "
<<
type
<<
endl
;
cout
<<
"Animal weight: "
<<
weight
<<
endl
;
cout
<<
"In stock? (1 = yes, 0 = no): "
<<
inStock
<<
endl
;
// Function to calculate the revenue
// by multiplying weight & price
void
Calculate_revenue
()
{
revenue
=
weight
*
dailyPrice
;
cout
<<
"Revenue: "
<<
revenue
<<
endl
;
}
//Function to sell
void
Sell_Animal
(
int
nr
)
{
if
(
number
==
nr
&&
inStock
==
1
)
{
cout
<<
"What is the daily price?"
<<
endl
;
cin
>>
dailyPrice
;
revenue
=
revenue
+
(
weight
*
dailyPrice
);
cout
<<
"Total revenue: "
<<
revenue
<<
endl
;
inStock
=
false
;
cout
<<
endl
<<
endl
;
}
else
if
(
number
==
nr
&&
inStock
==
0
)
{
cout
<<
"Animal with the number "
<<
nr
<<
" is in stock."
<<
endl
;
}
else
{
cout
<<
"Animal with the number "
<<
nr
<<
" is not in stock."
<<
endl
;
}
}
;
int
main
()
{
int
s
=
0
,
input
,
nr
;
// declares integer s to zero, is used for the menu
int
s
=
0
,
input
;
// declares integer s to zero, is used for the menu
// do-while loop that outputs the menu and calls submenus
do
{
system
(
"cls"
);
//Clears the screen for windows-systems. For unix, use system("clear"); - you can also omit it
cout
<<
"Welcome to the farm administration"
<<
endl
<<
endl
<<
"Please make your selection in the menu...."
<<
endl
<<
endl
<<
endl
;
// The menu
cout
<<
"[1] Create animal"
<<
endl
;
cout
<<
"[2] Show animal"
<<
endl
;
cout
<<
"[3] Sell animal"
<<
endl
;
cout
<<
"[1] Data query"
<<
endl
;
cout
<<
"[2] Calculate revenue"
<<
endl
;
cout
<<
"[0] Exit"
<<
endl
<<
endl
;
cout
<<
"Make a selection: "
;
cin
>>
input
;
// Switch loop calls the individual menu items
switch
(
input
)
{
case
1
:
{
system
(
"cls"
);
Create_Animal
();
// Function to create an animal
cout
<<
"
Animal
has been
created
."
<<
endl
;
Data_query
();
// Function to create an animal
cout
<<
"
Data
has been
typed in
."
<<
endl
;
cin
.
ignore
();
//In windows you can use alternatively system("pause");
cin
.
get
();
break
;
}
case
2
:
{
system
(
"cls"
);
Show_Animal
();
Calculate_revenue
();
cin
.
ignore
();
cin
.
get
();
break
;
}
case
3
:
{
system
(
"cls"
);
cout
<<
"Type in animal number: "
<<
endl
;
cin
>>
nr
;
Sell_Animal
(
nr
);
system
(
"pause"
);
break
;
}
default
:
{
cout
<<
"Wrong input!"
<<
endl
;
cin
.
ignore
();
...
...
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