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 |
Exam 2009 Q & A September 13, 2010 10:33PM |
Registered: 17 years ago Posts: 472 Rating: 0 |
Language: C++Class CodeVisitor: public QObject{ Q_OBJECT public: CodeVisitor(QString filter “-hâ€, bool recursive = true); void getNumFiles() const; QString getResultString() const; public slots: void processFile(QString filename); private: int m_NumFiles; QStringList m_Result; };
Language: C++ (QT)[...] FileVisitor fv(filter, recursive, symlink); CodeVisitor cv(filter, recursive); connect (fv, SIGNAL(foundFile(QString)), cv, SLOT(processFile(QString))); [...]
Language: C++ (QT)#ifndef MICROLENDING_H #define MICROLENDING_H #include <QObject> #include “bank.h†#include “creditbureau.h†#include “revenueservices.h†class MicroLending: public QObject{ Q_OBJECT public: MicroLending(); ~MicroLending(){} bool isEligible(QString customer, int amount); protected: Customer *m_customer; int m_amount; Bank *bank; CreditBureau *bureau; RevenueServices *sars; }; #endif
Language: C++ (QT)#include “microlending.h†bool MicroLending::isEligible(QString cust, int amt){ m_customer = cust; m_amount = amt; Bank *bank = new Bank(); CreditBureau *bureau = new CreditBureau(); RevenueServices *sars = new Sars(); if(bank->hasSufficientFunds(m_customer, amount) && bureau->hasGoodCredit(m_customer) && sars->hasRegularIncome(m_customer)) return true; else return false; }
Language: C++ (QT)int main(argc, argv){ Customer customer(“John Smithâ€); int amount = 12500; MicroLending *micro = new MircoLending(); if(micro->isEligible(customer, amount)) qDebug() << customer->getName() << “ has been approved†<< endl; else qdebug()<< customer->getName() << “ has been rejected†<< endl; }
microlending.cppLanguage: C++ (QT)#ifndef MICROLENDING_H #define MICROLENDING_H #include <QObject> #include “Bank.h†#include “CreditBureau.h†#include “RevenueServices.h†class MicroLending:: public QObject{ Q_OBJECT public: ~MicroLending(){} static MicroLending *instance(); bool isEligible(Customer customer, int amount); protected: MicroLending(); Bank *bank; CreditBureau *bureau; RevenueServices *sars; }; #endif
Language: C++ (QT)#include “MicroLending.h†MicroLending *MicroLending::instance(){ static Singleton *s_instance = 0; if(s_instance == 0){ s_instance = new MicroLending(); s_instance->setParent(qApp); } return s_instance; }
Language: C++QMetaObject const *baseClassMetaObject = f->metaObject()->superClass(); QString baseClassName = (baseClassMetaObject != 0) ? baseClassMetaObject->className() : QString();
Re: Exam 2009 Q & A September 14, 2010 03:53PM |
Registered: 13 years ago Posts: 50 Rating: 0 |
Re: Exam 2009 Q & A September 14, 2010 09:20PM |
Registered: 18 years ago Posts: 1,424 Rating: 0 |
Language: C++ (QT)QMetaObject const *baseClassMetaObject = f->metaObject()->superClass(); QString baseClassName = (baseClassMetaObject != 0) ? baseClassMetaObject->className() : QString();
Re: Exam 2009 Q & A September 14, 2010 10:28PM |
Registered: 17 years ago Posts: 472 Rating: 0 |
Re: Exam 2009 Q & A September 15, 2010 11:07AM |
Registered: 17 years ago Posts: 308 Rating: 0 |
Re: Exam 2009 Q & A September 15, 2010 09:59PM |
Registered: 17 years ago Posts: 308 Rating: 0 |
Re: Exam 2009 Q & A September 16, 2010 12:20AM |
Registered: 17 years ago Posts: 472 Rating: 0 |
Re: Exam 2009 Q & A September 16, 2010 09:31AM |
Registered: 17 years ago Posts: 308 Rating: 0 |
Re: Exam 2009 Q & A September 17, 2010 12:33AM |
Registered: 17 years ago Posts: 472 Rating: 0 |
Re: Exam 2009 Q & A October 11, 2010 11:31PM |
Registered: 17 years ago Posts: 472 Rating: 0 |
Re: Exam 2009 Q & A October 12, 2010 09:15AM |
Registered: 17 years ago Posts: 308 Rating: 0 |
Re: Exam 2009 Q & A October 12, 2010 02:44PM |
Registered: 17 years ago Posts: 472 Rating: 0 |
Re: Exam 2009 Q & A October 13, 2010 01:34PM |
Registered: 15 years ago Posts: 84 Rating: 0 |
Re: Exam 2009 Q & A October 14, 2010 01:02AM |
Registered: 15 years ago Posts: 50 Rating: 0 |
Re: Exam 2009 Q & A October 14, 2010 12:05PM |
Registered: 14 years ago Posts: 35 Rating: 0 |
Re: Exam 2009 Q & A October 15, 2010 12:09PM |
Registered: 13 years ago Posts: 50 Rating: 0 |
Re: Exam 2009 Q & A October 15, 2010 12:22PM |
Registered: 17 years ago Posts: 472 Rating: 0 |
Re: Exam 2009 Q & A October 15, 2010 12:30PM |
Registered: 13 years ago Posts: 50 Rating: 0 |
Re: Exam 2009 Q & A October 15, 2010 12:32PM |
Registered: 13 years ago Posts: 50 Rating: 0 |
Re: Exam 2009 Q & A October 15, 2010 02:24PM |
Registered: 15 years ago Posts: 23 Rating: 0 |
Re: Exam 2009 Q & A October 15, 2010 03:12PM |
Registered: 13 years ago Posts: 50 Rating: 0 |
Re: Exam 2009 Q & A October 16, 2010 08:13PM |
Registered: 15 years ago Posts: 50 Rating: 0 |
Language: C++ (QT)Class CodeVisitor: public QObject{ Q_OBJECT public: CodeVisitor(QString filter “-hâ€, bool recursive = true); void getNumFiles() const; QString getResultString() const; public slots: void processFile(QString filename); private: int m_NumFiles; QStringList m_Result; };
Language: C++ (QT)[...] FileVisitor fv(filter, recursive, symlink); CodeVisitor cv(filter, recursive); connect (fv, SIGNAL(foundFile(QString)), cv, SLOT(processFile(QString))); [...]
Re: Exam 2009 Q & A October 16, 2010 08:25PM |
Registered: 17 years ago Posts: 472 Rating: 0 |
Re: Exam 2009 Q & A October 16, 2010 08:26PM |
Registered: 17 years ago Posts: 472 Rating: 0 |
Re: Exam 2009 Q & A October 16, 2010 09:03PM |
Registered: 17 years ago Posts: 472 Rating: 0 |
Re: Exam 2009 Q & A October 16, 2010 09:04PM |
Registered: 15 years ago Posts: 23 Rating: 0 |
Re: Exam 2009 Q & A October 17, 2010 11:04AM |
Registered: 18 years ago Posts: 1,424 Rating: 0 |
Re: Exam 2009 Q & A October 17, 2010 05:19PM |
Registered: 15 years ago Posts: 50 Rating: 0 |
Re: Exam 2009 Q & A October 19, 2010 10:42AM |
Registered: 13 years ago Posts: 6 Rating: 0 |
Language: C++ (QT)//[i]process.h[/i] #ifndef PROCESS_H #define PROCESS_H #include <QObject> class Process : public QObject { Q_OBJECT public: virtual ~Process() {} virtual int getNumFiles() const = 0; virtual QString getResultString() const = 0; public slots: virtual void processFile(QString fileName) = 0; }; #endif // PROCESS_H
Language: C++ (QT)//[i]codevisitor.h[/i] #ifndef _CODE_VISITOR_H_ #define _CODE_VISITOR_H_ #include <QStringList> #include <QObject> #include "process.h" class CodeVisitor : public Process { Q_OBJECT public: CodeVisitor() {} int getNumFiles() const; QString getResultString() const; public slots: void processFile(QString fileName); private: int m_NumFiles; QStringList m_Result; }; #endif
Language: C++ (QT)//[i]codevisitor.cpp[/i] #include <QDebug> #include <QFile> #include <QTextStream> #include "codevisitor.h" 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++; } int CodeVisitor::getNumFiles() const { return m_NumFiles; } QString CodeVisitor::getResultString() const { return m_Result.join("\n"); }
Language: C++ (QT)//[i]findextension.h[/i] #ifndef FINDEXTENSION_H #define FINDEXTENSION_H #include <QStringList> #include <QObject> #include "process.h" class FindExtension : public Process { Q_OBJECT public: FindExtension() {} int getNumFiles() const; QString getResultString() const; public slots: void processFile(QString fileName); private: int m_NumFiles; QStringList m_Result; }; #endif // FINDEXTENSION_H
Language: C++ (QT)//[i]findextension.cpp[/i] #include <QDebug> #include "findextension.h" void FindExtension::processFile(QString fileName) { if (fileName.contains(".txt")) { m_Result << QString(fileName); m_NumFiles++;} } int FindExtension::getNumFiles() const { return m_NumFiles; } QString FindExtension::getResultString() const { return m_Result.join("\n"); }
Language: C++ (QT)//[i]type.h[/i] #ifndef TYPE_H #define TYPE_H #include <QObject> //#include <qstd.h> #include "process.h" #include "codevisitor.h" #include "findextension.h" //using namespace qstd; class Type : public QObject { Q_OBJECT public: Type(); void VisitCode(); void FindExe(); int getNoFiles(); QString getList(); public slots: void process(QString fileName); private: Process *m_Process; }; #endif // TYPE_H
Language: C++ (QT)//[i]type.cpp[/i] #include <qstd.h> #include "type.h" #include "codevisitor.h" #include "findextension.h" using namespace qstd; Type::Type() { m_Process = new FindExtension(); } void Type::VisitCode() { delete m_Process; m_Process = new CodeVisitor(); } void Type::FindExe() { delete m_Process; m_Process = new FindExtension(); } int Type::getNoFiles() { return m_Process->getNumFiles(); } QString Type::getList() { return m_Process->getResultString(); } void Type::process(QString fileName) { m_Process->processFile(fileName); }
Language: C++ (QT)//[i]codevisitor-test.cpp[/i] #include <FileVisitor.h> #include <argumentlist.h> #include "type.h" #include <QApplication> #include <qstd.h> using namespace qstd; void usage(QString appname) { cout << appname << " Usage: \n" << "codevisitor [-r] [-d startdir] [-f filter] [file-list]\n" << "\t-r \tvisitor will recurse into subdirs\n" << "\t-d startdir\tspecifies starting directory\n" << "\t-f filter\tfilename filter to restrict visits\n" << "\toptional list of files to be visited" << endl; } int main(int argc, char** argv) { ArgumentList al(argc, argv); QString appname = al.takeFirst(); /* app name is always first in the list. */ if (al.count() == 0) { usage(appname); exit(1); } bool recursive(al.getSwitch("-r")); QString startdir(al.getSwitchArg("-d")); QString filter(al.getSwitchArg("-f")); FileVisitor *fvis = new FileVisitor(filter, recursive); Type *cvis = new Type(); cvis->FindExe(); // VisitCode or FindExe qApp->connect(fvis, SIGNAL(foundFile(QString)), cvis, SLOT(process(QString))); if (startdir != QString()) { fvis->processEntry(startdir); } else if (al.size()) { fvis->processFileList(al); } else return 1; cout << "Files Processed: " << cvis->getNoFiles() << endl; cout << cvis->getList() << endl; return 0; }
Re: Exam 2009 Q & A October 19, 2010 08:29PM |
Registered: 16 years ago Posts: 284 Rating: 0 |