You are on page 1of 6

Test Class

============================================

#include <iostream.h>
#include <string.h>
#include <process.h>
#include <conio.h>

enum Subject {math,oop,se};


enum PaperType {mid,final,quiz};

template <class T>


class List{
public :
List () { }
List (int s){
maxSize=s;
used=0;
a= new T [maxSize];
}
//~List () { delete []a;}
bool addObject(T p){
if (!isFull()){
a[used]=p;
used ++;
return true;
}
else
return false;
}
int getMaxSize() { return maxSize;}

int getUsed() { return used;}


bool setObject (int index,T p )
{ if ((index <used )&&(index>=0)){
a[index]=p;
return true;
}
else
return false;
}

bool getObject (int index,T &p )


{ if (!isEmpty()) {
if ((index <used )&&(index>=0)){
p=a[index];
return true;
}
else
return false;
}
else
return false;
}

bool isFull() { return used==maxSize;}


bool isEmpty () { return used==0;}

private :
T *a;
int maxSize;
int used;
};

class Question {
public :
Question () { }
void setNo(int n) {no=n;}
void setStmt(char *s) { strcpy(stmt,s);}
void setA(char *s) { strcpy(a,s);}
void setB(char *s) { strcpy(b,s);}
void setC(char *s) { strcpy(c,s);}
void setD(char *s) { strcpy(d,s);}
void setAns(char s) { ans=s;;}
void setSub(Subject s) {subject=s; }
int getNo() { return no;}
char* getStmt() { return stmt;}
char* getA() { return a;}
char* getB() { return b;}
char* getC() { return c;}
char* getD() { return d;}
char getAns() { return ans;}
Subject getSubject() { return subject;}

private :
int no;
char stmt[256];
char a[256];
char b[256];
char c[256];
char d[256];
char ans;
Subject subject;

};

class QuestionPool {
public :
QuestionPool():ls(20) {}
bool addQuestion(Question p)
{ return ls.addObject(p);}
bool getQuestion(int index,Question &p)
{ return ls.getObject(index,p);}
bool setQuestion(int index,Question p)
{ return ls.setObject(index,p);}
List <Question> getSubjectQuestions(Subject s) {
List <Question> t(20);
Question q;
int i=0;
while (i<ls.getUsed()){
ls.getObject(i,q);
if (q.getSubject()==s)
t.addObject(q);
i++;
}
return t;

}
private :
List <Question> ls;
};

class Paper{
public :
Paper ():ls(20) { }

void setPaper(Subject s,PaperType t,QuestionPool p){


subject=s;
paperType=t;
ls=p.getSubjectQuestions(s);
}
void printPaper () { cout<<"Subject ="<<subject<<endl;
cout <<"Papar = "
<<paperType<<endl;
Question q;
int i=0;
while (i<ls.getUsed()){
ls.getObject(i,q);

cout<<q.getStmt()<<endl;
cout<<q.getA()<<endl;
cout<<q.getB()<<endl;
cout<<q.getC()<<endl;
cout<<q.getD()<<endl;

cout<<q.getAns()<<endl;

cout<<"......................."<<endl;
i++;
}

private:
Subject subject;
PaperType paperType;
public : List <Question>ls;

};
class StudentExam {
public :
StudentExam () { obtainedMarks=0;totalMarks=2;}
void setId(int d) { id=d;}
void setName(char *n) { strcpy(name,n);}
void setTotalMarks(int t) { totalMarks=t;}
void setObtainedMarks(int t) { obtainedMarks=t;}
int getId() { return id;}
char* getName() { return name;}
int getTotalMarks() { return totalMarks;}
int getObtainedMarks() { return obtainedMarks;}
void takeExam(Paper p) {
system("cls");
cout<<" Hello Mr : "<<getName()<<endl;
cout<< " Are u ready to take exam ....
presskey"<<endl;
cout.flush();
getch();

int i=0;
int k=1;
Question q;
char a;
while (i<p.ls.getUsed()){
p.ls.getObject(i,q);
cout<<"Question no = "<<k<<" ";
cout<<q.getStmt()<<endl;
cout<<"a) "<<q.getA()<<endl;
cout<<"b) "<<q.getB()<<endl;
cout<<"c) "<<q.getC()<<endl;
cout<<"d) "<<q.getD()<<endl;
cout<<" Enter correct Answer ";
cin>>a;
if (a==q.getAns())
obtainedMarks++;
cout<< "
................................."<<endl;
k++;
i++;
}

private :
int id;
char name[20];
int totalMarks;
int obtainedMarks;
};

void main() {
QuestionPool qp;
Question q;
q.setNo(1);
q.setStmt("Objact is an instance of .......");
q.setA("template"); q.setB("class"); q.setC("function");
q.setD("none");
q.setAns('b');q.setSub(oop);
qp.addQuestion(q);
q.setNo(2);
q.setStmt("Set is a collection ....... elements");
q.setA("distinct"); q.setB("ordered"); q.setC("unordered");
q.setD("none");
q.setAns('a');q.setSub(math);
qp.addQuestion(q);
q.setNo(3);
q.setStmt("For me OOP is very ....... course");
q.setA("boring"); q.setB("intersting"); q.setC("taugh");
q.setD("easy");
q.setAns('d');q.setSub(oop);
qp.addQuestion(q);
Paper p;
p.setPaper(oop,mid,qp);
//p.printPaper();
StudentExam se;
se.setId(10);
se.setName("Bilal");
se.takeExam(p);
cout<<"..............................."<<endl;
cout<<" TotalMarks="<<se.getTotalMarks()<<endl;
cout<<" ObtainedMarks="<<se.getObtainedMarks()<<endl;

http://www.ravianeducation.blogspot.com
FARHAN: 03008855006