24小时热门版块排行榜    

查看: 1848  |  回复: 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的回帖

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的回帖
查看全部 7 个回答

q515949148

铜虫 (小有名气)

jjdg: lz在14分钟后已翻译,请你继续 2014-05-24 01:26:38
能稍微翻译一下么?鄙人英语水平实在太差。但翻译出来还是会帮助你的

[ 发自小木虫客户端 ]
2楼2014-05-23 21:09:11
已阅   回复此楼   关注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的回帖

cooooldog

铁杆木虫 (著名写手)

ส็็็

这么清楚的练习题作业,
ส็็็็็็็็็็็็็็็็็็็็
5楼2014-05-24 07:28:09
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 时间戳变了,能看出什么问题? +16 基诺咪客 2026-08-17 20/1000 2026-08-20 12:44 by 201120518022
[基金申请] 重要消息,中午系统在维护 +11 yuleib84 2026-08-18 12/600 2026-08-20 11:09 by xskun
[基金申请] 言之凿凿,8月21号(明天)放榜 +12 医学老男孩 2026-08-20 14/700 2026-08-20 10:53 by ran2233
[基金申请] 今天基金会出结果吗?20260819 +14 kkkl_v 2026-08-19 15/750 2026-08-20 08:21 by sunzitan
[基金申请] filecode,4个jtjc了 +11 ziyangfang 2026-08-19 13/650 2026-08-19 21:28 by aasahr
[教师之家] 为什么余额宝的年化利率越来越低?主要原因有哪些? +5 瞬息宇宙 2026-08-15 5/250 2026-08-19 20:23 by super2002521
[基金申请] 今天放榜没戏了吧 +4 yuleib84 2026-08-19 5/250 2026-08-19 19:52 by hhs666
[基金申请] 今天放榜吗? +14 布布和一二 2026-08-19 15/750 2026-08-19 18:07 by gltch
[基金申请] filecode=后面第一个是大写字母 +10 wangze12014 2026-08-14 12/600 2026-08-19 16:56 by 苦难博士
[基金申请] 2027广东省杰青 +4 奶牛小黑 2026-08-15 10/500 2026-08-19 11:02 by wanfengnew
[基金申请] 朋友圈看到的 +6 wangzilk 2026-08-18 8/400 2026-08-19 10:55 by Haru815
[基金申请] 快农历七夕节了,轻松一下,男人悄悄话,女施主请不要进来。 +6 Tide man 2026-08-14 7/350 2026-08-19 09:56 by ZJTJZ
[基金申请] 什么时候开奖? +6 CrisMessi 2026-08-18 6/300 2026-08-19 08:06 by Equinoxhua
[基金申请] 明天放榜? +5 Shxjjxjkx 2026-08-18 5/250 2026-08-18 18:14 by -大大大大大-
[论文投稿] 投稿咨询 +4 wwm09 2026-08-17 6/300 2026-08-18 15:36 by wwm09
[基金申请] 时间戳又变了8-15 +14 archvillain 2026-08-15 26/1300 2026-08-18 13:37 by phantomgost
[基金申请] 今天维护系统维护 祝所有人 高中 +8 gjjjzhong 2026-08-18 9/450 2026-08-18 13:01 by 家与远方
[基金申请] 感觉是下周放榜了 +6 angus9576 2026-08-17 11/550 2026-08-17 23:57 by angus9576
[精细化工] 招聘 金属平磨液,抛光液研发工程师 +3 小天0311 2026-08-14 3/150 2026-08-16 07:31 by H9PLUS
[基金申请] 各位道友,我要去昆明玩几天,回来见。 +7 Tide man 2026-08-14 8/400 2026-08-15 01:11 by arzu_hma
信息提示
请填处理意见