Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
COMS327
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor 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
Jake Feddersen
COMS327
Commits
4a5495fb
Commit
4a5495fb
authored
5 years ago
by
Jake Feddersen
Browse files
Options
Downloads
Patches
Plain Diff
Notes
parent
3bafdb1a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
notes/4_01/inheritance
+0
-0
0 additions, 0 deletions
notes/4_01/inheritance
notes/4_01/inheritance.cpp
+77
-0
77 additions, 0 deletions
notes/4_01/inheritance.cpp
with
77 additions
and
0 deletions
notes/4_01/inheritance
0 → 100755
+
0
−
0
View file @
4a5495fb
File added
This diff is collapsed.
Click to expand it.
notes/4_01/inheritance.cpp
0 → 100644
+
77
−
0
View file @
4a5495fb
#include
<iostream>
using
namespace
std
;
class
shape
{
public:
int
color
;
virtual
double
area
()
=
0
;
virtual
double
perimeter
()
=
0
;
virtual
~
shape
()
{};
};
class
rectangle
:
public
shape
{
private:
double
width
,
height
;
public:
double
area
()
{
return
width
*
height
;
}
double
perimeter
()
{
return
2
*
(
width
+
height
);
}
rectangle
()
{
width
=
1
;
height
=
2
;
}
rectangle
(
double
width
,
double
height
)
{
this
->
width
=
width
;
this
->
height
=
height
;
}
friend
ostream
&
operator
<<
(
ostream
&
o
,
const
rectangle
&
r
);
};
ostream
&
operator
<<
(
ostream
&
o
,
const
rectangle
&
r
)
{
return
o
<<
"Rectangle: Width "
<<
r
.
width
<<
", Height "
<<
r
.
height
<<
endl
;
}
class
square
:
public
shape
{
private:
double
side
;
public:
double
area
()
{
return
side
*
side
;
}
double
perimeter
()
{
return
4
*
side
;
}
square
()
{
side
=
1
;
}
square
(
double
side
)
{
this
->
side
=
side
;
}
friend
ostream
&
operator
<<
(
ostream
&
o
,
const
square
&
s
);
};
ostream
&
operator
<<
(
ostream
&
o
,
const
square
&
s
)
{
return
o
<<
"Square: Side "
<<
s
.
side
<<
endl
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
square
s
(
4
);
rectangle
r
(
3
,
5
);
shape
*
sp
=
&
s
;
shape
&
sr
=
r
;
cout
<<
s
<<
s
.
perimeter
()
<<
endl
<<
s
.
area
()
<<
endl
;
cout
<<
r
<<
r
.
perimeter
()
<<
endl
<<
r
.
area
()
<<
endl
;
cout
<<
*
sp
;
cout
<<
sr
;
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
}
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