Announcements | Last Post | |
---|---|---|
SoC Curricula | 09/30/2017 01:08PM | |
Demarcation or scoping of examinations and assessment | 02/13/2017 07:59AM | |
School of Computing Short Learning Programmes | 11/24/2014 08:37AM | |
Unisa contact information | 07/28/2011 01:28PM |
Re: Exam 2009 Q & A October 19, 2010 08:34PM |
Registered: 17 years ago Posts: 472 Rating: 0 |
Re: Exam 2009 Q & A October 19, 2010 10:00PM |
Registered: 16 years ago Posts: 284 Rating: 0 |
Language: C++ (QT)#include <QObject> // CodeVisitor.h class CodeVisitor : public QObject Q_OBJECT { public: CodeVisitor(); int getNumFiles() const; QString getResultString() const; slots: void processFile(QString filename); private: int m_NumFiles; QStringList m_Result; }; // CodeVisitor.cpp void CodeVisitor::processFile(QString filename) { m_Result << filename; QString line; QFile file(filename); file.open(QIODevice::ReadOnly); QTextStream filestream(&file); while(!filestream.atEnd()) { line = filestream.readLine(); if(line.startsWith("#include")) { m_Result << QString(" %1").arg(line); } } file.close(); ++m_NumFiles; }
Language: C++ (QT)int main() { FileVisitor fVis("*", true, false); CodeVisitor cVis(); CONNECT(fVis, SIGNAL(foundFile(QString)), cVis, SLOT(processFile(QString))); // Process file }
Language: C++ (QT)// CodeVisitor.h #include <QObject> #include <QString> class CodeVisitor : public QObject Q_OBJECT { public: CodeVisitor(QString searchType); int getNumFiles() const; QString getResultString() const; virtual void processInput(QString filename); slots: void processFile(QString filename); private: CodeVisitor* context; int m_NumFiles; QStringList m_Result; }; // CodeVisitor.cpp void CodeVisitor::CodeVisitor(QString searchType) { switch(searchType) { case "IncludeSearcher": { context = new IncludeSearcher(); break; } case "AntiCodeSearcher": { context = new AntiCodeSearcher(); break; } default: { context = 0; } } } void CodeVisitor::processFile(QString filename) { if(context == 0) return; context.processInput(filename); }
Language: C++ (QT)// TxtEnderSearcher.h #include "codevisitor.h" class TxtEnderSearcher : public CodeVisitor { public: TxtEnderSearcher(); int getNumFiles() const; QString getResultString() const; void processInput(QString filename) private: int m_NumFiles; QStringList m_Result; } // TxtEnderSearcher.cpp void TxtEnderSearcher::processInput(QString filename) { m_Result << filename; QString line; QFile file(filename); file.open(QIODevice::ReadOnly); QTextStream filestream(&file); while(!filestream.atEnd()) { line = filestream.readLine(); if(!line.endsWith(".txt")) { m_Result << QString(" %1").arg(line); } } file.close(); ++m_NumFiles; }
Language: C++ (QT)// MicroLending.h // Assumptions below #include "Bank.h" #include "CreditBureau.h" #include "RevenueServices.h" // End assumptions class MicroLending : QObject { Q_OBJECT public: MicroLending() { } // Inline declaration as nothing happens here. bool isEligible(Customer cust, int amount); } // MicroLending.cpp bool MicroLending::isEligible(Customer cust, int amount) { // No Constructors shown, so creating these with the assumption of no parameters Bank bank(); CreditBureau creditBureau(); RevenueServices revenueServices(); if (bank.hasSufficientFunds(cust, amount) && creditBureau.hasGoodCredit(cust) && revenueServices.hasRegularIncome(cust)) { return true; } else { return false; } }
Language: C++ (QT)int main() { Customer cust("ABC Buyer"); bool eligible; int amount = 125000; MicroLending* mLending(); qDebug() << customer.getName() << "applies for R" << amount << "loan" << endl; eligible = mLending.isEligible(cust, amount); qDebug() << customer.getName() << "has been" << (eligible ? "Approved" : "Rejected") << endl; }
Language: C++ (QT)class MicroLending { public: bool isEligible(Customer cust, int amount); static MicroLending* getInstance(); protected: MicroLending() { } // Inline declaration as nothing happens here. } // MicroLending.cpp MicroLending::getInstance() { static MicroLending* instance = 0; if(instance == 0) { instance = new MicroLending(); instance->setParent(qApp); } return instance; }
Language: C++ (QT)MicroLending mLending* = MicroLending::instance();
Language: C++ (QT)f->metaObject()->superClass()->className();
Re: Exam 2009 Q & A October 20, 2010 11:15AM |
Registered: 14 years ago Posts: 8 Rating: 0 |
Re: Exam 2009 Q & A October 20, 2010 11:26AM |
Registered: 13 years ago Posts: 6 Rating: 0 |
Re: Exam 2009 Q & A October 20, 2010 11:34AM |
Registered: 15 years ago Posts: 50 Rating: 0 |
Re: Exam 2009 Q & A October 20, 2010 11:41AM |
Registered: 16 years ago Posts: 284 Rating: 0 |
Re: Exam 2009 Q & A October 20, 2010 11:45AM |
Registered: 13 years ago Posts: 6 Rating: 0 |
Re: Exam 2009 Q & A October 20, 2010 11:47AM |
Registered: 13 years ago Posts: 6 Rating: 0 |
Re: Exam 2009 Q & A October 20, 2010 12:24PM |
Registered: 15 years ago Posts: 84 Rating: 0 |
Re: Exam 2009 Q & A October 20, 2010 10:40PM |
Registered: 18 years ago Posts: 1,501 Rating: 0 |
Language: C++ (QT)[..] Signals: void foundFile(QString fileName);
Language: C++ (QT)void FileVisitor::processFile(QString filename) { emit foundFile(filename); }
Re: Exam 2009 Q & A October 20, 2010 10:52PM |
Registered: 18 years ago Posts: 1,501 Rating: 0 |
Re: Exam 2009 Q & A October 20, 2010 10:58PM |
Registered: 18 years ago Posts: 1,501 Rating: 0 |
Language: C++ (QT)class MicroLending : public QObject { Q_OBJECT public: bool isEligible(Customer cust, int amount); static MicroLending* getInstance(); protected: MicroLending() { } // Inline declaration as nothing happens here. } // MicroLending.cpp MicroLending::getInstance() { static MicroLending* instance = 0; if(instance == 0) { instance = new MicroLending(); instance->setParent(qApp); //Must be a QObject to setParent() } return instance; }
Re: Exam 2009 Q & A October 20, 2010 11:05PM |
Registered: 18 years ago Posts: 1,501 Rating: 0 |
Language: C++ (QT)Customer cust("ABC Buyer"); int amount = 125000; [..] eligible = MicroLending::getInstance()->isEligible(cust, amount);
Language: C++ (QT)Customer cust("ABC Buyer"); int amount = 125000; [..] MicroLending *ml = MicroLending::getInstance(); eligible = ml->isEligible(cust, amount);
Re: Exam 2009 Q & A October 21, 2010 12:10AM |
Registered: 17 years ago Posts: 472 Rating: 0 |
Re: Exam 2009 Q & A October 21, 2010 08:35AM |
Registered: 13 years ago Posts: 6 Rating: 0 |
Re: Exam 2009 Q & A October 21, 2010 08:49AM |
Registered: 18 years ago Posts: 1,501 Rating: 0 |
Re: Exam 2009 Q & A October 21, 2010 09:10AM |
Registered: 13 years ago Posts: 6 Rating: 0 |
Language: C++ (QT)void FileVisitor::processFile(QString filename) { emit foundFile(filename);}
Language: C++ (QT)FileVisitor *fvis = new FileVisitor; CodeVisitor *cvis = new CodeVisitor(); //codevisitor has a slot processFile(QString fileName) connect(fvis, SIGNAL(foundFile(QString)), this, SLOT(processFile(QString))); //we use "this" because cvis is declared here
Re: Exam 2009 Q & A October 21, 2010 09:17AM |
Registered: 18 years ago Posts: 1,501 Rating: 0 |