0% found this document useful (0 votes)
39 views5 pages

ROLL NO 150252 Class Bee 7-B Name Rimsha Kanwal: // Sets Roll Number To 10

The document describes 3 exercises to create classes in C++. Exercise 1 creates a Student base class and derives UniversityStudent and CSStudent classes from it. Exercise 2 overloads the CSStudent constructor and creates an array of CSStudent objects. Exercise 3 changes the classes created in Exercise 1 by making members private/protected and adding/removing member functions to set/get roll numbers, grades, and calculate grades based on minimum passing criteria.

Uploaded by

Aleena Kanwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views5 pages

ROLL NO 150252 Class Bee 7-B Name Rimsha Kanwal: // Sets Roll Number To 10

The document describes 3 exercises to create classes in C++. Exercise 1 creates a Student base class and derives UniversityStudent and CSStudent classes from it. Exercise 2 overloads the CSStudent constructor and creates an array of CSStudent objects. Exercise 3 changes the classes created in Exercise 1 by making members private/protected and adding/removing member functions to set/get roll numbers, grades, and calculate grades based on minimum passing criteria.

Uploaded by

Aleena Kanwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy