You are on page 1of 5

Student Class

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

#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream.h>
template<class type>

/*======= List Class ========*/


class List{

public:

/*===== Constructors =====*/

List(){ }
List(int s)
{
maxSize=s;
a= new type[maxSize];
used=0;
}

/*===== Getters=====*/

int getUsed()
{ return used; }

int getMaxSize()
{ return maxSize; }

/*===== IsEmpty =====*/

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

/*===== IsFull =====*/

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

/*===== AddObject =====*/

bool addObject(type obj)


{
if(!isFull())
{
a[used]=obj;
used++;
return true;
}
else
return false;
}

/*===== GetObject =====*/

bool getObject(int index, type &obj)


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

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

/*======= Class Student =======*/


class Student{

public:
/*===== Constructors =====*/

Student()
{
strcpy(name,"Unknown");
id=0;
marks=0;
}

Student(char *n, int d, float m )


{
strcpy(name,n);
id=d;
marks=m;
}

/*===== Setters =====*/

void setName(char *n)


{
strcpy(name,n);
}

void setId(int d)
{
id=d;
}

void setMarks(float m)
{
marks=m;
}

/*===== Getters =====*/

char *getName()
{
return name;
}

int getId()
{
return id;
}

float getMarks()
{
return marks;
}

private:

char name[30];
int id;
float marks;
};

/*======= Client Program =======*/

void main()
{
int no;
cout<<"\nEnter the no of Students that you want to Add: ";
cin>>no;

List<Student>Ls(no);

char name[30];
int id;
float marks;

/*======= Taking Input =======*/

for(int i=1;i<=no;i++)
{
system("cls");
Student ob;

cout<<"\nEnter the Name of ["<<i<<"] Student: ";


cin>>name;
ob.setName(name);

cout<<"\nEnter the Id of ["<<i<<"] Student: ";


cin>>id;
ob.setId(id);
cout<<"\nEnter the Marks of ["<<i<<"] Student: ";
cin>>marks;
ob.setMarks(marks);

Ls.addObject(ob);

system("cls");

Student obj;
/*======= Showing Output=======*/
for(int j=0,k=1;j<Ls.getUsed(),k<=Ls.getUsed();j++,k++)
{
cout<<"\nStudent "<<k<<endl;
Ls.getObject(j,obj);
cout<<"Name: "<<obj.getName()<<endl;
cout<<"Id: "<<obj.getId()<<endl;
cout<<"Marks: "<<obj.getMarks()<<endl;
cout<<endl<<endl;
}

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