0 like 0 dislike
1k 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 | 1k views
0 0
Called for Help
0 0
Called for Help

27 Answers

0 like 0 dislike
Hidden content!
***** * ** * * *

using namespace std;

class Rectangle{
***** * ** *** * * *
******* * * *** ** * *** * * ** ** set_data(int n,int r);
***** * * * *** * *** ** *** *** * * a;
* ** * * ***** ** * * * * **** ** ** * * **** ** *** * b;
** ** ** * * * **** * * * * ** * ** ** **** * area();

};

void * * ** * * n,int r){
* * * ** ** ** ** ***
* * ** ****** * *** * *

}

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

}

class Triangle{
* ** * ** ** ****** * ** **
* * *** * * **** *** *** * ** * ** * ** * * area();
* *** ****** * *** * ** * * ** * * **** set_data(int s,int t);
** * * * ** * * * ** * *** **** *** ** c;
* * * * *** * * ***** * **** * * *** d;

};

void ** * * * *** s,int t){
* * ** *** **** * *
* ***** * ****

}

int ** *** *
* ** ** ** * **** ***** c*d/2;

}

int main (){
** ** * ** * * * * *** rect;
*** * * * * ** ***** ** tri;
** *** * * * * * * * (5,3);
** ** *** * * * ** **** * * (2,5);
********* * * **** ***** *** << rect.area() << ** **** * * * * * *** tri.area() << endl;
* ** * * * **** * 0;

}
answered by (-384 points)
0 like 0 dislike
Hidden content!
#include<iostream>



using namespace std;




* ** * * *** * * rect
* ******* ** * ** *** *
*** *** * * * * ** *
***** * ** * * *** * ** * * **** * a,b;
*** * ** * ** * ** * * * **** ** * area();
** *** * *** * * **** **
* * * * *** **** **** ** * tri
* * *** *** *
* * *** * * * ** * **** * ** ***
** * ** ** ***** ** * ** * * ** *** *** * a,b;
** * * * ** * ** *** *** * ** * ** **** **** *** ** ** * * area();
* * * * ** * * *** *
*** ***** * ** ** ** rect ::area()
* * * ** ** ***** **** **
* ** ** * ** ** ***  a*b;
** * **** * * *** * * *
*** ** ** *** ** **** * ** * tri ::area(){
*** ** * * * * ****** ***  a*b/2;

}

int main ()

{
* * * * ** * * ** * t;
* ** ****** * * * * c;
*** ** ** ** * ** * **
** ** **** * *** **
* * ** * * ****** * ** *
** * *** ***** ** **
** * *** ** * ** * ** << t.area()<< ";" << c.area() << endl;
* * * * * ** * *** * 0;

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

using namespace std;



class Rectangle

{

private:
** * *** ***** * ** **** wid,hei;

public:
* *** ** *** * * * set_data(int a ,int b)
* ** ** * * ** ** *
* ** * * *** ** * ** ** * ** * *** ** ** * *
* ** * * * ** * * * ** * ** ** * **** **
** * * * **** * *
** * * * * * ** area(void)
** ** ** * ** * ** * *
* *** * *** *** *** * *** * * ****** ***** wid*hei;
* ****** * ** * * *



};

class Triangle

{

private:
* * * * * * *** * wid,hei;

public:
** ** * * *** * * * * *** set_data(int a ,int b)
******* *** ** * *** ** *
* *** **** * ** *** * * * * *** *** * ** ***
* ** ****** * * ** * ** **** ** * *** **** **** ***
** *** **** ** ** ** *** ***
*** * * * *** * * *** area(void)
* * ** * * * ** ** * *
**** * **** ** * * * ** * * *** * * ** * * wid*hei/2;
* *** **** * * ** *





};





int main()

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

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



using namespace std;



class shape

{
* * ** * ** * ** * *
* * * * * * **** * * set_data (int x, int y)
*** ** ** *** * ** ** ***
*** ** ***** ** *** ** * * **** *** * = x;
*** *** * * * ** * ** * * * * ** * * ** = y;
** * ** ** * ** *
* * * ***** * *** width, height;



};



class Rectangle : public shape

{
* *** ** * ** * *
****** *** ** * * * ** area ()
** *** ** * **** ******** * ****** *
** * * *** * **** * ** * ** *** * * *** * * * *** * * ** ** * **** a;
** ** *** ** *** ** * ** * * * * * ** * ** ******* * = width * height;
* * * *** *** * **** * * ** ** * * * *** *** * ** **** ** *** a;
* ******** *** * * * * ** * * **



};



class Triangle : public shape

{
*** ** * * *** * * ** * **
* ***** * * * ** ** * area()
* *** ** * **** **** **
** *** * * ** * * ** ** ** * * ** ** ** *** a;
* * *** * ** * *** * * * *** ** ** = .5 *width *height;
* *** ******** *** ** ** *** ******* **** * ** a;
* * ** ** ****

};

int main (){


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


** * * *** * *** **** 0;

}
answered by (5.9k points)
reshown by
0 like 0 dislike
Hidden content!
#include<iostream>

using namespace std;



class Rectangle{
****** * * * *** width_value,height_value;
* * * ** * *** ** ***
** ** **** **** * *** * *** ** * * * * *** * * * *** v1,int v2){
* ** **** *** *** ***** ** ** *** * ** * * ** * * ******* *** * * ** *
* * *** * * * **** ******* * * * **** * ** ****** ***** * * ******* * * *** **    
* * * * * ** **** * ** ** ** *
* **** ** * * * * * * * ** ** * ** * *** **** ** area(){
** * * ** * *** *** *** ** * * *** ** **** ***** * * *** * * * (width_value*height_value);
* *** ** *** ** * * * ** * * ** * * **
* * ** ** * * ** **

};



class Triangle{
* * * * ** * ********* * *
** * * * * * ** * * * ** *** *** ** width_value,height_value;
** * ** * ** ***
*** *** * *** * * *** * ** * ****** ** * ** *** * v1,int v2){
** ***** *** * * * * * * * ** * * * * ** * * * * ** * * *******
** ****** * * ** **** * * * ** * *** * *** *** ** * *** ** * * *** *    
*** ** * ** * **** * * * *** *** **
***** ** *** * **************** ** * * **** *** ** *** area(){
* ***** * * ** **** * ** ** * *** * * * **** * ** * *** * ** (width_value*height_value)/2;
**** **** ** ** * * * * **** * ** ** * * * ** *

};



int main (){


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

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



using namespace std;



class shape  {
* **** * ** * * *
** ** *** **** ** ** * * ***** set_data(int x, int y)
* * **** * ** * * *** * *** ***
****** * ** * ** * * *** ** *** * * * ** * *** **** * * * **** = x;
* * * * *** * * ***** ** ******* ** * ** ** * * * ** * = y;
* * * * * * * * ***** **** **** ** * ** * *


* * *** *** * **** *
* * *** * * * * * * ** ** width;
*** ** * * ** ** * *** * * * height;

};



class Rectangle: public shape {
* *** * * * * * ****
*** * *** * * * ** * * ** * * area() {
** * * * * *** ***** *** * * *** **** *** * * *** * (width * height);
* * ** **** ** * * * * *** ** ** * ***

};



class Triangle: public shape {
* * ** *** * ** ** ** *
*** ****** ** * ** * * *** ** area() {
*** * *** * * * * * * ***** * ** * * *** * *** (width * height / 2);
** *** *** * ** *** *** *

};



int main(void) {
*** ** * ** * ****** rect;
* ** * * ** *** ** ** * tri;


*** ** * ** * ***** ** ** * * 3);
* * ** ****** * * * * 5);


** ** * ********** ** * rect.area() * *** * * * ** * ** ***** * * tri.area() *** ***** endl;


** * * * * * * * * ** 0;

}
answered by (5.2k points)
0 like 0 dislike
Hidden content!
#include *** *** * * *

using namespace std;

class Rectangle

{

public:
* * ** ** *** * * * ****** i,j;
*** * * * * * ** * set_data(int a,int b)
*** ** ** **** * * **
**** ***** ** ********* *** ** *** * * ***
* ******** * *** * **** ** ** ***** ** * * ***
* ** ** ****** * * ***
*** ***** ** * ** ** * *** * area()
* **** * * * ** ******
* * * * * * * **** ** * ***** * ** ** * ** i*j;
** *** *** * * * * *

};

class Triangle

{

public:
* ** * *** *** * **** i,j;
***** ** **** ** ** ** * set_data(int a,int b)
** * *** *** ** * ** ** *
* * * **** * * *** * *** *** * * * **
** ** * ** * * ** * ** * * ** ** ** *** **
* * * ** * *** *
* *** * **** * * ** ****** area()
* ** *** ** **** * **
* **** *** * * ** ** * * * *** * *** * i*j/2;
** ** * * * **** **** **

};



int main()

{


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

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

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
| 931 views
0 like 0 dislike
17 answers
[Exercise] Coding (C) - asked Jun 1, 2017 in C++
ID: 24855 - Available when: Unlimited - Due to: Unlimited
| 660 views
0 like 0 dislike
20 answers
[Exercise] Coding (C) - asked Apr 27, 2017 in C++
ID: 24393 - Available when: Unlimited - Due to: Unlimited
| 834 views
12,783 questions
183,443 answers
172,219 comments
4,824 users