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
e91858fa
Commit
e91858fa
authored
7 months ago
by
Rudi Buss
Browse files
Options
Downloads
Patches
Plain Diff
Update Solution Exercise 2 - Car.cpp
parent
8a978688
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 2 - Car.cpp
+34
-42
34 additions, 42 deletions
... member variables/Solutions/Solution Exercise 2 - Car.cpp
with
34 additions
and
42 deletions
Part 1/8. Constructor, member initialization list, overloading, destructor, static member variables/Solutions/Solution Exercise 2 - Car.cpp
+
34
−
42
View file @
e91858fa
#include
<iostream>
#include
<iostream>
using
namespace
std
;
class
Car
{
private:
string
brand
;
int
mileage
;
static
int
number_rides
;
public:
Car
(
string
b
,
int
m
)
:
brand
(
b
),
mileage
(
m
)
{
}
~
Car
()
{
cout
<<
endl
<<
"Object has been deleted. "
<<
endl
;
}
void
drive
(
int
driven
)
//Declaration and Definition of the function query_data
{
mileage
+=
driven
;
number_rides
++
;
}
void
show_data
()
{
cout
<<
brand
<<
", actual mileage: "
<<
mileage
<<
endl
;
cout
<<
"Number of rides: "
<<
number_rides
<<
endl
;
}
class
Car
{
private:
string
brand
;
int
mileage
;
static
int
number_rides
;
public:
Car
(
string
b
,
int
m
)
:
brand
(
b
),
mileage
(
m
)
{}
~
Car
()
{
cout
<<
endl
<<
"Object has been deleted. "
<<
endl
;
}
void
drive
(
int
driven
)
// Declaration and Definition of the function query_data
{
mileage
+=
driven
;
number_rides
++
;
}
void
show_data
()
{
cout
<<
brand
<<
", actual mileage: "
<<
mileage
<<
endl
;
cout
<<
"Number of rides: "
<<
number_rides
<<
endl
;
}
};
int
Car
::
number_rides
=
0
;
int
main
()
{
Car
bmw
(
"BMW"
,
1500
);
bmw
.
drive
(
70
);
bmw
.
show_data
();
bmw
.
drive
(
80
);
bmw
.
show_data
();
bmw
.
drive
(
250
);
bmw
.
show_data
();
cout
<<
endl
<<
endl
;
return
0
;
}
int
Car
::
number_rides
=
0
;
int
main
()
{
Car
bmw
(
"BMW"
,
1500
);
bmw
.
drive
(
70
);
bmw
.
show_data
();
bmw
.
drive
(
80
);
bmw
.
show_data
();
bmw
.
drive
(
250
);
bmw
.
show_data
();
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