0 like 0 dislike
2.4k views

Write class shape with width and height following a constructor that gives value to them.
Then define two sub-classes triangle and rectangle.
Those sub-classes can calculate the area of the shape area().
You need to follow the main() below. Please complete the program.

int main (){

    Rectangle rect;
    Triangle tri;
    rect.set_data (5,3);
    tri.set_data (2,5);
    cout << rect.area() << ";" << tri.area() << endl;
    return 0;
}

 

[Exercise] Coding (C) - asked in C++
ID: 24389 - Available when: Unlimited - Due to: Unlimited

edited by | 2.4k views
0 0
Called for Help
0 0
Called for Help

27 Answers

0 like 0 dislike
Hidden content!
#include ** * ** * ***



using namespace std;



class Triangle

{

public:
*** * * * * ***** **** ** * *


* * * * ******* ** *** * area;

}tri;



class Rectangle

{

public:
**** ** ****** *** * ** * * **** * *


* ** * ** * * * ** area;

}rect;



int main (void)

{


** *** ****** * ** ** rect;
**** **** * * * * * ** ** tri;


*** * **** * *** * ******* * **
** ** ***** *** * * ** * * ** *




* * *** ****** * *** * * ****
* **** ** ** ****** ** * * *** *** *****




* **** *** * ** * * * ***** ** * * * **
* * ** ** * * * * *** * * ** *


** ** ** * ** ** ** * **** rect.area **** * *** *** * * ** *** ** tri.area ** * endl;
** * * **** ** * 0;

}
answered by (-324 points)
0 like 0 dislike
Hidden content!
* **** *** ******

using * * * std;



class Shape{
*


* ***** * *** * ** * ** set_data (int a,int b){
* **** * *** * *
** * ** *** * * * * **



int x;

int y;



};





class * * * public Shape{
* *


* ** * **** *** *** ** * area(){
** *** ***** * *** *** * ** ** **** * * x*y;




* * * * * * *** * * ** * *** *** * ** ***



};

class * * public Shape{
**
*** * ** ** * * * * * * ** area(){
**** * *** * * ** * * *** * **
** * * *** **** ** *





};



int main(){






* *** ******** * ** ****** rect;
** * * ** * * ** ** * tri;


** * ****** * * *** * (5,3);
* *** *** ** * * *** * ** (2,5);


*** **** * * *** ***** * * ** *** ** * * ****** **** * * * * * * * ** * * **** **** endl;
********* ** * ** ** * *** 0;
** * *** * * ** ** ** *
answered by (-34 points)
0 like 0 dislike
Hidden content!
* *** * *** * ** *

using * std;



class Shape{
* *


**** ** **** * ** * ** * * set_data (int a,int b){
*** *** *** * **** *
* ** *** **** ** * *



int x;

int y;



};





class * ** public Shape{
**


** * * * * * ** * area(){
* *** ** * * * * *** ** * * ** * *** *** *** x*y;




** * *** ** * ** *** ** * ** **



};

class * * public Shape{
** **
** * * * * ***** * * * area(){
** * ** ** * * *** ** * ** *
* *** * * *** * * ** * **





};



int main(){






** * * ** * * *** *** ** rect;
*** * *** * * * * * tri;


* * * * * * * *** *** *** (5,3);
* ** * * * *** ** ** * ** * *** (2,5);


* * * ** **** ** * * * * * * * *** *** * * * ** * * *** ** * **** * endl;
** * ** ** **** * *** **** * 0;
* ****** ** *** ** **
answered by (-34 points)
0 like 0 dislike
Hidden content!
* *** ****** * * *

using * * std;


*** * ***
*** *
* * ** * ** ** float ***
* * * * float
* * ** * * *** void * * ** * * **** * **
*** * **** float * *

};


*** *
* **** * * * **
** *** **** * float **
** * ** *** float * ***
** ** ** void * ** ** * *** ****
** * ** ******* float *

};



void * :: ** * ** ** * * *
* *** ** width = * *
* ** ** * * ** = ***

}


** * * * ::
* ** ** * * * ***** return (width * ** **

}



void ** * * :: * * *** ** * * *
* ****** * ** width = ** **
**** ** * * = * ******

}


** * * ** :: * *
* * ** *** * ** ** * **** * *

}



int main (){
* * * * * * **** * rect;
*** ** * ******* ** ** tri;
* *** *** * *** *** *** * * * * **
**** * * * ** * * * * * * (2,5);
* **** * *** * ** * * * * * ** * ** * * ** * * ** * * * ** ** **** * ** endl;
** * * ** * ** * * * ** 0;

}
answered by (-134 points)
0 like 0 dislike
Hidden content!
#include *** *** * **



using namespace std;



class Triangle

{

public:
* * **** **** * *** *** ** *


**** ** *** * * * **** * area;

}tri;



class Rectangle

{

public:
**** ** *** * * * ** * ** * ** * *


* * * *** * *** area;

}rect;



int main (void)

{


* * * * * *** rect;
** * ***** * * ** ****** * **** tri;


**** *** * ** * * * * *** ** *** **
** ** ****** ** ***** * * * *** *** *




** * ** *** * * *** * *** ** ***
** * * * ** * * * * *




** * ** ** * **** ** **** * * * * * * * * ** *
*** ******** ***** *** ** * * * * * * **** *** *


* ** * ** ** * * * * ** * * rect.area * * * * * *** * *** ** * * * ** tri.area * ** * * * endl;
*** *** ** * * *** ** ** 0;

}
answered by (-324 points)
0 like 0 dislike
Hidden content!
#include * *** * * ** **



using namespace std;



class Triangle

{

public:
* ** * * * ** ** *** * * * * *


* ** * * **** ** ** area;

}tri;



class Rectangle

{

public:
** * ** ** * **** * ** * * *


* * ** * **** * ** ** area;

}rect;



int main (void)

{


** *** ** * ** ***** * * rect;
** ** * ***** ** *** tri;


** * ** * **** ** * ** *** *
* ** ** *** ** ***** * * ***** *** *




** ** * * * * ** *** *** ***
***** * ** * ** ******




* * * * ** * ***** * * * *** * ** * ** *** *
** ***** * ** * ****** * * ** ** * ** *


*** ** * * * * *** * ** * ** rect.area * * * ** * ** * ** * ** * * tri.area * ** endl;
* ** * ** * * ** * 0;

}
answered by (-324 points)
0 like 0 dislike
Hidden content!
* * * * ** * *

using * std;



class **

{

public:
** ** * * *** * ***** * *** * * wval, int hval);
* * ** * * ** * * area();
*
* * * * *** *** ** ** * weith;
* ** **** * * * ** height;

};



void * * *** * * wval, int hval)

{
*** ** ****** *** * **** * **
** ** ***** * ** * * ****

}



int * **** ***

{
*** ***** ** * *** ****** * ** *

}



class ****

{
*
* **** * * *** * *** * * ** * wval, int hval);
* * * * ***** * ** area();
** **
* * * **** * * * * weith;
* * * ** *** * **** ** height;

};



void ***** * * * wval, int hval)

{
* * * * ** ** ** ******** *
* ** ** **** ** * ****

}



int ** ** * **

{
** *** ** * *** ** *** * ** ** ***

}



int main (){


***** * * ** * * * ***** * rect;
* ** * * ** * ** * * tri;
****** * * * * ** * * *** * * * * * * (5,3);
*** ** ** ** *** * * ** ** * (2,5);
*** **** * * * *** * * * ** * * * * *** ** ** *** **** * *** ** * * * ** endl;
* * ** * * * ***** * **** 0;

}
answered by (-581 points)
0 like 0 dislike
Hidden content!
#include ** * ** **



using namespace std;



class Rectangle

{
* ** * ***** * ** ** **
** * ****** * * * ** * * ** * * * ** ** * area();
* * ** ****** *** ******** * * ** ** * ** set_data (int aa, int bb);


** ** * *** * * **** *
*** * * ** * * ** ** *** ** * ****** ** ** a;
* * ** * * * * * * * ** ** * ** * * b;

};



class Triangle

{
*** * * ** * * * * * * **
* * * *** *** ** * ** ** * *** * ** * ** ** area();
** **** *** * ** ****** * ** * * * **** ** set_data (int aa, int bb);


*** * **** * * * * ** * *
* * * * ** * * * ** * * ** *** **** * * a;
** ** ******* * * ** * ** *** * ** * ** b;

};



int **** * **

{
* ** * ** * ** ** * * a*b;

}



float *** * *

{
** ******* ** *** * * * * a*b/2.0;

}



void ** * **** aa, int bb)

{
* ** ** ** *** * * ** * = aa;
** * * * * ** * ** * * = bb;

}



void * * * *** aa, int bb)

{
* * * * * ** * ********* = aa;
* ** ** * * * * * ****** = bb;

}





int main (){


* * ** * ** ** *** * ** rect;
**** ** * ** ********* * tri;
** ** **** * * ** *** * *** (5,3);
*** * * * ** ** * * * ** **** (2,5);
*** * ** * * * * * ** *** * rect.area() * * **** * ** * * ** * ** tri.area() ** ***** endl;
* * ****** * * * **** ** 0;

}
answered by (-364 points)
0 like 0 dislike
Hidden content!
#include * * * *** ****



using *** * std;



class shape

{
*****
* ** ** **** **** * length;
* ** * *** * * * ** *** width;

public:
* ** ****** ** ** * *
* * * * * ** ** * * * *** x, int y);

};


* *** *

{
*** *** **** * ***** * = 0;
*** * ** * ** **** * = 0;

}


**** ** x, int y)

{
* * * * * * * * ** * * * = x;
*** * ** ***** *** ** * * * = y;

}



class * *** *

{
*
**** ** * ** * * * * * l;
* *** * *** * ** * ** * * w;
*** ******* * * * ** ar;
* **
** * * *** * * *** ** ** a, int b);
**** * ** *** * * area();



};



void ***** * a, int b)

{
** ** * * * **** * * = a;
** *** ** * * = b;

}



int * ** ** * *

{
* ** * * * *** ** ** * = l*w;
** ** ** ** *** * * ** ar;

}



class * * **** ***

{
*
* * ** * * ** *** l;
* **** * **** * * * w;
** **** * * ** * ** ar;
*
*** * * * * ** * *** *** a, int b);
***** ** ** * ** **** *** area();

};



void **** * a, int b)

{
* **** *** ** * * * = a;
** ** ***** **** *** = b;

}



int ** * *

{
* *** *** ** *** = 0.5 * l * w;
* * * ** ** * * **** ar;

}



int main (){


** ** ** ** **** * * * ** rect;
** * **** ** ** * tri;
** **** * ** *** * ** * *** ** (5,3);
* ** **** *** ** * * ** ******* * (2,5);
** * * *** ** ** ** * ** * * * * * ** * * ** * *** ** ** * * **** ** ** endl;
** *** *** **** * ** * 0;

}
answered by (-189 points)
0 like 0 dislike
Hidden content!
* ** *** * * * ***
**** * * ** std;


** ** * **

{
** ***
** * ** c,int d);

int a;

int b;

int * **

};

void * ** **** c, int d)

{
** * ***** ** ******
*** * ** ** *** * * *** * *

}

int * *

{
** * * * * *** ******** a*b;

}
**** *

{
* ****

void ** ** g,int h);

int e;

int f;

int **

};
* * ** * * g, int h)

{
** ** * ** * ** * *** ****** **
* * ** * * ***** *

}

int * * **

{
** * * * *** ** * * *

}

int main (){


* * ***** ** ****** ** * * *
*** * ** * ** ** tri;
* *** * * * ** * * *** *
***** ** * * * * * ** * *
*** * ** * * * ** * * ** *** *** ***** *** * * * ***** ** * * *** *** * ** ** endl;
***** ** ** * * * ** * ** 0;

}
answered by (-367 points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.59.111
©2016-2025

Related questions

0 like 0 dislike
30 answers
[Exercise] Coding (C) - asked May 18, 2017 in C++
ID: 24769 - Available when: Unlimited - Due to: Unlimited
| 2.5k views
0 like 0 dislike
17 answers
[Exercise] Coding (C) - asked Jun 1, 2017 in C++
ID: 24855 - Available when: Unlimited - Due to: Unlimited
| 1.7k views
0 like 0 dislike
20 answers
[Exercise] Coding (C) - asked Apr 27, 2017 in C++
ID: 24393 - Available when: Unlimited - Due to: Unlimited
| 1.9k views
12,783 questions
183,442 answers
172,219 comments
4,824 users