24小时热门版块排行榜    

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

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

cooooldog

铁杆木虫 (著名写手)

ส็็็

这么清楚的练习题作业,
ส็็็็็็็็็็็็็็็็็็็็
5楼2014-05-24 07:28:09
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 0703化学调剂 +4 妮妮ninicgb 2026-03-21 4/200 2026-03-21 18:39 by 学员8dgXkO
[考研] 0703化学297求调剂 +3 Daisy☆ 2026-03-20 3/150 2026-03-21 17:45 by ColorlessPI
[考研] 313求调剂 +4 肆叁贰壹22 2026-03-19 4/200 2026-03-21 17:33 by ColorlessPI
[考研] 296求调剂 +4 www_q 2026-03-20 4/200 2026-03-21 17:26 by 学员8dgXkO
[考研] 0805材料320求调剂 +3 深海物语 2026-03-20 3/150 2026-03-21 15:46 by 无际的草原
[考研] 求调剂 +3 白QF 2026-03-21 3/150 2026-03-21 13:12 by zhukairuo
[考研] 能源材料化学课题组招收硕士研究生8-10名 +5 脱颖而出 2026-03-16 15/750 2026-03-21 10:16 by 脱颖而出
[考研] 299求调剂 +6 △小透明* 2026-03-17 6/300 2026-03-21 02:42 by JourneyLucky
[考研] A区线材料学调剂 +5 周周无极 2026-03-20 5/250 2026-03-20 21:33 by laoshidan
[考研] 260求调剂 +3 朱芷琳 2026-03-20 3/150 2026-03-20 20:35 by 学员8dgXkO
[考研] 一志愿西安交通大学 学硕 354求调剂211或者双一流 +3 我想要读研究生 2026-03-20 3/150 2026-03-20 20:13 by JourneyLucky
[考研] 求调剂 +3 @taotao 2026-03-20 3/150 2026-03-20 19:35 by JourneyLucky
[考研] 一志愿南理工085701环境302求调剂院校 +3 葵梓卫队 2026-03-20 3/150 2026-03-20 19:28 by zhukairuo
[考研] 08工学调剂 +5 用户573181 2026-03-20 5/250 2026-03-20 15:47 by xia_2003
[考研] 一志愿中国海洋大学,生物学,301分,求调剂 +5 1孙悟空 2026-03-17 6/300 2026-03-19 23:46 by zcl123
[考研] 085600材料与化工调剂 324分 +10 llllkkkhh 2026-03-18 12/600 2026-03-19 14:33 by llllkkkhh
[考研] 一志愿福大288有机化学,求调剂 +3 小木虫200408204 2026-03-18 3/150 2026-03-19 13:31 by houyaoxu
[考研] 一志愿985,本科211,0817化学工程与技术319求调剂 +10 Liwangman 2026-03-15 10/500 2026-03-19 10:25 by 无际的草原
[考研] 材料,纺织,生物(0856、0710),化学招生啦 +3 Eember. 2026-03-17 9/450 2026-03-18 10:28 by Eember.
[考研] 275求调剂 +4 太阳花天天开心 2026-03-16 4/200 2026-03-17 10:53 by 功夫疯狂
信息提示
请填处理意见