You are on page 1of 5

ROLL NO 150252

CLASS BEE 7-B


NAME RIMSHA KANWAL
Exercise 1:
1. Create a class named Student with following attributes
a. RollNumber (Public Property)
b. Name (Public Property)
c. Student() (Constructor) // Sets roll number to 10
d. ~Student() (Destructor)
2. Create another class named UniversityStudent which is derived from class Student and has fol
a. RollNumber (Public)
b. UniversityStudent () (Constructor) // Sets roll number to 20
c. ~ UniversityStudent () (Destructor)
3. Create a class named CSStudent which is derived from class UniversityStudent and has followi
a. RollNumber (Public)
b. PrintRollNumbers() (Public Function)
c. CSStudent () (Constructor)
d. ~CSStudent () (Destructor)
create a method named TestStudent () which initializes an instance of CSStudent class using
/////////////////////////////////////////// SOLUTION///////////////////////////////////
#include<iostream>
#include<string>
using namespace std;
class Student
{ public:
int Rollno;
char Name[30];
Student()
{RollNo=20;
cout<<"STUDENT CLASS CREATED"<<endl;
}
~Student()
{
cout<<"STUDENT CLASS DESTROYED"<<endl;
} };
class University_Student:public Student
{public:
int RollNo;
University_Student()
{RollNo=21;
cout<<"UNIVERSITY CLASS CREATED"<<endl;
}
~University_Student()
{
cout<<"UNIVERSITY CLASS DESTROYED"<<endl;}
};
class CSSStudent:public University_Student
{ public:
int RollNo;
CSSStudent()
{RollNo=22;
cout<<"CS STUDENT CLASS CREATED"<<endl;
}
~CSSStudent()
{
cout<<"CS STUDENT CLASS DESTROYED"<<endl;
} print_RollNo()
{
cout<<Student::RollNo<<endl;
cout<<University_Student::RollNo<<endl;
cout<<CSSStudent::RollNo<<endl;
}
};

}
int main()
{
Test_Student();
}
void Test_Student()
{
CSSStudent *STUDENT=new CSSStudent();
STUDENT->Print_RollNo();
STUDENT->~CSSStudent();

///////////////////////////////////////////////////////////////////////////////////////
Exercise 2:
In this method you will create an array of CSStudent class (created in Exercise 1), initialize
To accomplish the task:
a. Overload constructor in CSStudent class to accept an integer value (To set roll number value
b. Create an array of class CSStudent to contain 10 objects.

/////////////////////////////////////////SOLUTION//////////////////////////////////////
#include <iostream>
#include<string>
using namespace std;
class Student
{ public:
int RollNumber;
char Name[30];
Student()
{ RollNo=20;
cout<<"STUDENT CLASS CREATED"<<endl;}
~Student()
{cout<<"STUDENT CLASS DESTROYED"<<endl;}
};
// University Student Class //
class UniversityStudent:public Student
{public: int RollNo;
UniversityStudent()
{
RollNo=20;
cout<<"UNIVERSITY STUDENT CLASS CREATED"<<endl;}
~UniversityStudent()
{
cout<<"UNIVERSITY STUDENT CLASS DESTROYED"<<endl;
}
};
/// CSS STUDENT CLASS ////
class CSSStudent:public UniversityStudent
{public:
int RollNo;
CSSStudent()
{RollNo=30;
cout<<"CSS STUDENT CLASS CREATED"<<endl;
}
~CSSStudent()
{cout<<"CSS STUDENT CLASS DESTROYED"<<endl;
} printRollNo()
{cout<<Student::RollNo<<endl;
cout<<UniversityStudent::RollNo<<endl; cout<<CSSStudent::RollNo<<endl;}
};
// TEST STUDENT //
void TestStudent()
{CSSStudent *STU=new CSSStudent();
STU->printRollNo();
STU->~CSSStudent();
}
int main()
{TestStudent();
}
///////////////////////////////////////////////////////////////////////////////////////
Exercise 3:
In this exercise you will change the classes created in exercise 1 by adding / removing members
////////////////////////////////////////////////////////////////SOLUTION///////////////
#include <iostream>
#include<string>
using namespace std;
/// STUDENT CLASS ///
class Student{ private: int RollNo;
char name[30];
Student(){ RollNo=20;
cout<<"STUDENT CLASS CREATED"<<endl;}
~Student()
{cout<<"STUDENT CLASS DESTROYED"<<endl;} public:
int getRollNo()
{return RollNo;}
char getName()
{ return Name;}
void setRollNo(int RollNo)
{
this->RollNo=RollNo;} void
setName(char Name)
{ this-
>Name=Name; }
protected:char Grade;
};
class UniversityStudent:public Student
{private:
int RollNo;
int science;
int math;
UniversityStudent()
{
mingrade=40;
cout<<"UNIVERSITY CLASS CREATED"<<endl;
}
~universitystudent()
{
cout<<"UNIVERSITY CLASS DESTROYED"<<endl;
} public: void
setRollNo(int RollNo)

{ RollNo=RollNo;
}
void setscience(int science)

{ eng=eng; }
void setmath(int math)

{ math=math;
} int
getRollNo()
{ return
rollno; }
int getscience()
{ return
science; }
int getmath()
{ return
math;
}

protected: char
University_name; int
mingrade;
};
class CSSStudent:public UniversityStudent
{ private: int
RollNo; int CN;
CSSStudent()
{
cout<<"CSS STUDENT CLASS CREATED"<<endl;
}
~csstudent()
{
cout<<"CSS STUDENT CLASS DESTROYED"<<endl;
}
void Calculate_Grade()
{
if(CN<mingrade || getmath()<mingrade || getscience()<mingrade)
{Grade='F';
}
else
{ Grade='P'; }
} public:
void CNset(int CN)
{ this->CN=CN;
}
char getGrade()
{ return Grade;
}

void Calculate()
{
Calculate_Grade();
}

void Calculate(int a)
{
mingrade=a;
Calculate_Grade();
}
}; int
main()
{
CSSStudent stud;
stud.setmath(20);
stud.setscience(80);
stud.setCN(40);
stud.Calculate();
cout<<"Minimum passing point 40 = "<<stud.getGrade()<<endl;
stud.Calculate(20);
cout<<"Minimum passing point 70 = "<<stud.getGrade()<<endl;
return 0;
}
///////////////////////////////////////////////////////////////////////////////////////

You might also like