2000-line C + + basic Exercises

Source: Internet
Author: User

#include <iostream>using namespacestd;enumGameresult{win,lose,tie,cancel};intMain () {gameresult result; enumGameresult omit =CANCEL;  for(intCount = Win;count <= cancel;count++) {result=Gameresult (count); if(Result =omit) cout<<"The game was cancelled"<<Endl; Else{cout<<"The game was played"<<Endl; if(Result = =WIN) cout<<"and we won!"; if(Result = =lose) cout<<"and we lost"; cout<<Endl; }    }    return 0;}
#include <iostream>using namespacestd;classclock{ Public:    voidSetTime (intNEWH =0,intNEWM =0,intNewS =0); voidshowTime ();Private:    intHour,minute,second;};voidClock::settime (intNEWH,intNEWM,intNewS) {Hour=NEWH; Minute=NEWM; Second=NewS;} InlinevoidClock::showtime () {cout<":"<<minute<<":"<<second<<Endl;}intMain () {clock myclock; cout<<"First time set and output"<<Endl;    Myclock.settime ();    Myclock.showtime (); return 0;}
#include <iostream>using namespacestd;Const floatPI =3.141593;Const floatF = *;Const floatC = -;classcircle1{ Public: Circle1 (floatR); floatcircumference (); floatArea ();Private:    floatradius;}; Circle1::circle1 (floatR) {Radius=R;}floatcircle1::circumference () {return 2*pi*radius;}floatCircle1::area () {returnpi*radius*radius;}intMain () {floatradius; cout<<"Enter The radius of the pool:"<<Endl; CIN>>radius;    Circle1 Pool (RADIUS); Circle1 POOLR (Radius+3); floatFencecost = Poolr.circumference () *F; cout<<fenceCost<<Endl; floatConcretecost = (Poolr.area ()-Pool.area ()) *b; cout<<concreteCost<<Endl; return 0;}
#include <iostream>#include<cmath>using namespacestd;classpoint{ Public: Point (intxx =0,intyy =0) {x=xx; Y=yy; } Point&p); intGetX () {returnx;} intGetY () {returny;}Private:    intx, y;}; Point::p oint ( point&2) {x=p.x; Y=p.y; cout<<"copy constructor of Point"<<Endl;}classline{ Public: Line (Point XP1, point xp2); Line ( line&l); DoubleGetlen () {returnLen;}Private: Point p1,p2; DoubleLen;}; Line::line (Point xp1, point Xp2):p 1 (XP1), p2 (xp2) {cout<<"c of Line"<<Endl; Doublex = static_cast<Double> (P1.getx ()-p2.getx ()); Doubley = static_cast<Double> (P1.gety ()-p2.gety ()); Len= sqrt (x*x + y*y);} Line::line ( Line&l):p 1 (L.P1), p2 (l.p2) {cout<<"copy c of line"<<Endl; Len=L.len;}intMain () {Point myp1 (1,1), MYP2 (4,5);    Line line1 (MYP1,MYP2);    Line Line2 (line1); cout<<line1.getlen () <<line2.getlen () <<Endl; return 0;}
#include <iostream>using namespacestd;classPoint { Public: Point (intx =0,inty =0): X (x), Y (y) {count++; } Point&2) {x=p.x; Y=p.y; Count++; }     ~point () {count--;} intGetX () {returnx; }     intGetY () {returny;} voidShowcount () {cout<<count<<Endl;} Private:    intx, y; Static intcount;}; intPoint::count =0; intMain () {Point A (4,5); cout<<a.getx () <<a.gety () <<Endl;    A.showcount ();    Point B (a);    B.showcount (); return 0; } #include<iostream>using namespacestd;classPoint { Public: Point (intx =0,inty =0): X (x), Y (y) {count++; } Point&p) {x=p.x; Y=p.y; Count++; }     ~point () {count--;} intGetX () {returnx; }     intGetY () {returny;} Static voidShowcount () {cout<<count<<Endl;} Private:    intx, y; Static intcount;}; intPoint::count =0; intMain () {Point A (4,5); cout<<a.getx () <<a.gety () <<Endl;    Point::showcount ();    Point B (a);    Point::showcount (); return 0; }

2000-line C + + basic Exercises

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.