Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi , So basically i am trying to take in length and width of rectangle in derive

ID: 3634068 • Letter: H

Question

Hi , So basically i am trying to take in length and width of rectangle in derived class, then pass these values to base class where they are multiplied to give area. but obvioulsy the syntax is wrong, can you sort it out, thanks in advance!

Header file

#include<iostream.h>

class area
{
private:

int l,b;

public:

area(int,int);

void showarea();


};

class recta:public area
{
private:

public:

recta(int,int):area(int,int)



};

//////////////////////////////////////////

.cpp file

#include "l test prep.h"
area::area(int a, int br)
{l=a; b=br;
}
void area::showarea()
{
cout<<"Area is "<<l*b<<endl;
}
recta::recta(int len,int wid):area(len,wid){}

///////////////////

main.cpp

#include "l test prep.h"
void main()
{recta rect (5,7);

rect.showarea();
}

Explanation / Answer

/ Declare three object variables of type Rectangle Rectangle small, medium, large; // Create a constructor where the initial work is done Shapes ( ) { // Create the three rectangles small = new Rectangle(2, 5); medium = new Rectangle(10, 25); large = new Rectangle(50, 100); //Print out a header System.out.println("The areas of the rectangles are: "); //Print the details of the rectangles small.write( ); medium.write( ); large.write( ); }//end of constructor Shapes. //All programs have to have a main method public static void main(String [ ] args) { //Start the programm from its constructor new Shapes ( ); }//end of main method. }//end of class Shapes. class Rectangle { //Declare the variables related to a rectangle int length; int width; int area; //Create a constructor that copies the initial values into the object's variables Rectangle (int w, int l) { width = w; length = l; //Calculate the area area = width * length; }//end of constructor Rectangle //Create a method to output the details of the rectangle void write ( ) { System.out.println("The area of a rectangle " + width + " by " + length + " is " + area); }//end of write method. }//end of constructor