问题 问答题

请使用VC6或使用[答题]菜单打开考生目录proj3下的工程文件proj3,此工程中包含一个源程序文件proj3.cpp,其功能是从文本文件in.dat中读取全部整数,将整数序列存放到intArray类的对象中,然后建立另一对象myArray,将对象内容赋值给myArray。类intArray重载了“=”运算符。程序中给出了一个测试数据文件input,不超过300个的整数。程序的输出是:
10
11
13
16
20
要求:
补充编制的内容写在“//**********333**********”与“//**********666**********”之间。实现重载赋值运算符函数,并将赋值结果在屏幕输出。格式不限。不得修改程序的其他部分。
注意:程序最后将结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件,并且在本程序中调用。
//intArray.h
class intArray

private:
int*array;
int length;
public:
intArray (char*filename);
intArray ();
intArray & operator=(const intArray & src);
~intArray ();
void show ();
;
void writeToFile (const char*path);
//main.cpp
#include<iostream>
#include<fstream>
#include<cstring>
#include "intArray.h"
using namespace std;
intArray::intArray ()

length=10;
array=new int[length];
intArray::intArray(char*filename)

ifstream myFile(filename);
array=new int[300];
length=0;
while (myFile>>array[length++])
length--;
myFile.close();

intArray& intArray::operator=(const intArray & src)

if (arrayl=NUll) delete [] array;
length=src.length;
array=new int[length];
return*this;
intArray::~intArray ()

delete [] array;

void intArray::show ()

int step =0;
for(int i=0;i<length;i=i+step)

cout<<array[i]<<endl;
step++;


void main ()

intArray*arrayP=new intArray("input.dat");
intArray myArray;
myArray=*arrayP;
(*arrayP).show();
delete arrayP;
writeToFile(" ");

答案

参考答案:for(int i=0;i<length;i++)
//遍历对象src中的数组array,然后依次把值放进数组array中
array[i]=src.array[i];

解析: 本题主要考查intArray类,其中涉及动态数组、构造函数、运算符重载、析构函数及其他成员函数。
主要考查考生对运算符重载的掌握,该函数要重载运算符“=”,该运算符的意思是赋值。先看该函数的其他语句:
if(array!=NULL)delete[]array;
length=src.length;
array=new int[lengthl;
第一条语句是把原来动态数组释放,第二条语句是把形参src的成员length赋值给变量length,第三条语句是给指针array分配内存。接下来要把动态数组中的值逐个赋给array数组,在这里使用for循环语句,循环变量i的范围是0~length,并进行赋值操作。

阅读理解

阅读理解

     After winning a big game, athletes are often asked how they attained that success.Most say their

achievement is the result of gruelling hard work and intense practice.Usually athletes say how hard it

is to win the big games.At the opposite end of the spectrum, however, is the fact that losing the big

game, or, in my case, all the games, can be even tougher.

     From the spectators'point of view, last year's basketball season for my high school team was

nothing short of an embarrassment.And while 0 and 20 is certainly nothing to be proud of, that season

had a bigger impact on me than any other, and probably more than any season since.

     As a team captain, I knew it probably wouldn't be the easiest year, but did I ever think we would

lose every game?Of course not.Since six of our top players had graduated, it was clear that we were

a young team who would struggle.The struggle began earlier than expected, though, as our team's

starting center was suspended for the season, and two key members decided to quit after two weeks.

At some point, quitting probably passed through every player's mind, but, in the end, we all stuck it

out, vowing to work even harder.

     Then there came a time when even our own coach had given up on us.Personally, I felt like it was

no longer worth giving my all.I thought, if even the coach doesn't believe in us, why should I?But just

as my hope began to fade, a teammate called a meeting.He said, "Nobody thinks we're going to win,

and heck, we may not, but, as teammates and friends, we_owe_it_to_each_other_to_give_it_our_all

_every_game."

     Sure, it was a little clich? (陈旧的), but it was that moment that taught me how to be a leader.It hit

me then that I may have been a captain, but I, like others in my position, certainly didn't deserve the

role.As a leader you can never quit on the team who looks up to you.It is one thing to be named

captain and feel great and go through the motions, but it is quite another to be a real captain and make

sure everyone works to their potential all the time.

     I am sure it is great to go through high school without losing and bringing home awards.But in all

honesty, I relish the fact that my team lost every game last year.It may not help me to become a better

basketball player, but it already has made me a better leader and person.

1. What was the biggest problem with the author's team last season?

A. Several key members were unable to play the games.

B. Their coach no longer wanted to instruct them.

C. There were no actual leaders on the team.

D. Most of players lost hope and wanted to quit.

2. In the text, the author seems to suggest that a good leader should________.

A. be confident about himself

B. make sure everyone goes all out

C. work hard to win the games

D. feel great about his team

3. By saying "we owe it to each other to give it our all every game."(Paragraph 4) the teammate

    means that all of them should________.

A. be responsible for the losses

B. try their best on the court

C. feel thankful for what they've done

D. get together to win every game

4. What is the main idea the author aims to express in the text?

A. Success is the result of hard work.

B. A friend in need is a friend indeed.

C. One can learn something from the failure.

D. A real leader should never give up.

问答题 简答题