"TOJ 5240" C + + Experiment: virtual function

Source: Internet
Author: User

Describe

A shape class and a rectangle class are implemented in C + + and the area function is completed.

The code in the main function is given, please fill it out, and do not include the code that you have given when committing.

int main () {int W, h;while (cin>>w>>h) {shape* p = new Rectangle (w, h); Cout<<p->area () <<endl; Delete p;} return 0;}

Input

There are several groups of input data, one row per group, two positive integers per line, representing the length and width of the rectangle, respectively.

Output

Each group outputs a positive integer that represents the rectangular area.

Sample input

2 3
5 6

Sample output

6
30

#include <iostream>using namespacestd;classshape{ Public:    Virtual intArea () {}};classRectangle: Publicshape{ Public:    intb; Rectangle (intA=0,intb=0): A (a), B (b) {}intArea () {returnA *b; }};intMain () {intW, H;  while(cin>>w>>h) {Shape* p =NewRectangle (W, h); cout<<p->area () <<Endl; Deletep; }    return 0;}

"TOJ 5240" C + + Experiment: virtual function

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.