Professional Documents
Culture Documents
ROLL NO 150252 Class Bee 7-B Name Rimsha Kanwal: // Sets Roll Number To 10
ROLL NO 150252 Class Bee 7-B Name Rimsha Kanwal: // Sets Roll Number To 10
}
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;
}
///////////////////////////////////////////////////////////////////////////////////////