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

27 Answers

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 (126 points)
0 like 0 dislike
Hidden content!
#include * * * *



using ** ** std;



class Shape

{
**** **
*** * ** *** ** ******* * width, height;

public:
*** * * * *** ** * **** * * set_data (float a, float b)
* ** * * * ** * *** *
** * *** ***** ** ** ***** ** * * = a;
* * * *** *** ***** ** * ** * ** * * * * ** = b;
* ** * * * **** *

};



class **** public Shape

{

public:
* * * ** * * * * * * * area ()
** *** ***
****** ** ** **** * * ** * **** ** *** * * * (width * height);
***** * ** * ******* ****

};



class ** public Shape

{
* ***
*** **** **** * ** area ()
** ** * * * *** * ***
** ***** ** ** ** * * ** *** *** * * * * * * (width * height / 2);
* ** **** * * * *** ****

};



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

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



using ** std;



class Shape

{
* * *
* ** * * * * ** * *** ** * width, height;

public:
** **** * * ** * * * * set_data (float a, float b)
* *** *** ** **** * ** *
** * *** ** * * * * ** * *** * * **** * = a;
* ** **** * ***** * ***** ** * ** ** ** * * * = b;
* * * * * ** * ****

};



class * * ** public Shape

{

public:
*** ** * * * * * * * area ()
* * * * * ****
******* ** **** * * *** ** ** * * ** * *** * * * *** (width * height);
** ******* * ***

};



class * * * public Shape

{
* *
** * * ** ** * ** area ()
** **** ** * * * ****
* * ** * * ** * * * *** * ** * ** * ***** (width * height / 2);
** *** * ** * *** ** * **

};



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

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



using *** *** std;



class Shape

{
****
* * * **** **** * ** width, height;

public:
* * * * * * ** * * * set_data (float a, float b)
** * *** ** *** ** *
** * * * * * ** * **** * **** = a;
* * ** *** ** * ***** ***** *** ** *** = b;
**** * ** ** * *** ** *

};



class ***** public Shape

{

public:
*** * * ** area ()
* * * * * * ********
* * * * *** ** ***** *** ** ** * * ****** ** * (width * height);
** ** * * **** ** *

};



class * * public Shape

{
**
* ******* ** ** *** **** area ()
* * * ****** * *** * * ***
**** **** ** ****** * **** * * * **** ** (width * height / 2);
* *** * * **** * *

};



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

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

using * * std;



class ** **
*** * * ** * * *
*** * ** * * ** ** *** width;
** ** * ***** * ** * * ** height;
** *** ** * ** ** ** * * * **** * ** **** height);
* ***** **** **** ** * ** area();

};



class ** ****
* ** ** *** * * *******
* * * * ** * * *** width;
** * ** * *** * * **** **** height;
*** ** ** * *** * * * ** * * ** * ** ** * ** height);
* * ** * *** * ******* * * ** area();

};



void * :: * * * * swidth ,float ** * **
*** * * ***** * * * * * = swidth;
** *** * ** ** * * * = ** **

}



float * * :: area(){
* **** * ** ** * ** ** * ** ***** ** ** *** (width * * *

}



void ** * :: * * swidth ,float * *
** *** * * * *** * *** ** = swidth;
* * ** ** *** ** ** * ** * = *

}



float Triangle :: area(){
* *** * ***** * *** * ** **** ** * *** * *** **** * ((width * * * *

}



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

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

using ** std;



class * ** **
* * * * *** ** *** *
* *** * * * ***** * *** ** * width;
** *** *** ****** * * ** * * height;
* * *** ****** ** * *** * * * **** height);
**** * * ** * **** * area();

};



class **
* * *** * *** * ** * ** * * *
**** ** * ** *** ******** width;
* * *** ** * *** height;
***** *** * * * **** * ***** * ***** *** * * * ** **
** ** *** ** **** **** * area();

};



void * :: * ** swidth ,float *** *
*** * ** *** * *** * ** = swidth;
*** * * ***** ** * * * *** = sheight;

}



float * *** :: area(){
** *** *** ***** ** *** ** * * * * ********** (width * * * * *

}



void * :: *** * swidth ,float ** *
* *** * ** * *** * ** * = swidth;
*** * *** * *** * ***** * ** = sheight;

}



float Triangle :: area(){
** * **** * ** * * * * ****** ** **



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

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



using namespace std;



class Rectangle{

public:
** ** ** ** ***** ** ** set_data(int H, int W){
* * ** ***** * * * * ** ****** ***** ** ** = W;
* ** * * ***** ** ** *** * ** * ** * * * * * * ***** = H;
** * * *** ** * *
* * ** * ****** * * *** area(){
* * * ** * * * * * **** ** * *** ****** **** *** ** *
* ** *** *** * ** *** *



private:
* ** *** * **** * * * r_width;
*** *** *** * ** ** r_height;



};



class Triangle{

public:
** * *** ****** *** * *** set_data(int H, int W){
** ** * * * ** * * ** * ** * *** *** = W;
* ***** ** * *** **** ** ** * * * * * = H;
** ** * * ** *** * *
* *** * ******** * *** area(){
* * * * ** ** ** * ** * ** * ** **** *** ** *******
* * ** **** * *****

private:
* * **** ** * * *** * * t_width;
** * *** * ****** t_height;

};



int main()

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

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



using * * ** std;



class * * {
** * *** * ****** *** ***** width,
** ** * * ***
*** *** * ** * ** ** * * ** * * * *
********* * ******** ***** area() **** **

};



void * * * * * (int x, int y) {
* * ** * = x;
* * ** *** * * = y;

}



class * * {
** *** * ******* * base, ***
** ** ** * *
* * * * * ** ** * *** * * * * * *
***** ******* ** ** ****** area() {return *** **

};



void *** * *** (int x, int y) {
* * * ** = x;
** * ** * ** = y;

}



int main (){


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

}
answered by (-218 points)
0 like 0 dislike
Hidden content!
//

// * * *****

// ** *

//

// ** * * by ** on * *

// ** **** * © 2017年 * **** All rights ** *

//


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

#include * * **

using * ** std;



class shape {

public:
*** * * ****** * ** * ****** width, double height){
** * * * * * ** ** **** * ** * *** ** * * = width;
* ** ** ** * * * ** ******** ** **** * * ** = height;
** *** * **** * **



public:
**** * ** *** ** * * * * w;
* ** ** ********* ** h;

};



class **** public shape{

public:
* **** * ****** **** ** area(){
* * * * **** * ***** * *** ** * ***** * * * * * *** *
* **** * **** * **

};



class *** ** public shape{

public:
* * ** *** * ** * area(){
* **** * * ** *** * ** * *** ** * *** * *** ** * ** *** ** **
* * * ** **** ****** * ** *

};



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

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

using ** * std;



class ***

{

public:
** * ** ** ** * **** *** * a,int b);
********** * ** ** ** area();
* * * * *** * ** * ** a_,b_;

};



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

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

}



int ****** ***

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

}





class ****

{
**
** ** * ****** * ** * * ** *** a,int b);
** ** * * **** ** *** ** area();
**** **** *** **** **** a_,b_;

};



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

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

}



int ** * *** *

{
***** * **** ** * ** **** a_*b_;

}



int main ()

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

}
answered by (-324 points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.179.128
©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
| 1.7k 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.2k 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.4k views
12,783 questions
183,443 answers
172,219 comments
4,824 users