Welcome! Log In Create A New Profile

Advanced

Chapter 10 : textbook.h etc.

Posted by coetzeriw 
Announcements Last Post
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
Chapter 10 : textbook.h etc.
March 12, 2007 12:40AM
Hello

i created a new proj. with textbook.h and associated .cpp file. but cannot build that one! getting exactly 50 errors!

has anybody got it up and running?
Re: Chapter 10 : textbook.h etc.
March 12, 2007 01:29AM
textbook.h

#include "textbook.h"

#include <iostream>

using namespace std;

int main()
{


Textbook* t1 = new Textbook("Book 1", "Author 1", "1000", 1995);
Textbook* t2 = new Textbook("Book 2", "Author 2", "1000", 1996);
Textbook* t3 = new Textbook("Book 3", "Author 3", "1000", 1997);
Textbook* t4 = new Textbook("Book 4", "Author 4", "1000", 1998);

{
TextbookMap m;

m.add(t1);
m.add(t2);
m.add(t3);
m.add(t4);

m.showAll();
m.remove(t3->getIsbn());
}

cout<<"After m has been destroyed we still have: \n"<<t3->toString()<<endl;

return 0;
}
Re: Chapter 10 : textbook.h etc.
March 12, 2007 01:30AM
textbook.h (the previous post was my main.cpp text class ...)


#ifndef __TEXTBOOK_H__
#define __TEXTBOOK_H__

#include <QObject>
#include <QString>
#include <QMap>
#include <qstd.h>

#include <iostream>

using namespace std;

class Textbook : public QObject
{
Q_OBJECT
public:
Textbook(QString title, QString author, QString isbn, uint year);
//end
QString getAuthor() const;
QString getTitle() const;
QString getIsbn() const;
uint getYearPub() const;
QString toString() const;
public slots:
void setTitle(const QString& newTitle);
void setIsbn(const QString &newIsbn);
void setYearPub(uint newYear);
void setAuthor(const QString& newAuthor);
//start
private:
uint m_YearPub;
QString m_Title, m_Author, m_Isbn;
};

class TextbookMap : public QMap<QString, Textbook*> {
public:
~TextbookMap();
void add(Textbook* text);
void showAll() const;
};


Textbook::Textbook (QString title, QString author, QString isbn, uint year)
{
m_Title = title;
m_Author = author;
m_Isbn = isbn;
m_YearPub = year;
}

QString Textbook::getAuthor() const
{
return m_Author;
}

QString Textbook::getTitle() const
{
return m_Title;
}

QString Textbook::getIsbn() const
{
return m_Isbn;
}

uint Textbook::getYearPub() const
{
return m_YearPub;
}

QString Textbook::toString() const
{
return m_Title + ' ' + m_Author + ' ' + m_Isbn;
}

void Textbook::setTitle(const QString& newTitle)
{
m_Title = newTitle;
}

void Textbook::setIsbn(const QString& newIsbn)
{
m_Isbn = newIsbn;
}

void Textbook::setYearPub(uint newYear)
{
m_YearPub = newYear;
}

void Textbook::setAuthor(const QString& newAuthor)
{
m_Author = newAuthor;
}


TextbookMap::~TextbookMap()
{
cout<<"Destroying TextbookMap ..."<<endl;

foreach (QString key, keys())
delete value(key); //delete each pointer

clear();
}

void TextbookMap::add(Textbook* text)
{
insert(text->getIsbn(), text);
}

void TextbookMap::showAll() const
{
foreach (QString key, keys())
{
Textbook* tb = value(key);
cout<<"["<<key<<"]"<<tb->toString()<<endl;
}
}



#endif // __TEXTBOOK_H__
Re: Chapter 10 : textbook.h etc.
March 12, 2007 01:31AM
The cout<< are not working??? throwing errors when trying to build - complaining about the cout<< lines!!!

any ideas appreciated!

bye
Re: Chapter 10 : textbook.h etc.
March 12, 2007 11:19AM
Did any of the other projects compiled successfully?

What is the errors produced, that will be helpful.
Re: Chapter 10 : textbook.h etc.
March 12, 2007 06:51PM
Ok, I tried it and got a lot off errors as well.
By moving all the include files into the top of textbook.h, you will get rid of the compile errors.

So text.h should look like:
#ifndef _TEXTBOOK_H_
#define _TEXTBOOK_H_

#include <QObject>
#include <QString>
#include <QMap>
#include <qstd.h>
using namespace qstd;

class Textbook : public QObject {


and the examples.ccp should only have

#include "textbook.h"




There is still undefined reference but I assume we cannot do anything about that.


The output produces is:

mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/ezust_utils/src/containers/qmap/qmap'
g++ -mthreads -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runt
ime-pseudo-reloc -Wl,-subsystem,windows -o "debug\qmap.exe" debug\qmap-example.o
debug\moc_textbook.o -L"C:\Qt\4.1.1\lib" -lmingw32 -lqtmaind -L -lutils -lQtGu
id4 -lQtCored4
debug\qmap-example.o(.text+0x143): In function `ZN11TextbookMapD2Ev':
C:/ezust_utils/src/containers/qmap/qmap/../qmap-example.cpp:7: undefined referen
ce to `qstd::cout'
debug\qmap-example.o(.text+0x3c1): In function `ZN11TextbookMapD1Ev':
C:/ezust_utils/src/containers/qmap/qmap/../qmap-example.cpp:7: undefined referen
ce to `qstd::cout'
debug\qmap-example.o(.text+0x646): In function `ZN11TextbookMap3addEP8Textbook':

C:/ezust_utils/src/containers/qmap/qmap/../qmap-example.cpp:14: undefined refere
nce to `Textbook::getIsbn() const'
debug\qmap-example.o(.text+0x81e): In function `ZNK11TextbookMap7showAllEv':
C:/ezust_utils/src/containers/qmap/qmap/../qmap-example.cpp:20: undefined refere
nce to `Textbook::toString() const'
debug\qmap-example.o(.text+0x839):C:/ezust_utils/src/containers/qmap/qmap/../qma
p-example.cpp:20: undefined reference to `qstd::cout'
debug\qmap-example.o(.text+0xb3d): In function `main':
C:/ezust_utils/src/containers/qmap/qmap/../qmap-example.cpp:28: undefined refere
nce to `Textbook::Textbook(QString, QString, QString, unsigned int)'
debug\qmap-example.o(.text+0xd1a):C:/ezust_utils/src/containers/qmap/qmap/../qma
p-example.cpp:30: undefined reference to `Textbook::Textbook(QString, QString, Q
String, unsigned int)'
debug\qmap-example.o(.text+0xef7):C:/ezust_utils/src/containers/qmap/qmap/../qma
p-example.cpp:32: undefined reference to `Textbook::Textbook(QString, QString, Q
String, unsigned int)'
debug\qmap-example.o(.text+0x10d4):C:/ezust_utils/src/containers/qmap/qmap/../qm
ap-example.cpp:34: undefined reference to `Textbook::Textbook(QString, QString,
QString, unsigned int)'
debug\qmap-example.o(.text+0x1269):C:/ezust_utils/src/containers/qmap/qmap/../qm
ap-example.cpp:43: undefined reference to `Textbook::getIsbn() const'
debug\qmap-example.o(.text+0x133c):C:/ezust_utils/src/containers/qmap/qmap/../qm
ap-example.cpp:45: undefined reference to `Textbook::toString() const'
debug\qmap-example.o(.text+0x1357):C:/ezust_utils/src/containers/qmap/qmap/../qm
ap-example.cpp:45: undefined reference to `qstd::cout'
debug\moc_textbook.o(.text+0x1d7): In function `ZN8Textbook11qt_metacallEN11QMet
aObject4CallEiPPv':
C:/ezust_utils/src/containers/qmap/qmap/debug/moc_textbook.cpp:68: undefined ref
erence to `Textbook::setTitle(QString const&winking smiley'
debug\moc_textbook.o(.text+0x1f0):C:/ezust_utils/src/containers/qmap/qmap/debug/
moc_textbook.cpp:69: undefined reference to `Textbook::setIsbn(QString const&winking smiley'
debug\moc_textbook.o(.text+0x20b):C:/ezust_utils/src/containers/qmap/qmap/debug/
moc_textbook.cpp:70: undefined reference to `Textbook::setYearPub(unsigned int)'

debug\moc_textbook.o(.text+0x224):C:/ezust_utils/src/containers/qmap/qmap/debug/
moc_textbook.cpp:71: undefined reference to `Textbook::setAuthor(QString const&winking smiley
'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\qmap.exe] Error 1
mingw32-make[1]: Leaving directory `C:/ezust_utils/src/containers/qmap/qmap'
mingw32-make: *** [debug] Error 2
Re: Chapter 10 : textbook.h etc.
March 12, 2007 10:09PM
Hi
surely there must be a runnable version of this? somewhere?
I would love to see it in action.

As I don't even know where to start the excersise we are suppose to do in that chapter!!! help
Re: Chapter 10 : textbook.h etc.
March 13, 2007 07:17PM
Exercise is on page 233 and 234. Jip, it is Greek to me as well.
Here is a link about equivalence.
http://www.iscid.org/encyclopedia/Equivalence_Relation

If we understand that we might get a better idea of what to do.


Currently I still do not have an iea of how the command lines should look like.
Must we add sets from the command line, or must it be static sets defined in the beginning of the program.

ANY input will help.
avatar Re: Chapter 10 : textbook.h etc.
March 13, 2007 11:01PM
Hi guys

Firstly, the reason you're getting undefined reference errors is because the linker can't find the appropriate libraries. This goes for the compiler not being able to find certain headers as well.

To remedy this, you need to follow the instructions under point 5 in tut102; the part that explains how to set the project to a console project, how to add the include path and the library paths. This needs to be done for EVERY project you make since QIde doesn't have the ability to save project templates like DevC++ or MS Visual Studio.

Secondly, You have made some errors in your code:

You have assumed that because you see cout that you are using <iostream>. This is wrong. Qt has made it's own variables for that purpose based on the Qt library and not the STL. remove these includes.

Because you're using the utilities by the textbook authors, you should be using namespace qstd not using namespace std. Change that. While on that topic, you should NEVER put using namespace in a header file; it makes the whole point of a namespace redundant.

This should help solve your problem.
avatar Re: Chapter 10 : textbook.h etc.
March 13, 2007 11:16PM
Equivalence relations, symmetry, reflexivity and transitivity are all part of set theory and were covered in COS101
Re: Chapter 10 : textbook.h etc.
March 14, 2007 05:39AM
Unfortunately I did not do COS101.
Is there a link to additional reading on the subject or , What is the name of the prescribed book for COS101. Any info might help here as well.
Anonymous User
Re: Chapter 10 : textbook.h etc.
March 29, 2007 04:22AM
Can someone get the textbook thing to work in chap 10. I'm also stuck. followed all tut letters. All other stuff compile and work. just this one, give problems
avatar Re: Chapter 10 : textbook.h etc.
March 30, 2007 12:13AM
What are you stuck with?? What errors are you getting?
Anonymous User
Re: Chapter 10 : textbook.h etc.
March 30, 2007 03:20AM
A lot of normal compiler stuff then..............

mingw32-make[1]: *** [debug\qmap.exe] Error 1
mingw32-make[1]: Leaving directory `C:/ezust_utils/src/containers/qmap/qmap'
mingw32-make: *** [debug] Error 2

...........this error at the end. It is the same as what the guys in the previous error struggled with. Has any one been able to easily compile and run this example????????????????????????
Anonymous User
Re: Chapter 10 : textbook.h etc.
March 30, 2007 03:27AM
It's not that big a deal, was just looking for easy way out. Will go through their code on the weekend.

It was just strange that other people sort off sat with the same errors.

Cheers
avatar Re: Chapter 10 : textbook.h etc.
March 30, 2007 12:00PM
It could be either your setup or with your code. Remember that the code in the textbook isn't always complete. If you want the full source code, you should unzip it from the file on your 2007 CD. Mine compiles fine but I haven't really looked to see whether it does what it's supposed to do, I am rather far behind and should really try and catch up.
Re: Chapter 10 : textbook.h etc.
April 16, 2007 05:14PM
Iam getting the errors:
./qmap_example.cpp:13:undefined reference to "Textbook::getIsbn(QString const&".

My previous works, e.g. sliderLCD is working Ok.
Rob and cfdl: Could someone help

My headers & .cpp file heads are below:
//Textbook.h
#ifndef _TEXTBOOK_H_
#define _TEXTBOOK_H_

#include <QObject>
#include <QString>
#include <QMap>
#include <qstd.h>

class Textbook : public QObject {
Q_OBJECT
public:
Textbook(QString title, QString author, QString isbn, uint year);

//.cpp follows below

#include "textbook.h"

using namespace qstd;

//start id=impl
TextbookMap::~TextbookMap() {
cout << "Destroying TextbookMap ..." << endl;
Re: Chapter 10 : textbook.h etc.
April 16, 2007 09:48PM
Steps to make the example work. Keep in mind that Textbook is not implemented, you have to provide the code yourself.

Add a new resource named textbook.cpp to your project and put the Textbook and TextbookMap implementation there (I got some funny problems trying to put the implementation in the header). Remember to include "textbook.h" and <qstd.h>. Also add qstd:: in front of all cout's.

Add include <QMap> to textbook.h.

Remove TextbookMap implementation from qmap-example.cpp.

That should do it.
Re: Chapter 10 : textbook.h etc.
April 16, 2007 10:04PM
andrevh Wrote:
-------------------------------------------------------
> Unfortunately I did not do COS101.
> Is there a link to additional reading on the
> subject or , What is the name of the prescribed
> book for COS101. Any info might help here as well.

It is very simple

Reflexivity
a = a is true

symmetry
if a = b then so must b = a

Transitivity
If a = b and b = c then a = c

This is the basic contract for testing if things are equal to each other. That is all you have to do, keep track of things that are passed via the command line and which are equal to each other.
Re: Chapter 10 : textbook.h etc.
April 17, 2007 12:22PM
Thanks Jean: It now works Ok.
Could you be having the function to display uint year into string: toString(uint& t)const is not coming easily.
iva
Re: Chapter 10 : textbook.h etc.
April 19, 2007 07:51PM
thanks this post helped me too!
Sorry, only registered users may post in this forum.

Click here to login