0% found this document useful (0 votes)
3 views1 page

Quiz 2

The document contains a C++ code snippet with errors that need to be corrected. Key issues include missing constructor implementations, a missing semicolon in the Square class's print method, and a missing semicolon after the last cout statement in the main function. After corrections, the code will properly calculate and display the areas of a Rectangle and a Square.

Uploaded by

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

Quiz 2

The document contains a C++ code snippet with errors that need to be corrected. Key issues include missing constructor implementations, a missing semicolon in the Square class's print method, and a missing semicolon after the last cout statement in the main function. After corrections, the code will properly calculate and display the areas of a Rectangle and a Square.

Uploaded by

HANI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Quiz 2

Question 1: Analyze the given code, identify and correct any errors present, and provide the
output after the corrections.

#include <iostream>
using namespace std;

class Shape {
public:
double area() const = 0;
void print() const = 0;
};
class Rectangle : public Shape {
private:
double length;
double width;

public:
Rectangle(double l, double w);

double area() const override {


return length * width;
}

void print() const override {


cout << "Rectangle - Length: " << length << ", Width: " << width;
}
};
class Square : public Shape {
private:
double side;

public:
Square(double s);

double area() const override {


return side * side;
}

void print() const override {


cout << "Square - Side: " << side
}
};

int main() {
Rectangle rectangle(5, 8);
Square square(4);

cout << "Rectangle Area: " << rectangle.area() << endl;


rectangle.print();
cout << endl;

cout << "Square Area: " << square.area() << endl;


square.print();
cout << endl
return 0;
}

You might also like