Welcome! Log In Create A New Profile

Advanced

Let’s get started with Assignment 3 colleagues

Posted by Anonymous User 
Announcements Last Post
Announcement myUnisa availability 21 to 24 March 2019 03/17/2019 02:24PM
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Anonymous User
Let’s get started with Assignment 3 colleagues
September 01, 2011 04:25PM
Do not wait until is late. lets get started

Question 1 reads

Apply the Serializer pattern to the TextbookMap class given in Example 10.10, and test your code. (Apart from the discussion of the Serializer pattern in Section 10.5 of Ezust, see the notes at the end of Tutorial Letter 102.)

However, according to my soft copy version of the book, TextbookMap class is defined in Example 10.13. not 10.10
my question is, is this a mistake or I got a wrong copy?
avatar Re: Let’s get started with Assignment 3 colleagues
September 01, 2011 04:28PM
I think you'll find that the "official" version of the text is the one on the course disk. That is certainly the case in COS3711.
Anonymous User
Re: Let’s get started with Assignment 3 colleagues
September 02, 2011 10:49AM
I gues it is a mistake then. I will verify with the lecture
avatar Re: Let’s get started with Assignment 3 colleagues
September 02, 2011 01:46PM
The online book or soft copy is dynamic, by the authors changing around content. So this may be different to unisa's copy.

_____________________________________
The sun is always shining, but it is far away.
Re: Let’s get started with Assignment 3 colleagues
September 07, 2011 12:31PM
Phew! Finished my calculus assignment 2 now. Now going to do assignment 3. Hope it's not too late.

Good luck guys! See you around!
Re: Let’s get started with Assignment 3 colleagues
September 08, 2011 03:55PM
I don't have this file - .../src/containers/contact/serializer.cpp. I need to read this file in order to undestand how to implement a serializer pattern. Man, this is so &$@$@ frustating!!!!
Anonymous User
Re: Let’s get started with Assignment 3 colleagues
September 09, 2011 02:40PM
My program can display on the screen but i'm still figuring how to implement searializer. the subscribed book is useless, quite frankly, we are on our own here. UNISA should have compiled a supporting notes since this book is more of a monual or QT4 Documantation. no wonder is free online. just to vent. lol
avatar Re: Let’s get started with Assignment 3 colleagues
September 09, 2011 06:31PM
@Crunx. Don't panic. You're not on your own here. It takes a while to get the idea of the Serializer Pattern into your mind but once you get it, it's fairly simple.

If you take the barebones concept behind the pattern, it's to take a complex hierarchical data structure and lay it out in a linear fashion (byte after byte) and then be able to reverse the process. In a nutshell, you create a data format converter. What format you use is largely irrelevant as long as the deserialiser class does the opposite to the serialiser class.

The reason that the serializer.cpp file can't be found is because you need to create it as part of the exercise on the next page of the textbook. If you take the basic idea behind the Serialiser Pattern, you should have the following kind of idea:

Language: C++ (QT)
class Person{ public: QString name; QString surname; };   QString serialise(Person const &person){ return person.name + person.surname; }   Person deserialise(QString const &serialData){ // ??? }

As you can see, serialisation is usually the easier of the two. The difficulty in deserialisation is to figure out where one data item ends and the next data item begins. In the above example, this is hopeless.

If you look at Exercises : Serialiser Pattern, number 1, you'll see that they give you a common way of separating the data items; they tell you to use a tab character to separate (or delimit) the items. The tab character is indicated by the escapes character sequence '\t'.

The above example then becomes:
Language: C++ (QT)
QString serialise(Person const &person){ return person.name + '\t' + person.surname; }   Person deserialise(QString const &serialData){ QStringList fields = serialData.split('\t'); Person person; person.name = fields[0]; person.surname = fields[1]; return person; }

This simple example shows that you can get a data structure into a linear form, and linearly formatted data into a structured form. This is the essence of the Serialiser Pattern. Specific problems can require the implementation of the pattern to be quite complex. Using this example, you should be able to expand on it to complete the exercise and create your own serializer.cpp file.

Take note that this example serialises and deserialises a single data structure, the exercise requires you to work on a container of structures so you'll need to have expand on this a bit.
Re: Let’s get started with Assignment 3 colleagues
September 09, 2011 09:53PM
Hi again!

Thanks, robanaurochs smiling smiley I'm still working on question 1. It's almost complete now.

TextbookMapWriter class is easy to implement. My TextbookMapReader class is still under construction. Before reading your post, I needed to figure how to only pick up only relevant data from some input file before initialize them to an instance of class Textbook. Looks like I have to modify my TextbookMapWriter's write function to make it easy to implement TextbookMapReader's read function.

On the other hand, when I try to compile a program (Example 11.4 and 11.5), I always get these errors - "cannot find - lcards2" and "collect2: Id returned 1 exit status". Tutorial letter 102's so useless angry smiley

THIS IS THE WORST MODULE EVER!!!! SERIOUSLY!!!! If I still struggle to finish question 2 by next Monday then I will be in some serious trouble T_T

Good luck guys!!! Hope we will complete this assignment soon!
Anonymous User
Re: Let’s get started with Assignment 3 colleagues
September 09, 2011 11:14PM
robanaurochs wrote

If you take the barebones concept behind the pattern, it's to take a complex hierarchical data structure and lay it out in a linear fashion (byte after byte) and then be able to reverse the process. In a nutshell, you create a data format converter. What format you use is largely irrelevant as long as the deserialiser class does the opposite to the serialiser class.

I get the idea but that is quite mouthful to grasp. lets try to simplify it first and look at it from read/write to a file logic. I guess the assignment want us to illustrate the use of serializers to decouple the reading from and writing to files from the data objects. The great advantage of the serializer pattern is that we can replace or change the reading and writing behaviour, without touching the data objects.

so I create two class TextBookReader Class and TextBookWriter class to implement this serializer concept
Language: C++ (QT)
class TextBookReader{ public: friend TextBookReader& operator>>(TextBookReader& ter, Textbook cl); TextBookReader(QString fileName); bool read(textBookReader& cl); private: QString fn; };   TextBookReader cpp file   [code="cpp-qt"] TextBookReader& operator>>(TextBookReader& reader, Textbook& cl) reader.read(cl); return reader; } TextBookReader::TextBookReader(QString n){ fn = n; } bool TextBookReader::read(TextbookMap &cl){ QFile fl(fn) fl.open(QIODevice::ReadOnly); QTextStream out(&fl); while (!fl.atEnd()){ QStringList list = line.split("/t";); ? ? ? } } fl.close return true; }   so what I really want is this TextBookReader object to read a list from a file

[/code]
Anonymous User
Re: Let’s get started with Assignment 3 colleagues
September 09, 2011 11:39PM
below is the assignment question

You should submit the code of all the classes (TextbookMap, Textbook, TextbookMapReader and TextbookMapWriter) and of the two programs that test them. You should also submit the output that these programs display on the screen, as well as the contents of the file produced by the first program.

so my texbook, TextbookMap and test program are fine. so we need to implement TextbookMapReader and TextbookMapWriter class and test program.

lets say Textbook has attributes
Language: C++ (QT)
Textbook(QString title, QString author, QString isbn, unit yearPub);

and we this file contents

Design Patterns, Gamma, 0099886, 1999
Project Management, Crunx,98875, 2009
Operating system, Wayne rooney,67534, 2011

I want to write a program to read this file and dispaly it on screen

unless I do not understand the question
avatar Re: Let’s get started with Assignment 3 colleagues
September 10, 2011 10:22AM
Quote
Specre
On the other hand, when I try to compile a program (Example 11.4 and 11.5), I always get these errors - "cannot find - lcards2" and "collect2: Id returned 1 exit status". Tutorial letter 102's so useless

If the linker says it can't find -lcards2 then it means you've told it to link in a static library called cards2.a and it is struggling to find it. Do you need this library? Have you told the compiler in which directory it's in (using LIBS += -L/my/lib/path -lmylib in the .pro file)?

@crunx

Firstly, you don't seem to have understood the concept of an escape sequence.

You coded:
Language: C++ (QT)
QStringList list = line.split("/t";);
You have told the line to split wherever it finds the two character string of a forward slash followed by a lower-case t. This is not what I meant in my previous post.

This should be:
Language: C++ (QT)
QStringList list = line.split('\t');
Which is subtly different. Firstly, I've used the single character syntax of a backward slash followed by a lower-case t. This escape sequence represents the single Horizontal Tab character. You've used escape sequences before when sending text to the console. You use the newline escape sequence '\n' to move to the next line. Note, I used single quotes, not double quotes. This indicates that I am designating a single character and not a character string.

As far as the algorithm goes, note that I said that my Serialiser/Deserialiser that I made for my previous post is only capable of writing/reading a single data object. For the textbook exercise, and this assignment question, you have to read and write lists of objects. This is not too difficult since you are given the format of the data with the example: Records and separated by newlines and fields are separated by commas.

If I look at your code, you're opening a QFile object and then looping till its file pointer reaches the end of the file. In the code you pasted, you're never actually reading anything so you'll have an infinite loop.

I suggest a different approach. Read everything from the file into memory and then close the file. If you've got everything in memory, you can see any part of it at any time you wish. This is important because you need to split the text into records and fields. The order in which you split the QString is important.

Taking your example text file and making it look serial, you get the following:
Language: C++
"Design Patterns, Gamma, 0099886, 1999\nProject Management, Crunx,98875, 2009\nOperating system, Wayne rooney,67534, 2011\n"

If you split first by the field delimiter, you'll get the following list of QStrings:
Language: C++
"Design Patterns" " Gamma" " 0099886" " 1999\nProject Management" " Crunx" "98875" " 2009\nOperating system" " Wayne rooney" "67534" " 2011\n"
This is obviously undesirable so it would make more sense to split by record delimiter first.
Language: C++
"Design Patterns, Gamma, 0099886, 1999" "Project Management, Crunx,98875, 2009" "Operating system, Wayne rooney,67534, 2011" ""
From this point you have individual serialised records that you can split into fields and create your data objects that you can then add to your container.

A couple of warnings though, depending on how you serialise your data in the first place, you may, or may not have a serial string that you write to the file that ends with a newline character ('\n'). This extra newline character will pose a problem when deserialising because, by default, you'll end up with an empty QString as your last record, as I've shown above. To avoid this, use the second parameter of QString:: split(). Look in the Qt Assistant reference to QString for more information about this.
Language: C++ (QT)
QStringList records = fileData.split('\n', QString::SkipEmptyParts);
This will produce, the desired number of records, none of them empty:
Language: C++
"Design Patterns, Gamma, 0099886, 1999" "Project Management, Crunx,98875, 2009" "Operating system, Wayne rooney,67534, 2011"

A second warning is that your data in the file seem to have a space after the comma. This is probably an error and shouldn't be there. You should accomodate for this and automatically remove leading and training spaces using the QString:: trimmed() function. Look in the Qt Assistant for more information about this function.
Re: Let’s get started with Assignment 3 colleagues
September 11, 2011 12:31PM
Phew! Just completed my Serializer Pattern project. Thanks sir grinning smiley Your posts are really helpful!!!!! Really appreciate it.

Now trying to finish the last question. I think it should be easy as long as you use QtAssistance.
Re: Let’s get started with Assignment 3 colleagues
September 11, 2011 06:03PM
robanaurochs Wrote:
-------------------------------------------------------
> > On the other hand, when I try to compile a
> program (Example 11.4 and 11.5), I always get
> these errors - "cannot find - lcards2" and
> "collect2: Id returned 1 exit status". Tutorial
> letter 102's so useless
>
>
> If the linker says it can't find -lcards2 then it
> means you've told it to link in a static library
> called cards2.a and it is struggling to find it.
> Do you need this library? Have you told the
> compiler in which directory it's in (using LIBS +=
> -L/my/lib/path -lmylib in the .pro file)?

I really don't get it.

Language: C++ (QT)
TEMPLATE = app LIBS += -L$$(CPPLIBS) \ -lutils \ -lcards2   # Input HEADERS += cardtable.h \ cardpics.h SOURCES += boxes.cpp \ cardtable.cpp \ cardpics.cpp RESOURCES = \ cards2.qrc

I have read tutorial letter 102 very very carefully. I still get the same error messages sad smiley I'm totally lost now. I have included all the required files/folder (cardpic header/implementation files and the image folder) in the same project folder. What did I miss? I have read tutorial letter 102 like many times but it doesn't help.
Anonymous User
Re: Let’s get started with Assignment 3 colleagues
September 11, 2011 06:24PM
Thanks Rob for your assistance. I think i am now in a good position to finish this question off.

@Spectre good for you mate
avatar Re: Let’s get started with Assignment 3 colleagues
September 11, 2011 06:26PM
Why do you have in the line:
LIBS += -L$$(CPPLIBS)  \
        -lutils  \
        -lcards2
The line for linking in a static library called cards2.a? Does this file actually exist? Are you not making a mistake here? Do you understand what a static library is and what it's for? What's in the cards2.a library that you need in your project?
Re: Let’s get started with Assignment 3 colleagues
September 11, 2011 07:01PM
robanaurochs Wrote:
-------------------------------------------------------
> Why do you have in the line:
>
> LIBS += -L$$(CPPLIBS) \
> -lutils \
> -lcards2
>
> The line for linking in a static library called
> cards2.a? Does this file actually exist? Are you
> not making a mistake here? Do you understand what
> a static library is and what it's for? What's in
> the cards2.a library that you need in your
> project?

I didn't add anything here except the line ->

RESOURCES = \
cards2.qrc

I merely copied the boxes.cpp and boxes.pro files into my project folder along with the other required files.

I fixed it by creating a new blank project and add the same files except the pro file to the project then compiled it. Bam! It works. I feel so ashamed -_-

Now I need to figure out how to make a simple BlackJack game.
Re: Let’s get started with Assignment 3 colleagues
September 12, 2011 11:35AM
Hi again! Sorry for asking too many questions.

Is it possible to shuffle a QList of stuff randomly? Like Vector's randomShuffle()? Hope you get what I mean. Do I have to create a new function to do this job?
avatar Re: Let’s get started with Assignment 3 colleagues
September 12, 2011 11:59AM
I don't see anything like that for QVector, so I presume Vector is one of the Ezust functions?

Then you'd just use it as a model?

I would guess you need to just keep using swap at random for a certain amount of time. Your i and j, I suppose you'd get by using modulo division on an appropriate range (not including zero, I suppose).
Re: Let’s get started with Assignment 3 colleagues
September 12, 2011 12:28PM
slow_eddy Wrote:
-------------------------------------------------------
> I don't see anything like that for QVector, so I
> presume Vector is one of the Ezust functions?
>
> Then you'd just use it as a model?
>
> I would guess you need to just keep using swap at
> random for a certain amount of time. Your i and j,
> I suppose you'd get by using modulo division on an
> appropriate range (not including zero, I suppose).

Hey!

No, QVector doesn't have the randomShuffle() function like STL Vector does. QList doesn't have a similiar function as well.

I want to write shuffleCard() function for class Deck which is a container (QList<*Card>winking smiley. I want the cards in a deck (an instance of class Deck) to be randomly arranged when shuffleCard() is called.

There's not enough information in Question 3 to help us with creating Blackjack program. That sucks big time thumbs down.

EDIT: Hey, I think it's better to use QMap instead of QList. That way, it's easy to write randomShuffle() function. Right?
avatar Re: Let’s get started with Assignment 3 colleagues
September 12, 2011 12:55PM
There's no need to try and re-invent the wheel. This has been done many times in the past and is public knowledge. Google "suffle algorithm" and you'll find a lot of options.

Personally, the one that seems least of a hassle is the Durstenfeld version of the Fisher–Yates algorithm. It shouldn't be too difficult to implement.
Re: Let’s get started with Assignment 3 colleagues
September 12, 2011 01:13PM
robanaurochs Wrote:
-------------------------------------------------------
> There's no need to try and re-invent the wheel.
> This has been done many times in the past and is
> public knowledge. Google "suffle algorithm" and
> you'll find a lot of options.
>
> Personally, the one that seems least of a hassle
> is the Durstenfeld version of the Fisher–Yates
> algorithm. It shouldn't be too difficult to
> implement.

Thanks, sir grinning smiley
avatar Re: Let’s get started with Assignment 3 colleagues
September 12, 2011 02:34PM
Thanks, Spectre. Now I know something new about the STL Vector class. Add that to the almost nothing (bar COS112) that I knew before, and it's quite a lot. smile

Looks like after COS214 as done this year you guys will at least find COS371 a doddle. grinning smiley
Re: Let’s get started with Assignment 3 colleagues
September 12, 2011 04:48PM
You are welcome, mate grinning smiley Cool, looking forward to that!
Anonymous User
Re: Let’s get started with Assignment 3 colleagues
September 12, 2011 10:51PM
I had three other assignments to submit today hence my absence on this phorum. anyway, Question 1 is done and dusted. I have not looked at Question 2 yet but I hope the help that have already been dished here will pave the way for me. later then
Anonymous User
Re: Let’s get started with Assignment 3 colleagues
September 12, 2011 11:02PM
@ Slow eddy

if I pass all my 4 modules i'm doing this semester, I will be left with one third year module. I have dilemma if to go for 3711 or graphics. I had registered for graphics this semester but dropped it after it gave me problems. Is not that difficult but its need a lot of time.
Re: Let’s get started with Assignment 3 colleagues
September 13, 2011 09:34AM
crunx Wrote:
-------------------------------------------------------
> I had three other assignments to submit today
> hence my absence on this phorum. anyway, Question
> 1 is done and dusted. I have not looked at
> Question 2 yet but I hope the help that have
> already been dished here will pave the way for me.
> later then

Hey mate, I think you should start doing question 2 now. It takes a lot of time to create a simple Blackjack game (In my opinion). But actually it's easy to program this game smiling smiley
Anonymous User
Re: Let’s get started with Assignment 3 colleagues
September 13, 2011 11:51AM
wow. just looked at the question. quite challenging and interesting at the same time. I will if I will cross the bridge with this one
avatar Re: Let’s get started with Assignment 3 colleagues
September 13, 2011 01:43PM
If you want more pain, go for 3711. Graphics is challenging but 3711 will consume your life for a few months. That said, it looks like they're giving you a pretty good workout here already. Could be that you guys will be readier for 3711 than us.
Re: Let’s get started with Assignment 3 colleagues
September 13, 2011 04:30PM
slow_eddy Wrote:
-------------------------------------------------------
> If you want more pain, go for 3711. Graphics is
> challenging but 3711 will consume your life for a
> few months. That said, it looks like they're
> giving you a pretty good workout here already.
> Could be that you guys will be readier for 3711
> than us.

Will studying this module help me make really awesome games easily? (I know it's obvious!)If so, bring it on! grinning smiley grinning smiley grinning smiley
Sorry, only registered users may post in this forum.

Click here to login