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

Please write the coding clearly.I need to understand how to solve this question.

ID: 3875424 • Letter: P

Question

Please write the coding clearly.I need to understand how to solve this question.

CS/OCT 2016/CSC125/128/ITC120 CONFIDENTIAL QUESTION 2 Based on the following diagram: Height Length base a) Write the function definition for the following tasks: ) A function named rectArea () that calculate and return the area of the A function named triArea ( ) that calculate and return the area of the triangle. It b) Write a main function that allows a user to enter a height, a length and a base. Then, rectangle. The function receives the length and height as parameters. receives the height and base as parameters. calculate the area of the above diagram by calling all functions in a). Lastly display the area of the rectangle, area of the triangle and the area of above diagram. (15 marks) END OF QUESTION PAPER D Hak Cipta Universits Teknologl MARA CONFIDENTIAL

Explanation / Answer

calculate the area of rectangle and triangle in c++:-

(A)simple syntax for rectangle & triangle:-

i) int rectarea(int,int);

int rectarea(int l,int b) //using calculate area of rectangle

{

return(l*b);

}

ii) float triarea(float,float);

float triarea(float bs,float ht) //using calculate area of triangle

{

return((bs*ht)/2);

}

program:- (B)

#include<iostream.h>

using namespace std;

#include<conio.h>

#include<stdio.h>

int rectarea(int,int);

float triarea(float,float);

int main()

{

int l,b;

float ht,bs;

cout<<"Enter length and breadth of rectangle:";

cin>>l>>b;

cout<<"Enter base and height of triangle:";

cin>>bs>>ht;

cout<<" Area of rectangle is "<<rectarea(l,b);

cout<<" Area of triangle is "<<triarea(bs,ht);

}

int rectarea(int l,int b)

{

    return(l*b);

}

float triarea(float bs,float ht)

{

   return((bs*ht)/2);

}

output:-

sample input:

Enter length and breadth of rectangle:36

Enter base and height of triangle:44

sample output:

Area of rectangle is 18

Area of triangle is 8