BSEE21036 Lab18a Oop
BSEE21036 Lab18a Oop
BSEE21036 Lab18a Oop
Signature: ____________________________
Objective
The objective of this lab is to observe the basic knowledge of programming in C++.
Equipment and Component
Component Value Quantity
Description
Computer Available in lab 1
Conduct of Lab
1. Students are required to perform this experiment individually.
2. In case the lab experiment is not understood, the students are advised to seek help from
the course instructor, lab engineers, assigned teaching assistants (TA) and lab
attendants.
Virtual inheritance is a mechanism in C++ used to resolve the "diamond problem," which occurs when a
class inherits from two classes that share a common base class. Virtual inheritance ensures that only one
copy of the common base class is shared among the derived classes, preventing ambiguity and redundant
data. It is achieved by using the virtual keyword during the inheritance declaration.
Lab Task
Part A [Marks: 5]
// Clean up memory
for (int i = 0; i < numberShapes; ++i) {// for loop condition
delete shapes1[i];// deleting the shape
}
delete[] shapes1;
//task02
#include <iostream>// preproceesar
#include <cmath>
using namespace std;// cout library
public:
Rectangle(double L, double W) : Length(L), Width(W) {}
public:
Circle(double r) : Radius(r) {}
double getArea() const override {
return M_PI * Radius * Radius;
}
public:
Triangle(double B, double H) : Base(B), Height(H) {}
int main() {
float RectL, RectW, TriangB, TriangH, Rad;//// declaration
cout<<"Enter the length of Rectangle"<<endl;// output and moving to next line
cin>>RectL;// input from user
cout<<"Enter the Width of Rectangle"<<endl;// output and moving to next line
cin>>RectW;// input from user
cout<<"Enter the Base of Triangle"<<endl;// output and moving to next line
cin>>TriangB;// input from user
cout<<"Enter the Height of Triangle"<<endl;// output and moving to next line
cin>>TriangH;// input from user
cout<<"Enter the Radius"<<endl;// output and moving to next line
cin>>Rad;// input from user
// Clean up memory
for (int i = 0; i < numShapes; ++i) {// for loop condition
delete shapes[i];
}
return 0;
}
//task02
Assessment Rubric for Lab