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
bc435586
Commit
bc435586
authored
7 months ago
by
Rudi Buss
Browse files
Options
Downloads
Patches
Plain Diff
Update Solution Exercise 3 - Article.cpp
parent
fcc5d9a3
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/7. Classes and objects/Solutions/Solution Exercise 3 - Article.cpp
+53
-67
53 additions, 67 deletions
...s and objects/Solutions/Solution Exercise 3 - Article.cpp
with
53 additions
and
67 deletions
Part 1/7. Classes and objects/Solutions/Solution Exercise 3 - Article.cpp
+
53
−
67
View file @
bc435586
#include
<iostream>
#include
<iostream>
using
namespace
std
;
class
Article
{
private:
string
Name
;
float
Price
;
class
Article
{
private:
string
Name
;
float
Price
;
public:
//getter
string
get_Name
()
{
return
Name
;
}
float
get_Price
()
{
return
Price
;
}
//setter
void
set_Name
()
{
cout
<<
"Please enter the name of the article: "
;
cin
>>
Name
;
}
void
set_Price
()
{
cout
<<
"Please enter the price of the article: "
;
cin
>>
Price
;
}
//Member functions
void
Show_data
()
//Declaration and definition of the member function Show_data
{
cout
<<
"The article "
<<
get_Name
()
<<
" costs "
<<
get_Price
()
<<
" Euro."
<<
endl
;
}
void
Enter_data
()
//Declaration and definition of the member function Enter_data
{
set_Name
();
set_Price
();
}
void
Calculate_TotalPrice
(
int
quant
)
//Declaration and definition of the member function Calculate_TotalPrice
{
cout
<<
"Total price: "
<<
quant
*
get_Price
()
<<
endl
;
}
public:
// getter
string
get_Name
()
{
return
Name
;
}
float
get_Price
()
{
return
Price
;
}
// setter
void
set_Name
()
{
cout
<<
"Please enter the name of the article: "
;
cin
>>
Name
;
}
void
set_Price
()
{
cout
<<
"Please enter the price of the article: "
;
cin
>>
Price
;
}
// Member functions
void
Show_data
()
// Declaration and definition of the member function Show_data
{
cout
<<
"The article "
<<
get_Name
()
<<
" costs "
<<
get_Price
()
<<
" Euro."
<<
endl
;
}
void
Enter_data
()
// Declaration and definition of the member function Enter_data
{
set_Name
();
set_Price
();
}
void
Calculate_TotalPrice
(
int
quant
)
// Declaration and definition of the member function Calculate_TotalPrice
{
cout
<<
"Total price: "
<<
quant
*
get_Price
()
<<
endl
;
}
};
int
main
()
{
Article
art
;
int
quantity
;
art
.
Enter_data
();
art
.
Show_data
();
cout
<<
"Please enter a quantity: "
;
cin
>>
quantity
;
art
.
Calculate_TotalPrice
(
quantity
);
cout
<<
endl
<<
endl
;
return
0
;
}
int
main
()
{
Article
art
;
int
quantity
;
art
.
Enter_data
();
art
.
Show_data
();
cout
<<
"Please enter a quantity: "
;
cin
>>
quantity
;
art
.
Calculate_TotalPrice
(
quantity
);
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