int main () { //first example CRectangle rect; rect.set_values (3,4); cout << "area: " << rect.area() << "\n"; //example of internal vs external class func defn CRectangle_internal rect_internal; cout << "area internal: " << rect_internal.area() << "\n"; rect_internal.set_values(3,4); cout << "area internal: " << rect_internal.area() << "\n"; //example of multiple instances CRectangle rectb; rectb.set_values(5,6); cout << "areab: " << rectb.area() << "\n"; //constructors CRectangle_con rectc; CRectangle_con rectd (5,6); cout << "rectc area: " << rectc.area() << endl; cout << "rectd area: " << rectd.area() << endl; //destructor //implicit default // CRectangle_implicit rect_implict (2,3); // CRectangle_implicit rect_implicit2 (rect_implicit); // cout << "rect_implict: " << rect_implict.area() << endl; // cout << "rect_implict2: " << rect_implict2.area() << endl; // CExample ex (2,3); // CExample ex2 (ex); //pointers return 0; }
int main () { CRectangle recta(3,4); CRectangle rectb(5,6); CRectangle rectc; recta.set_values(4,4); cout << rectc.n << endl; cout << "recta area: " << recta.area()<<endl; cout << "rectb area: " << rectb.area()<<endl; cout << "rectc area: " << rectc.area()<<endl; CRectangle a; CRectangle *pb = new CRectangle; CRectangle *pc = &a; CRectangle *pe = new CRectangle(3,4); CRectangle *pd = new CRectangle[2]; a.set_values (1,2); pd->set_values (5,6); pd[1].set_values (7,8); cout << "a area: " << a.area() << endl; cout << "b area: " << pb->area() << endl; cout << "*c area: " << pc->area() << endl; cout << "d[0] area: " << pd[0].area() << endl; cout << "d[1] area: " << pd[1].area() << endl; cout << "e area: " << pe->area()<<endl; if ( pc->isitme(a) ) cout << "yes, &a is pc"<<endl; return 0; }
int main(){ CRectangle rect; rect.set_values(3, 4); cout << "area: " << rect.area(); return 0; }
int main () { CSquare sqr; //pilha CRectangle rect; //pilha sqr.set_side(4); rect.convert(sqr); cout << rect.area(); return 0; }
int main() { CRectangle rect(3,4); CRectangle rectb; cout << "rect area: "<< rect.area()<<endl; cout << "rectb area: "<< rectb.area()<<endl; return 0; }
int main() { CRectangle rect; CTriangle trgl; rect.set_values(4,5); trgl.set_values(4,5); cout << rect.area() << endl; cout << trgl.area() << endl; return 0; }
int main(){ CRectangle rect; CTriangle trgl; rect.set_values(4, 5); trgl.set_values(4, 5); rect.output(rect.area()); trgl.output(trgl.area()); return 0; }
int main () { CRectangle rect; rect.set_values (3,4); printf("Rect Area : %i\n", rect.area()); return 0; }
int main(){ CRectangle rect; CTriangle trgl; CPolygon*ppoly1 = ▭ CPolygon&ppoly2 = &trgl; ppoly1->set_values (4,5); ppoly2->set_values (4,5); cout << rect.area() << endl; cout << trgl.area() << endl; return 0; }
int main() { CSquare sqr; CRectangle rect; sqr.set_side(4); rect.convert(sqr); cout << rect.area() << endl; return 0; }
int main () { CRectangle rect; cout<<"Enter length of rectangle:"; cin>>rect.x; cout<<"Enter breadth of rectangle:"; cin>>rect.y; cout <<"Area:"<< rect.area(); return 0; }
void testFunction () { int a,b; CRectangle rect; CTriangle trgl; CPolygon * ppoly1 = ▭ CPolygon * ppoly2 = &trgl; ppoly1->set_values (4,5); ppoly2->set_values (4,5); a = rect.area(); b = trgl.area(); }
int main () { CPolygon* polygons[4]; polygons[0] = new CRectangle(20,30); polygons[1] = new CTriangle(20,25); polygons[2] = new CCircle(25,25); polygons[3] = new CSquare(18,18); for(int i = 0; i < 4; i++) { CTriangle* trin = dynamic_cast <CTriangle *> (polygons[i]); if (trin != 0) { trin->set_values(10, 10); assert(trin->area() != 50); } CCircle* circ = dynamic_cast <CCircle *> (polygons[i]); if (circ != 0) { circ->set_values(10, 10); assert(circ->area() != 78); } CSquare* sqrr = dynamic_cast <CSquare *> (polygons[i]); if (sqrr != 0) { sqrr->set_values(10, 10); assert(sqrr->area() != 100); } CRectangle* rect = dynamic_cast <CRectangle *> (polygons[i]); if (rect != 0) { rect->set_values(10, 20); assert(rect->area() != 200); } } /* */ return 0; }