Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CSCI30_Project
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Temujin
CSCI30_Project
Commits
8ffc046b
Commit
8ffc046b
authored
Dec 08, 2019
by
Temujin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge branch 'master' of
https://gitlab.discs.ateneo.edu/Omanko6969/csci30_project
parent
0ea8ba34
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
0 deletions
+104
-0
chandelier.ft
chandelier.ft
+46
-0
family_tree.py
family_tree.py
+58
-0
No files found.
chandelier.ft
0 → 100644
View file @
8ffc046b
family Chandelier
count 11
name Kyle
age 91
sex true
name Fe
age 73
sex false
name Daniel
age 77
sex true
name Alma
age 52
sex false
name Aaron
age 49
sex true
name Dane
age 33
sex true
name Juan
age 32
sex true
name Charles
age 17
sex true
name Joyce
age 11
sex false
name Floyd
age 4
sex true
name Patricia
age 2
sex false
links 10
child Kyle Fe
child Kyle Daniel
child Daniel Alma
child Daniel Aaron
child Alma Dane
child Alma Juan
child Juan Charles
child Juan Joyce
child Charles Floyd
child Charles Patricia
family_tree.py
View file @
8ffc046b
...
...
@@ -328,6 +328,52 @@ class Person:
"""Return the name."""
return
self
.
name
def
openfile
(
filename
):
#Open Method
atree
=
FamilyTree
()
fname
=
filename
+
".ft"
readF
=
open
(
fname
,
"r"
)
familyname
=
readF
.
readline
()
.
split
()[
1
]
count
=
int
(
readF
.
readline
()
.
split
()[
1
])
for
i
in
range
(
count
):
name
=
readF
.
readline
()
.
split
()[
1
]
age
=
int
(
readF
.
readline
()
.
split
()[
1
])
sex
=
bool
(
readF
.
readline
()
.
split
()[
1
])
person
=
Person
(
name
,
age
,
sex
)
atree
.
insert_person
(
person
)
links
=
int
(
readF
.
readline
()
.
split
()[
1
])
for
i
in
range
(
links
):
line
=
readF
.
readline
()
.
split
()
p1
=
atree
.
get_person
(
line
[
1
])
p2
=
atree
.
get_person
(
line
[
2
])
p2
.
set_parent
(
p1
)
readF
.
close
()
return
atree
def
savefile
(
filename
,
tree
):
#Save Method
fname
=
filename
+
".ft"
saveF
=
open
(
fname
,
"w+"
)
saveF
.
write
(
"family "
+
filename
+
"
\n
"
)
count
=
len
(
tree
.
family_tree
)
saveF
.
write
(
"count "
+
str
(
count
)
+
"
\n
"
)
for
i
,
x
in
tree
.
family_tree
.
items
():
name
=
x
.
get_name
()
age
=
str
(
x
.
get_age
())
sex
=
str
(
x
.
get_sex
())
saveF
.
write
(
"name "
+
name
+
"
\n
"
)
saveF
.
write
(
"age "
+
age
+
"
\n
"
)
saveF
.
write
(
"sex "
+
sex
+
"
\n
"
)
links
=
count
-
1
saveF
.
write
(
"links "
+
str
(
links
)
+
"
\n
"
)
for
i
,
x
in
tree
.
family_tree
.
items
():
if
x
is
not
tree
.
root
:
parent
=
x
.
get_parent
()
saveF
.
write
(
"child "
+
parent
.
get_name
()
+
" "
+
x
.
get_name
()
+
"
\n
"
)
def
main
():
r"""For testing.
...
...
@@ -376,6 +422,18 @@ def main():
print
(
"relationship {} is {}'s: {}"
.
format
(
D
,
C
,
ftree
.
relationship
(
C
,
D
)))
print
(
"relationship {} is {}'s: {}"
.
format
(
C
,
D
,
ftree
.
relationship
(
D
,
C
)))
print
(
""
)
#test for opening and saving files
ntree
=
openfile
(
"chandelier"
)
ntree
.
find_root
()
ntree
.
precompute
()
print
(
"The root of the tree is {}."
.
format
(
ntree
.
root
))
for
key
,
node
in
ntree
.
family_tree
.
items
():
print
(
"{}: {}"
.
format
(
node
,
node
.
get_generation
()))
savefile
(
"test"
,
ntree
)
if
__name__
==
"__main__"
:
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment