±±¾©Ê¯ÓÍ»¯¹¤Ñ§Ôº2026ÄêÑо¿ÉúÕÐÉú½ÓÊÕµ÷¼Á¹«¸æ
²é¿´: 1687  |  »Ø¸´: 6
µ±Ç°Ö»ÏÔʾÂú×ãÖ¸¶¨Ìõ¼þµÄ»ØÌû£¬µã»÷ÕâÀï²é¿´±¾»°ÌâµÄËùÓлØÌû

zhaowei8686

гæ (СÓÐÃûÆø)

[ÇóÖú] ÇóÖúÒ»¸öC++µÄ³ÌÐò£¬Ê®Íò»ð¼± ÒÑÓÐ1È˲ÎÓë

ÌâÄ¿ÊÇ£º
The Car Company

A car company sells different car models. During the purchase order, the customer can choose between different types of engines, body chapes (coup¨¦, sedan, estate), body colors, etc...

Can you create a C++ class architecture that will provide a car object, corresponding to our needs ?

Every car has some typical functions to read mileage, fuel gauge or number of seats, start the engine, turn right, etc... Feel free to implement some you think relevant to exploit the C++ object model.

Example of function calls to implement:
Car* myCar = CarCompany.getCar( paremeters );
fuel_type = myCar.getFuleType();
km = myCar.getMileAge();
(etc...)

±¾ÈËûÓÐѧ¹ýC++,Çó¸ßÊÖ°ïÖú
»Ø¸´´ËÂ¥

» ²ÂÄãϲ»¶

» ±¾Ö÷ÌâÏà¹Ø¼ÛÖµÌùÍÆ¼ö£¬¶ÔÄúͬÑùÓаïÖú:

ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

cooooldog

Ìú¸Ëľ³æ (ÖøÃûдÊÖ)

ส็็็

ÕâôÇå³þµÄÁ·Ï°Ìâ×÷Òµ,
ส็็็็็็็็็็็็็็็็็็็็
5Â¥2014-05-24 07:28:09
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû
²é¿´È«²¿ 7 ¸ö»Ø´ð

q515949148

Í­³æ (СÓÐÃûÆø)

jjdg: lzÔÚ14·ÖÖÓºóÒÑ·­Ò룬ÇëÄã¼ÌÐø 2014-05-24 01:26:38
ÄÜÉÔ΢·­ÒëÒ»ÏÂô£¿±ÉÈËÓ¢ÓïˮƽʵÔÚÌ«²î¡£µ«·­Òë³öÀ´»¹ÊÇ»á°ïÖúÄãµÄ

[ ·¢×ÔСľ³æ¿Í»§¶Ë ]
2Â¥2014-05-23 21:09:11
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

zhaowei8686

гæ (СÓÐÃûÆø)

ÒýÓûØÌû:
2Â¥: Originally posted by q515949148 at 2014-05-23 21:09:11
ÄÜÉÔ΢·­ÒëÒ»ÏÂô£¿±ÉÈËÓ¢ÓïˮƽʵÔÚÌ«²î¡£µ«·­Òë³öÀ´»¹ÊÇ»á°ïÖúÄãµÄ

Ò»¼ÒÆû³µ¹«Ë¾ÏúÊÛ²»Í¬ÀàÐÍµÄÆû³µ¡£ÔڲɹºÊ±£¬¿Í»§¿ÉÒÔÑ¡Ôñ²»Í¬ÀàÐ͵ķ¢¶¯»ú£¬³µÌ壨±ÈÈçË«ÃÅÅܳµ£¬½Î³µ£¬·¿³µµÈ£©£¬³µÉíÑÕÉ«µÈµÈ..

Äã¿ÉÒÔ´´½¨Ò»¸öC + +ÀàµÄ¼Ü¹¹£¬¸ù¾ÝÎÒÃǵÄÐèÇó£¬À´Ìṩһ¸öÆû³µ¶ÔÏó¡£

ÿÁ¾Æû³µ¶¼ÓÐһЩµäÐ͵ĺ¯ÊýÀ´¶ÁÈ¡ÐÐÊ»Àï³Ì£¬È¼Óͱí»ò×ùλÊý£¬Æô¶¯·¢¶¯»ú£¬ÓÒתµÈ¡£Ëæ±ãÀ´ÊµÏÖһЩÄãÈÏΪÏà¹ØµÄÀûÓÃÁËC + +¶ÔÏóÄ£ÐÍ¡£

»ù±¾ÉϾÍÊÇÕâÑù×ӵ쬳öÌâµÄÊÇÒ»¸ö·¨¹úµÄ½ãÃ㬴ó¸ÅÒâ˼¾ÍÊÇÕâÑùÁË¡£
3Â¥2014-05-23 21:23:13
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

libralibra

ÖÁ×ðľ³æ (ÖøÃûдÊÖ)

æôÆï½«¾ü

¡¾´ð°¸¡¿Ó¦Öú»ØÌû

¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï
¸Ðл²ÎÓ룬ӦÖúÖ¸Êý +1
zhaowei8686(jjdg´ú·¢): ½ð±Ò+5, ÐÁ¿àÁË 2014-05-24 01:25:55
zhaowei8686: ½ð±Ò+25, ¡ï¡ï¡ï¡ï¡ï×î¼Ñ´ð°¸ 2014-05-24 08:21:27
ÒýÓûØÌû:
3Â¥: Originally posted by zhaowei8686 at 2014-05-23 21:23:13
Ò»¼ÒÆû³µ¹«Ë¾ÏúÊÛ²»Í¬ÀàÐÍµÄÆû³µ¡£ÔڲɹºÊ±£¬¿Í»§¿ÉÒÔÑ¡Ôñ²»Í¬ÀàÐ͵ķ¢¶¯»ú£¬³µÌ壨±ÈÈçË«ÃÅÅܳµ£¬½Î³µ£¬·¿³µµÈ£©£¬³µÉíÑÕÉ«µÈµÈ..

Äã¿ÉÒÔ´´½¨Ò»¸öC + +ÀàµÄ¼Ü¹¹£¬¸ù¾ÝÎÒÃǵÄÐèÇó£¬À´Ìṩһ¸öÆû³µ¶ÔÏó¡£

ÿ ...

Ö»ÄܰïÄãµ½ÕâÀïÁË,¸´ÖƽøÒ»¸öºó׺ΪcppµÄÎļþÔËÐÐÒ»ÏÂ,¸ù¾ÝÐèÒªÔٸĸÄ,Ìí¼ÓһЩÐèÒªµÄº¯Êý
CODE:
#include <iostream>
#include <string>

using namespace std;

class Car
{
private:
    int mileage;
    int fuel;   // fuel gauge: 0-Diesel, 1-Petrol
    int seat;
    double engine;
    int type;   // body type: 0-Coup¨¦, 1-Sedan, 2-Estate
    int color;  // body color: 0-Red, 1-Orange, 2-Yellow, 3-Green, 4-Blue, 5-Purple, 6-Magenta
    int direction; // directions: 0-North, 1-East, 2-South, 3-West
    int status; // status: 0-OFF, 1-ON

    static string types[3];
    static string dirs[4];
    static string colors[7];
public:
    Car(double e, int t, int c, int m=0, int f=0, int n=4, int d=0, int s=0) : mileage(m), fuel(f), seat(n),
    engine(e), type(t), color(c), direction(d), status(s) { }

    int getMileAge(void) { return this->mileage; }
    string getFuleType(void) { return this->fuel?"Petrol":"Diesel"; }
    int getSeats(void) { return this->seat; }

    double getEngine(void) { return this->engine; }
    string getType(void) { return this->types[this->type]; }
    string getColor(void) { return this->colors[this->color]; }
    void setEngine(double e) { this->engine = e; }
    void setType(int t) { this->type = t; }
    void setColor(int c) { this->color = c; }

    void turnRight(void) { cout << "Turning right..." << endl; this->direction++; this->direction %= 4; }
    void turnLeft(void) { cout << "Turning left..." << endl; this->direction = this->direction==0?3:this->direction-1;}
    string getDirection(void) { return this->dirs[this->direction]; }

    string getStatus(void) { return this->status?"ON":"OFF"; }
    void startEngine(void) { if (!this->status) { cout << "Starting engine..." << endl; } this->status = 1; }
    void stopEngine(void) { if (this->status) { cout << "Stop engine..." << endl; }this->status = 0; }

    void printInfo(void)
    {
        cout << "\nCar information: " << endl
        << "\tEngine size:\t" << this->getEngine() << " L" << endl
        << "\tType:\t\t" << this->getType() << endl
        << "\tColor:\t\t" << this->getColor() << endl
        << "\tMileage:\t" << this->getMileAge() << " mile(s)" << endl
        << "\tFuel:\t\t" << this->getFuleType() << endl
        << "\tSeats:\t\t" << this->getSeats() << endl
        << "\n\tDirection:\t" << this->getDirection() << endl
        << "\tEngine is:\t" << this->getStatus() << endl;
    }
};

string Car::dirs[] = {"North","East","South","West"};
string Car::types[] = {"Coup¨¦", "Sedan","Estate"};
string Car::colors[] = {"Red","Orange","Yellow","Green","Blue","Purple","Magenta"};

class Company
{
public:
    Car* getCar(double engine, int type, int color)
    { return new Car(engine,type,color); }
};

int main()
{
    Company CarCompany = Company();
    Car* myCar = CarCompany.getCar(1.6,0,1);
    myCar->printInfo();

    myCar->startEngine();
    myCar->printInfo();

    myCar->turnRight();
    myCar->printInfo();

    myCar->turnRight();
    myCar->printInfo();

    myCar->turnRight();
    myCar->printInfo();

    myCar->turnRight();
    myCar->printInfo();

    myCar->turnLeft();
    myCar->printInfo();

    myCar->stopEngine();
    myCar->printInfo();
    return 0;
}

ÔËÐнá¹û
CODE:

Car information:
        Engine size:    1.6 L
        Type:           Coup¨¦
        Color:          Orange
        Mileage:        0 mile(s)
        Fuel:           Diesel
        Seats:          4

        Direction:      North
        Engine is:      OFF
Starting engine...

Car information:
        Engine size:    1.6 L
        Type:           Coup¨¦
        Color:          Orange
        Mileage:        0 mile(s)
        Fuel:           Diesel
        Seats:          4

        Direction:      North
        Engine is:      ON
Turning right...

Car information:
        Engine size:    1.6 L
        Type:           Coup¨¦
        Color:          Orange
        Mileage:        0 mile(s)
        Fuel:           Diesel
        Seats:          4

        Direction:      East
        Engine is:      ON
Turning right...

Car information:
        Engine size:    1.6 L
        Type:           Coup¨¦
        Color:          Orange
        Mileage:        0 mile(s)
        Fuel:           Diesel
        Seats:          4

        Direction:      South
        Engine is:      ON
Turning right...

Car information:
        Engine size:    1.6 L
        Type:           Coup¨¦
        Color:          Orange
        Mileage:        0 mile(s)
        Fuel:           Diesel
        Seats:          4

        Direction:      West
        Engine is:      ON
Turning right...

Car information:
        Engine size:    1.6 L
        Type:           Coup¨¦
        Color:          Orange
        Mileage:        0 mile(s)
        Fuel:           Diesel
        Seats:          4

        Direction:      North
        Engine is:      ON
Turning left...

Car information:
        Engine size:    1.6 L
        Type:           Coup¨¦
        Color:          Orange
        Mileage:        0 mile(s)
        Fuel:           Diesel
        Seats:          4

        Direction:      West
        Engine is:      ON
Stop engine...

Car information:
        Engine size:    1.6 L
        Type:           Coup¨¦
        Color:          Orange
        Mileage:        0 mile(s)
        Fuel:           Diesel
        Seats:          4

        Direction:      West
        Engine is:      OFF

Process returned 0 (0x0)   execution time : 0.062 s
Press any key to continue.

matlab/VB/python/c++/Javaд³ÌÐòÇë·¢QQÓʼþ:790404545@qq.com
4Â¥2014-05-23 23:40:43
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû
×î¾ßÈËÆøÈÈÌûÍÆ¼ö [²é¿´È«²¿] ×÷Õß »Ø/¿´ ×îºó·¢±í
[¿¼ÑÐ] 321Çóµ÷¼Á +6 è±Óñ~~ 2026-03-25 7/350 2026-03-28 17:48 by è±Óñ~~
[¿¼ÑÐ] 081200-11408-276ѧ˶Çóµ÷¼Á +4 ´Þwj 2026-03-26 4/200 2026-03-28 16:47 by jiyingjie123
[¿¼ÑÐ] 085602 »¯¹¤×¨Ë¶ 338·Ö Çóµ÷¼Á +12 ·³ÕСç÷ 2026-03-27 12/600 2026-03-28 15:41 by L135790
[¿¼ÑÐ] ²ÄÁÏÓ뻯¹¤272Çóµ÷¼Á +9 °¢Ë¹µÙ·Ò2004 2026-03-28 9/450 2026-03-28 15:21 by 1018329917
[¿¼ÑÐ] 311Çóµ÷¼Á +4 ¶¬Ê®Èý 2026-03-24 4/200 2026-03-28 13:17 by ÌÆãå¶ù
[¿¼ÑÐ] 085701»·¾³¹¤³Ì£¬267Çóµ÷¼Á +16 minht 2026-03-26 16/800 2026-03-28 12:16 by zllcz
[¿¼ÑÐ] 0703»¯Ñ§/290Çóµ÷¼Á/±¾¿Æ¾­Àú·á¸»/¹¤¿ÆÒ²¿É +9 µ¤ÇàÄÌ¸Ç 2026-03-26 10/500 2026-03-28 07:45 by barnett0632
[¿¼ÑÐ] 295Çóµ÷¼Á +5 1428151015 2026-03-27 6/300 2026-03-28 04:04 by fmesaito
[¿¼ÑÐ] Çóµ÷¼Á +8 ÕÅzz111 2026-03-27 9/450 2026-03-28 03:41 by fmesaito
[¿¼ÑÐ] »¯Ñ§µ÷¼Á +4 °®³Ô·¬ÇѵÄÐñ 2026-03-24 5/250 2026-03-27 17:50 by kiokin
[¿¼ÑÐ] Ò»Ö¾Ô¸ Î÷±±´óѧ ×Ü·Ö282 Ó¢ÓïÒ»62 Çóµ÷¼Á +7 18419759900 2026-03-25 8/400 2026-03-27 16:38 by 18419759900
[¿¼ÑÐ] 287Çóµ÷¼Á +10 land xuxu 2026-03-26 10/500 2026-03-27 15:33 by ÅÁ¶ûÂíÀ­ÌØ
[¿¼ÑÐ] 305Çóµ÷¼Á +5 ÍÛ¬¿¨¿â 2026-03-26 5/250 2026-03-27 14:01 by laoshidan
[¿¼ÑÐ] 292Çóµ÷¼Á +4 ÇóÇóÁËÊÕÏÂÎÒ°É£ 2026-03-26 4/200 2026-03-27 10:37 by zhshch
[¿¼ÑÐ] Ò»Ö¾Ô¸Ö£ÖÝ´óѧ£¬080500ѧ˶£¬×Ü·Ö317·ÖÇóµ÷¼Á +4 ¾Ù¸öÀõ×Óoi 2026-03-24 5/250 2026-03-26 23:15 by ²»³Ôô~µÄ؈
[¿¼ÑÐ] 329Çóµ÷¼Á +5 1() 2026-03-22 5/250 2026-03-26 20:40 by fmesaito
[¿¼ÑÐ] 303Çóµ÷¼Á +6 À¶É½Ô 2026-03-25 6/300 2026-03-25 22:47 by 418490947
[¿¼ÑÐ] Ò»Ö¾Ô¸ÎäÀí085500»úеרҵ×Ü·Ö300Çóµ÷¼Á +3 an10101 2026-03-24 7/350 2026-03-25 00:00 by ɽ¹í0-
[¿¼ÑÐ] 080500Çóµ÷¼Á +3 zzzzfan 2026-03-24 3/150 2026-03-24 16:38 by barlinike
[¿¼²©] 26É격×Ô¼ö +3 whh869393 2026-03-24 3/150 2026-03-24 09:55 by 21018060
ÐÅÏ¢Ìáʾ
ÇëÌî´¦ÀíÒâ¼û