A
arnuld
on Jul 16th, 2007, Erik Wikström gave me this exercise for starting
with real-life C++ code:
-------------------------------------------
So you basically want a proposal for a project which does not require
the usage of third party libraries and which is not to difficult.
I've got one for you, build a parser for a subset of the NASTRAN card
format, the format is as follows, each line is divided into columns of
8 character each and there are 6 columns per row (totalling 48 chars/row).
There are two kinds of records of interest for you, the first type
represents a point in space and has the word "GRID" written in the first
column, the second column is the ID of the point, the third column is
empty while the fourth, fifth, and sixth is the X, Y, and Z coordinates,
respectively, of the point. An example row:
GRID 1209 0000.0000008.0000010.000
This represents the point (0,9,10) in 3D space.
A note on exponents: When writing numbers as exponents we usually write
1.23e4 or 9.87e-6, in the files they skip the 'e' so those two numbers
would be 1.23+4 and 9.87-6 respectively.
The second type of record of interest represents a triangle and contains
information about which points are the corners of the triangle and which
object it belongs to. The format is as follows: First column contains
the word "CTRIA3", second column is the ID of the triangle, third the ID
of the object the triangle belongs to and the fourth to sixth columns
contains an ID of a point which makes out the corners of the triangle.
CTRIA3 0117 11 1198 1209 1210
This is triangle nr 117, belonging to object 11, its corners are located
at the points 1198, 1209, and 1210.
Construct a program which reads such a file and constructs a data-
structure containing information about what objects are in the model,
and for each objects have a list of all the triangles that makes up the
object. For each triangle store information about its corners, its
area, its centre (mass centre will do), and surface normal (assume
clockwise ordering of the corners). If you want an extra challenge also
make a list of all neighbours of the triangles, that is other triangles
that share shares an edge with it (remember that it does not have to be 3,
it can be less).
Some of the data will require some linear algebra to get, I hope you've
had a course on the subject, if not you might want to skip some of it.
Also comp.graphics.algorithms, alt.math, and sci.math might be helpful.
OK, so what is all this you might ask, and why should you do it? While
it's might not the most exiting assignment in the world (and will be
totally useless to you) it is a "real" project. What I described above
specifies the parser used by a program I've written that performs
simulations of heat transfer used by the automotive industry.
It really is not a very complicated task, there are two important
pieces, the first is to correctly read the data from the file which
will require some fiddling with IO-streams but you should be familiar with
the basics by now. The other part is to organise the data you read in,
start by designing classes representing the "things" in the program, such
as objects as such.
--------------------------------
here is the full list of input: http://dpaste.com/hold/37024/
Erik said i could write this program usign Classes. I have only one
idea about this program: I need to put that input into a simple text file
but then how to read all those things fromthere into different veriables ?
and from where to start ? and how does
GRID 1209 0000.0000008.0000010.000
This represents the point (0,9,10) in 3D space ?
how he calculated the 3 co-ordinates. I only see 1 co-ordinate and that
is: 0000.0000008.0000010.000
with real-life C++ code:
-------------------------------------------
So you basically want a proposal for a project which does not require
the usage of third party libraries and which is not to difficult.
I've got one for you, build a parser for a subset of the NASTRAN card
format, the format is as follows, each line is divided into columns of
8 character each and there are 6 columns per row (totalling 48 chars/row).
There are two kinds of records of interest for you, the first type
represents a point in space and has the word "GRID" written in the first
column, the second column is the ID of the point, the third column is
empty while the fourth, fifth, and sixth is the X, Y, and Z coordinates,
respectively, of the point. An example row:
GRID 1209 0000.0000008.0000010.000
This represents the point (0,9,10) in 3D space.
A note on exponents: When writing numbers as exponents we usually write
1.23e4 or 9.87e-6, in the files they skip the 'e' so those two numbers
would be 1.23+4 and 9.87-6 respectively.
The second type of record of interest represents a triangle and contains
information about which points are the corners of the triangle and which
object it belongs to. The format is as follows: First column contains
the word "CTRIA3", second column is the ID of the triangle, third the ID
of the object the triangle belongs to and the fourth to sixth columns
contains an ID of a point which makes out the corners of the triangle.
CTRIA3 0117 11 1198 1209 1210
This is triangle nr 117, belonging to object 11, its corners are located
at the points 1198, 1209, and 1210.
Construct a program which reads such a file and constructs a data-
structure containing information about what objects are in the model,
and for each objects have a list of all the triangles that makes up the
object. For each triangle store information about its corners, its
area, its centre (mass centre will do), and surface normal (assume
clockwise ordering of the corners). If you want an extra challenge also
make a list of all neighbours of the triangles, that is other triangles
that share shares an edge with it (remember that it does not have to be 3,
it can be less).
Some of the data will require some linear algebra to get, I hope you've
had a course on the subject, if not you might want to skip some of it.
Also comp.graphics.algorithms, alt.math, and sci.math might be helpful.
OK, so what is all this you might ask, and why should you do it? While
it's might not the most exiting assignment in the world (and will be
totally useless to you) it is a "real" project. What I described above
specifies the parser used by a program I've written that performs
simulations of heat transfer used by the automotive industry.
It really is not a very complicated task, there are two important
pieces, the first is to correctly read the data from the file which
will require some fiddling with IO-streams but you should be familiar with
the basics by now. The other part is to organise the data you read in,
start by designing classes representing the "things" in the program, such
as objects as such.
--------------------------------
here is the full list of input: http://dpaste.com/hold/37024/
Erik said i could write this program usign Classes. I have only one
idea about this program: I need to put that input into a simple text file
but then how to read all those things fromthere into different veriables ?
and from where to start ? and how does
GRID 1209 0000.0000008.0000010.000
This represents the point (0,9,10) in 3D space ?
how he calculated the 3 co-ordinates. I only see 1 co-ordinate and that
is: 0000.0000008.0000010.000