急!急!!!求Visual c++高手帮住下 看看下面的题目

[复制链接]
查看11 | 回复1 | 2008-9-21 08:36:13 | 显示全部楼层 |阅读模式
都是只改*****found******下一行有错
(3)要求输出结果为
00:00:00
00:01:00
#include
#include
using namespace std;
class StopWatch// "秒表"类
{
int hours;
// 小时
int minutes; // 分钟
int seconds; // 秒
public:
StopWatch():hours(0), minutes (0), seconds(0){}
void reset(){hours=minutes=seconds=0;}
StopWatch operator++(int)
// 后置++
{

StopWatch old=*this;

++(*this);

return old;
}
//前进1秒
StopWatch& operator++()
// 前置++
{

// ERROR *********found*********

if(seconds++==60)

{

seconds=0;minutes++;

if(minutes==60)

{

minutes=0;

hours++;

}

}

// ERROR *********found*********

return this;
}
friend void show(StopWatch);
};
void show(StopWatch watch)
{
cout<<setfill('0');

cout<<setw(2)<<watch.hours<<':'

<<setw(2)<<watch.minutes<<':'

<<setw(2)<<watch.seconds<<endl;
}
int main()
{
StopWatch sw;
show(sw);
for (int i=0; i<59; i++) sw++;
// ERROR *********found*********
show(sw++);
return 0;
}
填空题 填写横线的空白 使程序输出如下要求结果
(1)要求输出的结果为
1 2 3 4 5 6 7 8 9 10
#include
using namespace std;
// 集合类的操作接口
class Collection {
public:
// 向集合中添加一个元素
virtual void add(int e) = 0;
// 获取指定位置的元素
virtual int get(unsigned int i) const = 0;
};
// 实现了集合接口
class Array : public Collection {
public:
Array(unsigned int s)
{

//**********found**********

a = new ________________;

size = s;

num = 0;
}

~Array()
{

//**********found**********

_______________;
}

virtual void add(int e)
{

if (num < size) {

//**********found**********

_______________ = e;

num++;

}
}

virtual int get(unsigned int i) const
{

if (i < size) {

//**********found**********

_______________;

}

return 0;
}
private:
int *a;
unsigned int size;
unsigned int num;
};
void fun(Collection& col)
{
int i;
for (i = 0; i < 10; i++) {

col.add(i+1);
}
for (i = 0; i < 10; i++) {

cout << col.get(i) << ", ";
}
cout << endl;
}
int main()
{
Array a(0xff);
fun(a);

return 0;
}

回复

使用道具 举报

千问 | 2008-9-21 08:36:13 | 显示全部楼层
// ERROR *********found********* if(seconds++==60) 改 if(++seconds==60) //左右自增的问题 // ERROR *********found********* return this; 改 return *this;(2)#include using namespace std;// 集合类的操作接口class Collection{public:// 向集合中添加一个元素
virtual void add(int e) = 0;// 获取指定位置的元素
vi...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行