求大神帮忙!!不会做啊~~ T_T
任务1
目标:
熟悉开发环境
简单的类语法
任务:
实现车辆类。每部车辆的特点是由当前的速度(int型)和最大速度(int型) 。车辆有
可能存储最大5个feature(string) 。除了必要的构造函数, set和get方法,车辆有
一些附加的方法:
bool changeSpeed (int delta) :增加了currentspeed如果新值的范围是[0 ..
maxspeed] ,返回true,如果currentspeed已更新(这句有些有问题,英文写的就用问题
,我的理解就是如果新值在0~max间就更新,否则就不更新当前速度)。
void addFeature (string):添加字符串到feature列表,如果空间有效(没有超出五
个)
bool removeFeature (string) ,从列表中删除一个feature,如果已被删除,则返回
true 。
std::string info() 返回信息,就像车辆运行速度
创建一个测试应用程序实例,改变车辆的速度,添加和删除feature和显示信息的输出,
根据不同情况,检查执行情况
任务2
-继承语法
-重写方法
任务:
实现一个Solarcar类,该类继承于Vehicle类。一个Solarcar对象有一个额外的属性
batterylevel(float类型:取值在0.0到1.0之间)。提供必要的方法。
在Solarcar类中中重写方法info(),因为关于电池水平的信息在速度信息的后面直接
显示出来。尝试在Solarcar::info()方法中重用Vehicle::info()。
写几个构造函数,分别有0,1,2,3个参数。
创建一个合适的测试程序。
任务3
目标:
- 动态内存管理
任务:
实现一个Occupied类,该类可以连续内存中,存储任意数量的不同float数据,其构造函
数接受一个整形参数,用作容器的初始大小,如果没有给定初始值,那么就假定其初始
大小是5.
如果一个元素在容器中尚未存在,方法void add_element(float)将向容器中增加该元素
,同时,如果必要,需调整容器的大小。
如果位于index的元素存在,方法bool remove_element(int index)将删除该元素,并将
其后的元素依次前移。如果元素被成功删除,该方法返回true。
方法bool get_element(int index, float & result)返回位置为index的元素,如果该
元素存在,那么返回结果将保存在result中。同时根据这个返回值来标志函数的失败/成
功。
方法Show()应该用类似下面的形式输出容器的内容:
容器的大小 : 3
* 第一个元素 = 1.26345
* 第二个元素 = -0.25
* 第三个元素 = 444444444.01
下面的代码会发生什么事情呢?
Occupied o = 5; // 我们怎样让编译器拒绝此种行为?
实例化一个非常大的容器来检验内存管理,比如在本地范围Occupied large(99999999);
然后在分别在本地范围内、外终止程序运行,并用“任务管理器”查看内存的使用情况
。
创建一个合适的程序,用以测试所有实现的功能。
任务4
目标:
-使用静态绑定或动态绑定
-使用标准模板库集合类
-操作符重载
-最优化你的代码
任务:
对Vehicles和Solarcars做出必要的变化以此来使用标准模板库中的矢量(向量)。
对Vehicles类重载操作符<<.当你调用info()或者使用<<你将会看到正确的信息。
使用你现知道的所有C++知识最优化你的代码。考虑调用方法,返回类型,必要的构造函
数、析构函数、拷贝构造函数、赋值操作符...
英文版的:
Task 1
Goal:
- Familiarise with development environment
- Simple class syntax
Task:
Implement a Vehicle class. Every Vehicle is characterised by a current speed (integer) and a maximal speed (integer). A Vehicle has the possibility to store maximum 5 features (string). Besides the necessary constructor(s), setters and getters, a Vehicle has some extra methods:
+ bool changeSpeed(int delta): adds delta to currentspeed if new value is in range [0..maxspeed], returns true if currentspeed has been updated.
+ void addFeature(string): adds string to featurelist if space is still available
+ bool removeFeature(string f): removes feature f from featurelist if f is found, shift content of all following features. Returns true if string has been removed.
+ std::string info() which returns a string like
The vehicle is running at speed [currentspeed]
and has [nr. of features] features:
* [feature1]
* ...
Create a test application which instantiates some vehicles, change speed, add and remove features and show output of info() on different situations to check the implementation
- inheritance syntax
- overriding methods
Task:
Implement a Solarcar class which inherits from Vehicle. A Solarcar has an extra attribute batterylevel (float between 0.0 and 1.0). Provide the necessary methods.
The method info() is overridden in Solarcar because the info on the batterylevel is also shown directly after the speed information. Try to reuse Vehicle::info() in Solarcar::info().
Make it possible to call the same constructor with zero, one, two or three parameters.
Create a suitable test application.
Goal:
- dynamic memory management
Task:
Implement an Occupied class which can store an undefined number of different floats consecutive in memory. The constructor accepts an integer as initial size of the container. If no value is specified, a size of 5 is assumed.
The method void add_element(float) adds an element to the container if it is not yet stored and adapts the size if needed.
The method bool remove_element(int index) removes the element at position index, if available and shifts all remaining elements. Returns true if element is removed.
The method bool get_element(int index, float & result) returns the specific element, if available, in result and use the return value to flag failure/succes.
The method Show() which should show info about the container like:
Size of container : 3
* the 1st element = 1.26345
* the 2nd element = -0.25
* the 3rd element = 444444444.01
What happens with following code?
Occupied o = 5; // how can we let the compiler to refuse it?
Check your memory management by instantiating a very large container, e.g. Occupied large(99999999); in a local scope and stopping the program both inside and directly outside this scope. Use "Task Manager" to visualise your memory usage.
Create a suitable application which test all the implemented functionaly.
Goal:
- use of static/dynamic binding
- using STL collections
- operator overloading
- optimize your code
Task:
Make the necessary changes to be able to populate a STL vector with both Vehicles and Solarcars. Overload the << operator for Vehicle. When you call info() or use << you should see the right information appearing.
Use all your current knowledge on C++ to optimize your code. Think about calling methods, return types, need to define constructor, destructor, copy-constructor, assignment operator...
[解决办法]
那你想怎样?发个90分的帖子让大家给你做这几个task?
[解决办法]
这。。。90分就来求大神会不会太儿戏了点~?
[解决办法]
¥300 一题,支付宝先款。
程序员们,你们的市场价值需要自己维护!恶性竞争、砸盘对谁都没有好处!!
[解决办法]
¥300 一题,支付宝先款。
程序员们,你们的市场价值需要自己维护!恶性竞争、砸盘对谁都没有好处!!